Skip to content

fix(rollout): stop on every EOS id in the model's generation config - #9161

Queued
anyadontfly wants to merge 1 commit into
deepspeedai:masterfrom
anyadontfly:fix-rollout-generation-config-eos-ids
Queued

anyadontfly wants to merge 1 commit into
deepspeedai:masterfrom
anyadontfly:fix-rollout-generation-config-eos-ids

Conversation

@anyadontfly

Copy link
Copy Markdown
Contributor

Fixes #9157.

Summary

HybridEngineRollout ended responses only on the tokenizer's eos_token_id, so a model whose generation_config lists more EOS ids (Qwen3, Llama 3.1) kept decoding past them to max_new_tokens. Every path now stops on the tokenizer's id and every id in generation_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).
  • The set replaces the tokenizer's id in _generation_kwargs (generate() and the ZeRO-3 stopping criterion), _pad_after_eos on the static path, _is_eos in both continuous loops, and every EOS check of _generate_graph. A single id is still passed to generate() as a scalar.
  • Docs: which ids end a response.

Behavior change: setting only tokenizer.eos_token_id to an id that never occurs no longer disables EOS when the generation config lists one; set generation_config.eos_token_id = None as well. The v1 test models now do.

Tests

  • CPU: 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, replacing test_non_zero3_generation_uses_native_eos, checks that generate() gets the list and that a row ends at its first id of either kind.
  • GPU: test_every_path_stops_on_a_generation_config_eos_id on static, static graph, continuous and continuous graph, against generate() 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.

Command Result
pytest tests/unit/v1/test_hybrid_engine_rollout_v1.py (2 GPUs) 50 passed, 1 skipped (opt-in pretrained test)
pytest tests/unit/runtime/rollout 195 passed, 3 skipped (two 4-GPU classes, one model download)

Reproduction 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.isin over 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.

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

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T07:40:26.225435Z b197093 PR opened
ℹ️ 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.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@delock
delock added this pull request to the merge queue Nov 24, 2026

This branch has not been deployed

No deployments
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.

[BUG] HybridEngineRollout stops only on the tokenizer's EOS id, not on those in the model's generation_config

2 participants