Skip to content

Document 1M-token training and add a context-parallelism example - #6846

Draft
qgallouedec wants to merge 45 commits into
mainfrom
long-context-example
Draft

Document 1M-token training and add a context-parallelism example#6846
qgallouedec wants to merge 45 commits into
mainfrom
long-context-example

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Aug 21, 2026

Copy link
Copy Markdown
Member

Training on sequences far longer than the usual few thousand tokens:

  • docs/source/long_context_training.md, a new how-to guide, moved out of distributing_training.md and extended with the configurations I verified and the levers in the order you hit them
  • examples/sft_qwen3_8b_1m_context/, a runnable example that trains a book-length sequence per step on one 8xH100 node

Measured

One 8xH100 node, bf16, per_device_train_batch_size=1, loss_type="chunked_nll" (the default). Qwen3-8B at 1,048,576 tokens: 380 s/step, 56.2 GB per GPU. Runs end to end, 12 steps, and saves.

Depends on

transformers >= 5.16 for gradient checkpointing offload (huggingface/transformers#48444, merged). Without it Qwen3-8B at 1M does not fit. The example checks the version at startup.

Corrections since the first version

The step times I first posted came from machines where the system CUDA shadowed the cuDNN bundled with torch, so torch fell back to FlashAttention and every number was inflated. huggingface/transformers#48163 looked like a 1.7x win there and is now closed: PyTorch already prefers cuDNN on Hopper by itself.

Earlier revisions required huggingface/accelerate#4175 instead. Measured back to back on one node, the two are the same (379.75 s vs 379.76 s), so the example uses the transformers one and needs no unreleased accelerate.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bae6acb881

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/source/distributing_training.md Outdated
Comment thread examples/sft_long_context/sft_long_context.py Outdated
Comment thread examples/sft_long_context/sft_long_context.py Outdated
Comment thread examples/sft_long_context/sft_long_context.py Outdated
Comment thread docs/source/distributing_training.md Outdated
- One folder per example, named method + task (grpo_wordle, sft_gpt_oss, ...);
  each folder holds everything the example needs (scripts, notebooks, prompts,
  chat templates, eval code)
- Split the openenv, vlm, and ppo buckets into per-example folders
- Drop thin single-trainer example scripts, redundant with trl/scripts (CLI)
  and the runnable snippets in each trainer's doc page
- Drop orphaned examples/cli_configs
- Rewrite example_overview.md as a single index of examples; rewire all doc
  links, Colab badges, and the harbor runtime path strings
The reorg removed the Scripts / OpenEnv Scripts / OpenEnv Notebooks sections;
jobs_training.md and openenv.md still linked to their anchors.
The reorg renamed folders but kept legacy file names (sft_qwen_vl.ipynb under
sft_qwen3_vl/, openenv_sudoku_grpo.ipynb, grpo_trl_lora_qlora.ipynb, *_vlm.py,
bare ppo.py/rloo.py/gspo.py). Every folder's main entry is now
examples/<name>/<name>.py or .ipynb; variant and helper files keep their
suffixed names. All Colab badges, doc links, and docstring run commands updated
in the same sweep.
Deleting examples/scripts/gold.py removed text-mode GOLD's only end-to-end
recipe (there is no trl gold CLI). It comes back as
examples/gold_chatbot_arena/, with its doc section and Index row.
The online DPO benchmark blocks still invoke the deleted
examples/scripts/online_dpo.py; the prose now says to run them from a v1.10.0
checkout.
- openenv.md: enumerate the 8 ready-to-use OpenEnv examples instead of
  pointing at the generic Index
- jobs_training.md: say which Index entries are uv-submittable, and stop
  calling trl/scripts/sft.py an example script
- add the missing run-command docstrings (grpo_2048, ppo_sentiment, ppo_tldr)
  and drop rloo_math's pip line that disagreed with its script header
- examples/README.md: defer the layout description to the docs page instead of
  duplicating it
- distillation_trainer.md: the section documents the CLI, not an example script
- drop the stale examples/notebooks/wandb/ gitignore entry
- add a test asserting the example_overview Index stays in sync with the
  examples/ folders
Comment thread examples/sft_qwen3_8b_1m_context/sft_qwen3_8b_1m_context.py
Comment thread examples/sft_qwen3_8b_1m_context/sft_qwen3_8b_1m_context.py
qgallouedec and others added 5 commits August 27, 2026 22:32
`accelerate launch` does not read the script's dependency header, so the
`transformers>=5.0` it declares is not enforced. On v4 the `rope_parameters`
override is dropped silently and the run starts around loss 10.6 instead of 4.4.
Also quote the 1M step time measured on a correctly configured machine.

@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.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 78dde06. Configure here.

Comment thread examples/sft_qwen3_8b_1m_context/sft_qwen3_8b_1m_context.py
…rate one

huggingface/transformers#48444 landed the same offload behind
`gradient_checkpointing_kwargs={"offload": True}`, so the example no longer needs an unreleased
accelerate. Measured back to back on one 8xH100 node: 379.76 s/step with transformers, 379.75 s/step
with huggingface/accelerate#4175, same loss.
`gradient_checkpointing` is already `True` in `SFTConfig`. Also correct the `logging_steps` default
in the comment (10, not 500) and attribute the two version requirements separately.
The sequence parallelism and million-token material was two thirds of `distributing_training`, which
is otherwise about multi-GPU and multi-node launching. It gets its own page next to the other how-to
guides, and `distributing_training` points at it.
@qgallouedec
qgallouedec marked this pull request as draft September 1, 2026 14:21
The opening sentence called them the same thing, which the note right below it contradicts: here CP is
ring attention on FSDP2 and SP is ALST/Ulysses on DeepSpeed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

most of this is moved content. I want to re-write the whole section in a follow-up pr

@qgallouedec qgallouedec changed the title [WIP] Document 1M-token training and add a context-parallelism example Document 1M-token training and add a context-parallelism example Sep 1, 2026
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.

1 participant