fix: mistral embedding regression fix#21913
Merged
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
JustinTong0323
approved these changes
Apr 2, 2026
Collaborator
JustinTong0323
left a comment
There was a problem hiding this comment.
LGTM. Root cause analysis is clear and the fix is minimal and correct — for fast tokenizers, should remain to match HF reference behavior. Good bisection work.
JustinTong0323
approved these changes
Apr 2, 2026
Collaborator
JustinTong0323
left a comment
There was a problem hiding this comment.
LGTM. Root cause analysis is clear and the fix is minimal and correct. For fast tokenizers, add_eos_token should remain False to match HF reference behavior. Good bisection work.
Collaborator
|
/tag-and-rerun-ci |
091dce5 to
619e344
Compare
sundar24295s
pushed a commit
to sundar24295s/sglang
that referenced
this pull request
Apr 4, 2026
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.
Motivation
Embedding models using
LlamaTokenizerFast(e.g.intfloat/e5-mistral-7b-instruct) regressed in cosine similarity from ~1.0 to ~0.33 after the transformers v5.3.0 upgrade (#17784). The regression was identified by bisecting between v0.5.9 (good) and v0.5.10rc0 (bad), pinning the first bad commit to d1e95af ("Upgrade transformers==5.3.0 (#17784)").Root cause
The transformers v5 upgrade introduced
_fix_v5_add_bos_eos_token()to restoreadd_bos_token/add_eos_tokenflags that v5 strips when atokenizer.jsonpost-processor is present. The fix correctly handlesadd_bos_tokenfor generative models like DeepSeek-V3, but incorrectly also restoredadd_eos_tokenfor fast tokenizers.For fast tokenizers (
PreTrainedTokenizerFast),add_eos_tokenwas never applied via the Python-level attribute in transformers v4 — EOS behavior was defined intokenizer.json's post-processor. In v5, both sglang and HF vanilla end up withadd_eos_token=False. By restoringadd_eos_token=Trueonly in sglang (but not in the HF reference), the tokenizers diverge:The model's
tokenizer_config.jsonhas"add_eos_token": truebecause Mistral uses EOS as a generation stop token — but forLlamaTokenizerFast, this was always handled by the post-processor, not the Python attribute. The attribute existed in v4 but was a no-op for fast tokenizers.Modifications
In
_fix_v5_add_bos_eos_token(), skip restoringadd_eos_tokenwhen the loaded tokenizer is aPreTrainedTokenizerFastinstance. This matches v5 vanilla behavior (which also doesn't restore it) and keeps sglang consistent with the HF reference for fast tokenizers.add_bos_tokenrestoration is unaffected.Accuracy Tests
Tested on
intfloat/e5-mistral-7b-instructwith a full clean reinstall (sglang + sglang-kernel uninstalled and reinstalled from scratch):Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci