fix(rollout): stop on every EOS id in the model's generation config (#9161)
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.
Signed-off-by: Puyuan Yao <williamyao034@gmail.com>