Repository navigation
Fix double BOS when using chat templates (vllm, transformers, sglang backends) - #1467
Open
EvanZhuang wants to merge 1 commit into
Open
EvanZhuang wants to merge 1 commit into
EvanZhuang wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
with
use_chat_template, lighteval renders the template to text (apply_chat_template(..., tokenize=False), which already has<|begin_of_text|>) and then tokenizes it withadd_special_tokens=True, so Llama 3, Gemma 2/3, and Mistral v0.3 chat prompts start with two BOS tokens ([128000, 128000, 128006, ...]).huggingface/open-r1#462noted this earlier and #598 madeadd_special_tokens=Falsesettable from the CLI while keeping theTruedefault (setting it globally strips the BOS that plain-text base prompts need).lighteval vllmonmeta-llama/Llama-3.2-1B-Instruct(gsm8k|0,ifeval|0, greedy, 1x H100):mainadd_special_tokens=False[128000, 128000][128000, 128006][128000, 128006]extractive_match(n=1,319)Fix: in
VLLMModel,TransformersModel, andSGLangModel,add_special_tokensreturnsself._add_special_tokens and not self.use_chat_template, skipping extra special tokens only for rendered chat templates while base mode keeps its BOS. If a chat template omits BOS while its tokenizer adds one, chat mode now matchesapply_chat_template(tokenize=True)and omits that BOS.Tests: unit tests in
test_vllm_model.pyandtest_transformers_model.py(Llama-3.2-1B-Instructchat/base,Qwen3-0.6B), andoverride_chat_template=Falseintest_loglikelihood_rolling_matches_manual_scoring.repro (prints the first prompt token ids): https://gist.github.com/EvanZhuang/90f4eba2e660cfdd1997ea77f129191b