Repository navigation
fix(rollout): stop on every EOS id in the model's generation config - #9161
anyadontfly wants to merge 1 commit into
Conversation
HybridEngineRollout ended responses only on the tokenizer's eos_token_id. Passed to generate(), it replaced the list in generation_config, and the continuous loops, the static graph decode and _pad_after_eos compared against the same single id. Models that list more EOS ids, such as Qwen3 (<|im_end|>, <|endoftext|>) or Llama 3.1 (<|eom_id|> after a tool call), kept decoding past them to max_new_tokens. _eos_token_ids() merges the tokenizer's id with generation_config's, in that order, without duplicates or negative ids (generate() ignores a list that holds one). Every path stops, trims and checks for EOS on that set; a single id is still passed to generate() as a scalar. Setting only tokenizer.eos_token_id to an id that never occurs no longer disables EOS when the generation config lists one, so the v1 test models set eos_token_id=None in their configs. Signed-off-by: Puyuan Yao <williamyao034@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1970933b7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| rollout = HybridEngineRollout(SimpleNamespace(module=module), | ||
| SimpleNamespace(pad_token_id=0, eos_token_id=tokenizer_eos)) | ||
|
|
||
| assert rollout._eos_token_ids() == expected |
There was a problem hiding this comment.
Exercise EOS merging through the public rollout API
This test asserts the private _eos_token_ids() representation, and the adjacent test calls _is_eos() directly, so an equivalent implementation that removes these helpers or represents the same EOS set differently would fail even when every rollout path preserves the contract. Replace these with assertions through generate() (the added public-path test already provides that surface), or add the explicitly required fixed-bug justification; AGENTS.md requires tests to survive a different correct implementation and forbids private-return assertions without such a comment.
AGENTS.md reference: AGENTS.md:L76-L78
Useful? React with 👍 / 👎.
Fixes #9157.
Summary
HybridEngineRolloutended responses only on the tokenizer'seos_token_id, so a model whosegeneration_configlists more EOS ids (Qwen3, Llama 3.1) kept decoding past them tomax_new_tokens. Every path now stops on the tokenizer's id and every id ingeneration_config.eos_token_id.Changes
_eos_token_ids()returns the tokenizer's EOS id, then the generation config's ids, without duplicates or negative ids (generate()ignores a list that holds one)._generation_kwargs(generate()and the ZeRO-3 stopping criterion),_pad_after_eoson the static path,_is_eosin both continuous loops, and every EOS check of_generate_graph. A single id is still passed togenerate()as a scalar.Behavior change: setting only
tokenizer.eos_token_idto an id that never occurs no longer disables EOS when the generation config lists one; setgeneration_config.eos_token_id = Noneas well. The v1 test models now do.Tests
test_eos_token_ids_merge_tokenizer_and_generation_config(an id, a list, overlap, no config, a negative tokenizer id);test_continuous_rows_end_on_a_generation_config_eos_id;test_non_zero3_generation_stops_on_every_eos_id, replacingtest_non_zero3_generation_uses_native_eos, checks thatgenerate()gets the list and that a row ends at its first id of either kind.test_every_path_stops_on_a_generation_config_eos_idon static, static graph, continuous and continuous graph, againstgenerate()with the same generation config. All four cases fail on master.Validation
Hardware and software: 2× NVIDIA A100-SXM4-40GB (driver 595.71.05), PyTorch 2.14.1+cu130, CUDA 13.0, Python 3.12.15, Transformers 5.19.0.
pytest tests/unit/v1/test_hybrid_engine_rollout_v1.py(2 GPUs)pytest tests/unit/runtime/rolloutReproduction on Qwen3-0.6B, fp32 greedy, with an extra EOS id the model generates midway: master generates the full 32 tokens on every path; this PR stops each row where
generate()does (3, 32, 4, 14 tokens) on all four paths.Performance: one
torch.isinover a few ids per step in place of an equality check; not measured separately.Compatibility matrix: single GPU and AutoTP 2 with ZeRO 0, fp32, on the paths above; ZeRO-3 is covered by the CPU tests of the stopping criterion, not on GPU.
AI assistance
This PR was written with AI assistance (Claude Code). The submitter reviewed every changed line and ran the tests above.