Repository navigation
[Bugfix][Rust Frontend] Bump fastokens to 0.3.6 - #66327
Open
waynehacking8 wants to merge 1 commit into
Open
waynehacking8 wants to merge 1 commit into
waynehacking8 wants to merge 1 commit into
Conversation
tencent/Hy3's byte-level vocabulary has no token for "\r", and its BPE
has neither an unk token nor byte fallback. fastokens 0.3.5 fails to
encode any text containing a carriage return ("byte 0x0d has no token
in vocabulary"), while Hugging Face tokenizers drops the byte and lets
the bytes around it merge. 0.3.6 (crusoecloud/fastokens#89) does the
same as HF.
Both fastokens paths had the bug, so both now require 0.3.6: the Rust
frontend's dependency, and the minimum for VLLM_USE_FASTOKENS=1 in
vllm/tokenizers/fastokens.py, envs.py and the docs, and the
Nemotron 3.5 Lightning recipe that installs fastokens for it.
The new Rust test builds a byte-level BPE without the "\r" token, with
and without the fused split, and checks encode and encode_ordinary
against HF on texts with a carriage return, including a merge across
the dropped byte. It fails on 0.3.5 with that error and passes on
0.3.6.
The only other change since 0.3.5 (crusoecloud/fastokens#87) shares
the segment cache between a tokenizer and its deep copies. That cache
is off unless FASTOKENS_SEGMENT_CACHE is set, and vLLM does not
enable it.
Signed-off-by: WEI CHENG CHIU <waynehacking8@gmail.com>
Assisted-by: AI tools
waynehacking8
requested review from
BugenZhao,
DarkLight1337,
esmeetu and
njhill
as code owners
November 7, 2026 23:22
Contributor
|
Documentation preview: https://vllm--66327.org.readthedocs.build/en/66327/ |
Contributor
This branch was successfully deployed
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.
Overview
With
tencent/Hy3ortencent/Hy3-preview, fastokens 0.3.5 fails on any text with a carriage return ("byte 0x0d has no token in vocabulary"), where Hugging Face tokenizers drops the byte. fastokens 0.3.6 (crusoecloud/fastokens#89, fixing crusoecloud/fastokens#88) drops it too and gives the same ids (both models fail in crusoecloud/fastokens#88 and match in the checks on crusoecloud/fastokens#89).vLLM uses fastokens in two places: the Rust frontend's tokenizer, and the optional Python backend behind
VLLM_USE_FASTOKENS=1. This PR moves both to 0.3.6.This change was prepared with AI assistance.
Claims
VLLM_USE_FASTOKENS=1, vLLM now requires fastokens 0.3.6 and says so in the import error, the env var help, the docs and the Nemotron 3.5 Lightning recipe that installs it.VLLM_USE_FASTOKENS=1with fastokens 0.3.5 now fails at tokenizer load with anImportErrorthat names 0.3.6, for every model. 0.3.6 is on PyPI.Validation
Served:
vllm-rs serve tencent/Hy3(Hub revision a960ebc3) withvllm-mock-engine, then/tokenizerequests, built once with fastokens 0.3.5 locked and once with 0.3.6:"a\rb""line one.\r\nline two"\r\n\rThe Python-parity test from #65757 (head dc36074) compares the Rust frontend's ids with the Python frontend's on a fixed corpus of 31 texts, 6 of them with
\r.With Hy3 it passes on 0.3.5 because it expects exactly this error for those 6 texts. On 0.3.6 its only failures are "matches Python now" for those 6, in both of its variants (the tokenizer as published, and with truncation and padding set), so all 31 texts give the Python frontend's ids.
New test,
fastokens_matches_hf_when_a_byte_has_no_tokeninrust/src/tokenizer/src/hf.rs: it removes the\rtoken from the byte-level test vocab, adds a merge across the dropped byte (ĠĠwithĊ), and comparesencodeandencode_ordinarywith Hugging Face on six texts, with and without the fixture's fused pre-tokenizer setting. crusoecloud/fastokens#89 has its own test, but vLLM'sencode_fastokens_ordinarycalls the fusedtokenize_batch_fuseddirectly, which that test does not reach. It runs in the existing Rust frontend cargo CI step.cargo fmt --checkandcargo clippy -p vllm-tokenizer --all-targets --all-features -- -D warningspass.Python path, with transformers 5.22.2 (in vLLM's supported range):
AutoTokenizer.from_pretrainedon the Hy3 snapshot afterfastokens.patch_transformers(), which is whatVLLM_USE_FASTOKENS=1calls, fails on 0.3.5 with the same error for three texts with\rand gives the same ids as Hugging Face on 0.3.6. The Python version gate has no test, and I did not serve through the Python frontend. The mock engine emits random tokens, so these runs say nothing about generation.Details
fastokenson 2026-11-08; [Rust Frontend] Use fastokens for tiktoken models #51027 still pins 0.3.1).\r(which byte-level BPE writes asč), and its BPE has no unk token and no byte fallback. fastokens' merge routines for raw bytes assumed every byte has a token in the vocab. Hugging Face drops a byte it cannot map, and the bytes on either side can still merge into one token across the gap; 0.3.5 returned an error instead.FASTOKENS_SEGMENT_CACHEis set, and vLLM does not set it.Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.