Skip to content

[rl] Bug fix: Do not give vLLM a fake eos_token_id - #4987

Merged
wwwjn merged 8 commits into
pytorch:mainfrom
wwwjn:rl-vllm-no-fake-eos
Oct 2, 2026
Merged

wwwjn merged 8 commits into
pytorch:mainfrom
wwwjn:rl-vllm-no-fake-eos

Conversation

@wwwjn

@wwwjn wwwjn commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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.

@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Oct 1, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 1, 2026
@wwwjn wwwjn changed the title [rl] Do not give vLLM a fake eos_token_id [rl] Bug fix: Do not give vLLM a fake eos_token_id Oct 1, 2026
Comment on lines +101 to +102
# know the tokenizer's ids, so leave them unset; vLLM takes EOS from
# the tokenizer and callers pass any other stop tokens.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how? I guess it's via this renderer?

self._renderer = renderer_config.build(tokenizer=tokenizer)

@wwwjn wwwjn Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.json in 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.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@wwwjn wwwjn Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 or config.json, and also tokenizer.
  • So ideally we should stop vllm reading from type 1 EOS. We can set SamplingParams.ignore_eos to let vllm ignore EOS tokens from type1. I added that to this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

offline discussion: let's ban Type 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Screenshot 2026-10-01 at 5 32 50 PM

So I put both ignore_eos=True and skip_tokenizer_init=True. So only type 2 serves.

@wwwjn
wwwjn requested a review from tianyu-l October 1, 2026 21:43
Comment thread torchtitan/rl/generator.py Outdated
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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@wwwjn
wwwjn force-pushed the rl-vllm-no-fake-eos branch from 3f9742f to e0e1189 Compare October 1, 2026 23:58
wwwjn added 8 commits October 1, 2026 17:43
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.
@wwwjn
wwwjn force-pushed the rl-vllm-no-fake-eos branch from e0e1189 to 9e49329 Compare October 2, 2026 00:53
@wwwjn
wwwjn merged commit c327638 into pytorch:main Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants