[GOLD][vLLM] On-policy generation decodes prompts with skip_special_tokens=True (chat template stripped) — intentional?
Hi TRL team, thanks for GOLD and the vLLM integration.
I’m trying to understand the intended behavior of GOLD’s on-policy generation with vLLM, which was originally identified by @simran135 and discussed in https://github.com/siyan-zhao/OPSD/issues/3.
In v0.29.0, this line says:
https://github.com/huggingface/trl/blob/v0.29.0/trl/experimental/gold/gold_trainer.py#L1680
"Decode prompts for vLLM (without special tokens - vLLM expects clean text)"
In _generate_on_policy_outputs_vllm, prompts are decoded with skip_special_tokens=True before being sent to vLLM:
prompts_text_for_vllm = self.processing_class.batch_decode(
inputs["prompts"],
skip_special_tokens=True, # strips <|im_start|>, <|im_end|>, etc.
)
This strips chat-template special tokens (e.g., <|im_start|>, <|im_end|>, role markers) before vLLM receives the prompt. Then vLLM gets raw text and tokenizes it, rather than receiving the original templated prompt IDs.
For chat-template-driven models (e.g., Qwen3), this may change rollout behavior. In particular, if thinking mode depends on template-time controls (such as template kwargs), it may not be activated during on-policy vLLM generation.
Questions
- Is using
skip_special_tokens=Truehere intentional? - What is the reason for requiring “clean text” instead of preserving templated prompt IDs/text?
Looking forward to your response. Thanks!
Thanks @siyan-zhao for raising this with the TRL team.
For reference, this behavior was originally identified and discussed in my original OPSD issue.
In that thread, I reported that _generate_on_policy_outputs_vllm decodes prompts with skip_special_tokens=True before sending them to vLLM. This strips chat-template tokens (e.g. <|im_start|>, <|im_end|>), meaning vLLM receives plain text rather than the original templated prompt.
As a consequence:
-
student rollouts become raw text continuations instead of chat-mode completions
-
template-controlled behaviors (e.g. thinking modes in chat models) may not activate during generation
-
the prompt is re-tokenized, which can create a length mismatch relative to the original student_prompt_length
The maintainers confirmed there that this behavior was not intentional and was inherited from TRL’s GOLDTrainer.
Linking the original report and discussion here so the timeline and prior analysis are available. I’ve attached a screenshot from that thread as well for convenience.
This still looks present on main: in _generate_on_policy_outputs_vllm, the prompts are decoded with skip_special_tokens=True before being sent to vLLM (trl/experimental/gold/gold_trainer.py:1142):
prompts_text = self.processing_class.batch_decode(
prompt_ids_list,
skip_special_tokens=True,
)
So the chat-template special tokens (<|im_start|>, <|im_end|>, role markers, and any <think>-style controls) are stripped, and vLLM re-tokenizes raw text rather than receiving the templated prompt. As @siyan-zhao and @simran135 note, for chat-template-driven models (e.g. Qwen3) this can change rollout behavior, including thinking-mode activation that depends on template-time controls.
@kashif — this is assigned to you and has been open since March without a verdict. If you haven't started on it, I'm happy to take it: the straightforward fix is to pass the already-templated prompt token IDs to vLLM (llm.generate(prompt_token_ids=...)) instead of decoding to text and letting vLLM re-tokenize — that preserves the exact templated prompt and avoids the round-trip entirely. If you'd prefer to keep the text path, the minimal change is skip_special_tokens=False.
Let me know if you're already on this or want me to open a PR — and which approach you'd prefer.
Yes a minimal change fix would be great!
@kashif before writing the minimal change I traced the current generation path, and I think this is already resolved on main — the decode-to-text path the issue describes no longer exists.
What the issue reported (v0.29.0)
Prompts were decoded to text with skip_special_tokens=True and that text was sent to vLLM, which re-tokenized it — stripping <|im_start|>/<|im_end|>/role markers before generation.
What main does now
Generation passes the templated token IDs straight to vLLM, no decode→re-tokenize round-trip:
# trl/experimental/gold/gold_trainer.py
_, completion_ids, _, _ = self.vllm_generation.generate(
prompts=prompt_ids_list, # token IDs, not text
images=None,
num_generations=self.num_generations,
)
VLLMGeneration.generate takes token IDs by contract and forwards them via vLLM's pre-tokenized path:
# trl/generation/vllm_generation.py
def generate(self, prompts: list[list[int]], ...):
"""prompts: List of token ID lists, one per prompt (already tokenized)."""
...
vllm_prompts = [{"prompt_token_ids": ids} for ids in all_prompts]
all_outputs = self.llm.generate(vllm_prompts, sampling_params=sampling_params, use_tqdm=False)
So vLLM receives the exact templated prompt IDs and never re-tokenizes raw text. The Qwen3 thinking-mode concern from the original report doesn't apply on main, since the template-time tokens are preserved.
This changed in #5351 (migration to the shared trl.generation.VLLMGeneration), merged after this issue was opened — which is why the issue is still open even though the code path it points at is gone.
The one remaining skip_special_tokens=True
There's still a skip_special_tokens=True decode in _generate_on_policy_for_slices, but it only builds the human-readable prompt string for _buffered_text_logs (the completions log). It doesn't feed generation, the training tensors, or the byte offsets (_maybe_add_completion_byte_offsets derives those from the sampled token IDs, not from this text). One small inconsistency: this prompt log strips special tokens while the completion log and the teacher-conditioning prompt decode keep them — so the logged prompt omits <|im_start|> etc. That's cosmetic, not a generation/training issue. Happy to send a one-line tweak to align it if you think the logs should show the templated prompt, but I'd keep that separate from this issue.
I think #5241 can be closed as resolved by #5351. Let me know if you still see the special tokens being stripped before generation on a recent version — happy to dig further if so.