Skip to content

[Bugfix][Rust Frontend] Bump fastokens to 0.3.6 - #66327

Open
waynehacking8 wants to merge 1 commit into
vllm-project:mainfrom
waynehacking8:rust-fastokens-0.3.6
Open

waynehacking8 wants to merge 1 commit into
vllm-project:mainfrom
waynehacking8:rust-fastokens-0.3.6

Conversation

@waynehacking8

@waynehacking8 waynehacking8 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Overview

With tencent/Hy3 or tencent/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

  • The Rust frontend encodes Hy3 text with a carriage return the same way as Hugging Face, instead of returning an error.
  • With 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.
  • A new Rust test fails on 0.3.5 with the error above and passes on 0.3.6.
  • Breaking for opt-in Python users: VLLM_USE_FASTOKENS=1 with fastokens 0.3.5 now fails at tokenizer load with an ImportError that names 0.3.6, for every model. 0.3.6 is on PyPI.

Validation

Served: vllm-rs serve tencent/Hy3 (Hub revision a960ebc3) with vllm-mock-engine, then /tokenize requests, built once with fastokens 0.3.5 locked and once with 0.3.6:

request 0.3.5 0.3.6
prompt "a\rb" HTTP 500, "byte 0x0d has no token in vocabulary" 200, same ids as Hugging Face
prompt "line one.\r\nline two" HTTP 500, same error 200, same ids as Hugging Face
chat message with \r\n HTTP 500, same error 200
prompt without \r 200, same ids as Hugging Face 200, same ids as Hugging Face

The 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_token in rust/src/tokenizer/src/hf.rs: it removes the \r token from the byte-level test vocab, adds a merge across the dropped byte (ĠĠ with Ċ), and compares encode and encode_ordinary with Hugging Face on six texts, with and without the fixture's fused pre-tokenizer setting. crusoecloud/fastokens#89 has its own test, but vLLM's encode_fastokens_ordinary calls the fused tokenize_batch_fused directly, which that test does not reach. It runs in the existing Rust frontend cargo CI step.

# in rust/; for 0.3.5, first set the Cargo.toml requirement to "0.3.5" and run:
cargo update -p fastokens --precise 0.3.5
cargo test -p vllm-tokenizer --lib hf::tests
fastokens 0.3.5: 14 passed, 1 failed: "encoding failed: model error: byte 0x0d has no token in vocabulary"
fastokens 0.3.6 (this PR): 15 passed

cargo fmt --check and cargo clippy -p vllm-tokenizer --all-targets --all-features -- -D warnings pass.

Python path, with transformers 5.22.2 (in vLLM's supported range): AutoTokenizer.from_pretrained on the Hy3 snapshot after fastokens.patch_transformers(), which is what VLLM_USE_FASTOKENS=1 calls, fails on 0.3.5 with the same error for three texts with \r and 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


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (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.

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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify

mergify Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Documentation preview: https://vllm--66327.org.readthedocs.build/en/66327/

@mergify mergify Bot added the documentation Improvements or additions to documentation label Nov 7, 2026
@mergify

mergify Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@mergify mergify Bot added recipe rust bug Something isn't working labels Nov 7, 2026

This branch was successfully deployed

1 active deployment
recipes-preview — 091ffe2e Deployed Nov 7, 2026 by waynehacking8 via dispatch #401
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation recipe rust

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant