Skip to content

Launch the CLI, docs and examples with torchrun instead of accelerate launch - #7180

Merged
qgallouedec merged 15 commits into
mainfrom
drop-accelerate-launch
Nov 9, 2026
Merged

qgallouedec merged 15 commits into
mainfrom
drop-accelerate-launch

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

trl <cmd> now launches its training script with torchrun, and the docs and examples follow. Arguments the script does not know go to torchrun (--nproc_per_node, --nnodes, ...), and DeepSpeed and FSDP are set through the training arguments (--deepspeed zero3.json, --fsdp), like for any Trainer.

accelerate launch keeps working. Until v2.0.0, trl still uses it, with a FutureWarning, for arguments only accelerate knows (--num_processes, --accelerate_config) and when an accelerate config default file exists.

  • examples/accelerate_configs/ becomes examples/deepspeed_configs/*.json and examples/fsdp_configs/fsdp2.json.
  • Tested on 2xH100 (SFT DDP, ZeRO-2/3, FSDP2, context parallelism, DPO ZeRO-3, both deprecated paths; tests/distributed 49 passed, the 12 Liger tests skipped) and on Trainium2 with 4 NeuronCores (torchrun 1.84 s/step, accelerate 1.82).

Note

Medium Risk
Broad user-facing change to distributed entry points and config layout; deprecated accelerate paths may hide breakage until v2.0.0, but core training logic is largely unchanged.

Overview
trl <cmd> now launches training with torchrun instead of accelerate launch, forwarding unrecognized flags (e.g. --nproc_per_node) to the launcher and enabling DeepSpeed/FSDP via standard training args (--deepspeed, --fsdp), aligned with Transformers Trainer. Single-GPU runs invoke the script directly without rendezvous; multi-GPU defaults to all visible devices unless --nproc_per_node is set.

Legacy accelerate launch remains until v2.0.0 when torchrun rejects args (--num_processes, --accelerate_config) or a default accelerate config file exists, with a FutureWarning.

Docs, examples, and shared configs are migrated: launch snippets use torchrun (or python for async trainers); CLI scaling docs drop --accelerate_config profiles in favor of examples/deepspeed_configs/*.json and examples/fsdp_configs/; examples/accelerate_configs/ is removed. Several scripts gain --deepspeed parsing or in-code deepspeed/fsdp/ParallelismConfig settings. Distributed tests and invariant harnesses launch via torchrun and JSON FSDP/DeepSpeed configs.

Reviewed by Cursor Bugbot for commit 633f97f. Bugbot is set up for automated code reviews on this repo. Configure here.

… launch

`trl <cmd>` hands the arguments its script does not know to torchrun
(`--nproc_per_node`, `--nnodes`, ...), defaulting to one process per
accelerator; a single process runs as `python script.py`. DeepSpeed and
FSDP go through the training arguments (`--deepspeed`, `--fsdp`), so the
shipped accelerate yamls become `examples/deepspeed_configs/*.json` and
`examples/fsdp_configs/fsdp2.json`. The 1M-context example sets its
context-parallel config in the SFTConfig.
@qgallouedec qgallouedec changed the title [Exploratory] Drop accelerate launch: the CLI, docs and examples launch with torchrun Launch the CLI, docs and examples with torchrun instead of accelerate launch Oct 26, 2026
@qgallouedec
qgallouedec marked this pull request as ready for review October 26, 2026 23:50
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-26T23:50:16.521922Z cbd3d5f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread examples/sft_gemma3/sft_gemma3.py Resolved
@bot-ci-comment

bot-ci-comment Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. A few issues need addressing before this can be merged:

  1. A bare --fsdp on the command line only works on transformers >= 5.10 (huggingface/transformers#45640). Below that, fsdp requires a value, so trl sft ... --fsdp fails with "expected one argument", and our floor is 4.56.2. This affects the # or --fsdp lines in clis.md and example_overview.md. fsdp=True in Python and fsdp: true in YAML work on all supported versions. Could we add a short note?
  2. --accelerate_config zero2 used a config shipped in the package. The new examples/deepspeed_configs/zero2.json only exists in a repo clone, so users who installed with pip have no ready config. Maybe inline the minimal JSON in clis.md?
  3. Nit: torch.distributed.run.main([...]) instead of run(parse_args(...)) keeps torchrun's @record error reporting and is shorter.

Launch the FSDP checkpoint test from #7939 with torchrun, with FSDP set in the training arguments
…rmers 5.10, and inline a ZeRO-2 config for pip installs
@qgallouedec

Copy link
Copy Markdown
Member Author

Thanks, addressed in 9979734:

  1. clis.md and example_overview.md now say a bare --fsdp needs transformers 5.10 or later, with fsdp: true / fsdp=True for older versions.
  2. clis.md inlines the ZeRO-2 config for pip installs.
  3. trl <cmd> now calls torch.distributed.run.main.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread examples/sft_gemma3/sft_gemma3.py Resolved
Comment thread tests/distributed/test_distributed.py Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@albertvillanova

Copy link
Copy Markdown
Member

Thanks, the three points are addressed. Before merging:

  1. The branch conflicts with main: Rewrite the gpt-oss example: fine-tune on chess puzzles, then back to MXFP4 #8085 deleted examples/sft_gpt_oss/sft_gpt_oss.py.
  2. Rewrite the gpt-oss example: fine-tune on chess puzzles, then back to MXFP4 #8085 also added examples/sft_gpt_oss_chess/, which still launches with accelerate launch --config_file examples/accelerate_configs/fsdp2.yaml (README and script docstring). The script parses no CLI arguments, so it needs fsdp=True (and fsdp_config={"cpu_ram_efficient_loading": True}, as in the old config) in its SFTConfig, plus torchrun --nproc_per_node 4.

# Conflicts:
#	examples/async_distillation_mopd/async_distillation_mopd.py
#	examples/sft_gpt_oss/sft_gpt_oss.py
#	tests/experimental/test_async_grpo_trainer.py
@qgallouedec

Copy link
Copy Markdown
Member Author

Thanks, done: the chess example now sets fsdp=True with fsdp_config={"cpu_ram_efficient_loading": True} (the rest of the old fsdp2.yaml is transformers' defaults) and launches with torchrun --nproc_per_node 4. The LFM2.5 research agent example from #7754 had the same accelerate launch, converted too.

# Conflicts:
#	tests/experimental/test_async_distillation_trainer.py

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 633f97f. Configure here.

@qgallouedec
qgallouedec merged commit 7a2e66a into main Nov 9, 2026
12 checks passed
@qgallouedec
qgallouedec deleted the drop-accelerate-launch branch November 9, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants