Repository navigation
[rl] Bug fix: Do not give vLLM a fake eos_token_id - #4987
Conversation
| # know the tokenizer's ids, so leave them unset; vLLM takes EOS from | ||
| # the tokenizer and callers pass any other stop tokens. |
There was a problem hiding this comment.
how? I guess it's via this renderer?
torchtitan/torchtitan/rl/rollout/rollouter.py
Line 254 in 6ff806f
There was a problem hiding this comment.
In short yes. But beside the renders' stop token, there are other source.
Agent gives this detailed explanation: Not only the renderer. vLLM stops a request on two kinds of token ids, and they come from different places:
Type 1:
- EOS is the tokenizer's end-of-sequence id, a single id (tokenizer.eos_token_id, <|endoftext|> for Qwen3.5). Read from
tokenizer_config.jsonin the checkpoint folder.- vLLM sets it on every request itself. The input processor calls
update_from_generation_config(gen_config, renderer.get_eos_token_id()) (vllm/v1/engine/input_processor.py:366), which reads it from the tokenizer (vllm/renderers/base.py:408). - The scheduler stops on it (vllm/v1/core/sched/utils.py:101).
- The caller doesn't pass it; it can only be switched off with ignore_eos.
- vLLM sets it on every request itself. The input processor calls
Type 2: From torchtitan
- Stop tokens are a list of extra ids that the caller chooses (SamplingParams.stop_token_ids).
- The common case is a chat template's end-of-turn token, which isn't the tokenizer's EOS. Qwen3.5 ends a turn with <|im_end|>.
- TorchTitan's renderer supplies them. The controller passes stop_token_ids=self.renderer.get_stop_token_ids() (controller.py:428) through SamplingConfig into SamplingParams (generator.py:1282); generate.py:177 does the same.
Type 3: Read from generation_config.json
- The generation config's eos_token_id is a third source: vLLM adds those ids to the stop tokens of every request (sampling_params.py:705). The fake 1 (") got into every request this way, which is why we set it to None. Real EOS still comes from the tokenizer, and the chat stop tokens still come from our renderer.
There was a problem hiding this comment.
I get Type 2.
- passed to generator all the way from https://github.com/pytorch/torchtitan/blob/main/torchtitan/rl/controller.py#L968 to https://github.com/pytorch/torchtitan/blob/main/torchtitan/rl/rollout/rollouter.py#L414 to generator https://github.com/pytorch/torchtitan/blob/main/torchtitan/rl/generator.py#L1099 (alternatively obtainable from generator config)
I didn't get Type 1.
- There is no chance in titan RL that vllm can get access to tokenizer -- we are doing token-in-token-out, in a sense that generator NEVER needs to interact with strings, because
TokenEnvis handling the translation viarendererhttps://github.com/pytorch/torchtitan/blob/main/torchtitan/rl/rollout/rollouter.py#L418 and https://github.com/pytorch/torchtitan/blob/main/torchtitan/rl/rollout/environment/token.py#L147 - Where does Type 1 come from?
Also, this is non-trivial, please add a note somewhere.
There was a problem hiding this comment.
Type1 comes from:
- vLLM loads the tokenizer itself. Token-in-token-out is how TorchTitan uses vLLM (strings never pass through the generator), but vLLM still builds its own tokenizer from what we passed the vllm engine
model=hf_asset_path), where in this folder, it might contain a genearation_config.json orconfig.json, and also tokenizer. - So ideally we should stop vllm reading from type 1 EOS. We can set
SamplingParams.ignore_eosto let vllm ignore EOS tokens from type1. I added that to this PR.
There was a problem hiding this comment.
offline discussion: let's ban Type 1
There was a problem hiding this comment.
Update: Sorry there should be 3 types. Type 1 is from file tokenizer_config.json ; Type 3 is from file generation_config.json. Eg, https://huggingface.co/Qwen/Qwen3.8-27B/tree/main this checkpoint has both files...
So I put both ignore_eos=True and skip_tokenizer_init=True. So only type 2 serves.
| stop_token_ids=sampling.stop_token_ids, | ||
| # Drops the generation config's eos ids, which vLLM merges into | ||
| # stop_token_ids even with skip_tokenizer_init. | ||
| ignore_eos=sampling.stop_token_ids is not None, |
There was a problem hiding this comment.
In normal cases, would it ever be None? This is more of a question to renderer lib.
Using common sense, I don't think it'd every be None, so I would rather add an assert instead of fallback.
There was a problem hiding this comment.
Yes, as we are closing type 1 and type 3, so we don't hope type 2 to be None as well. Changing it to assert
3f9742f to
e0e1189
Compare
model_config_to_hf_config_dict set eos_token_id=1 (and bos_token_id=0) as placeholders, assuming vLLM never reads them. When the checkpoint has no generation_config.json (e.g. Qwen3.5-9B), vLLM builds the generation config from this HF config and adds its eos_token_id to every request's stop set. Token 1 is '"' in the Qwen vocab, so every sampled double quote ended the completion: Terminal-Bench turns stopped after a few tokens, at the first quote, with no </think> or tool call. Leave both ids unset; vLLM takes EOS from the tokenizer and callers pass any other stop tokens. Test: new CPU test fails before (eos_token_id == 1) and passes after. TorchTitan VLLMGenerator on Qwen3.5-9B, a Terminal-Bench prompt, 16 seeds: before, every completion stops at the closing quote after 13-16 tokens; after, 212-344 tokens with full reasoning, matching stock vLLM.
vLLM loads the tokenizer from the checkpoint and, by default, stops every request on the tokenizer's EOS and on the generation config's eos_token_id. Set ignore_eos when the caller passes stop ids, so the renderer's ids (which already include the tokenizer's EOS) are the only stop source.
The generator is token-in-token-out, so vLLM does not need its own tokenizer. Skipping it removes the tokenizer eos_token_id as a stop. ignore_eos still drops the generation config eos ids, so the renderer's stop_token_ids stay the only stops. generate.py now encodes raw prompts and decodes outputs with the torchtitan tokenizer.
generate.py accepts raw string prompts and prints vLLM's decoded text, so it keeps vLLM's tokenizer. ignore_eos already limits its stops to the renderer's ids.
stop_token_ids is always filled from the renderer (controller, and the Verifiers renderer client), so assert it in generate() and reject requests without it in the Verifiers generation server; ignore_eos is now always on.
e0e1189 to
9e49329
Compare
model_config_to_hf_config_dict set eos_token_id=1 (and bos_token_id=0) as placeholders, assuming vLLM never reads them. When the checkpoint has no generation_config.json (e.g. Qwen3.5-9B), vLLM builds the generation config from this HF config and adds its eos_token_id to every request's stop set.
Token 1 is
"in the Qwen vocab, so every sampled double quote ended the completion: Terminal-Bench turns stopped after a few tokens, at the first quote, with no or tool call.Leave both ids unset; vLLM takes EOS from the tokenizer and callers pass any other stop tokens.
Test: new CPU test fails before (eos_token_id == 1) and passes after. TorchTitan VLLMGenerator on Qwen3.5-9B, a Terminal-Bench prompt, 16 seeds: before, every completion stops at the closing quote after 13-16 tokens; after, 212-344 tokens with full reasoning, matching stock vLLM.