Repository navigation
[Qwen3.5 & Qwen3.8][Tokenizer] Enable fastokens to reduce host overhead during prefill - #116
Conversation
- Restore Qwen checkpoint components only for Fastokens. - Preserve runtime state and checkpoint revisions in both loading paths. - Require Fastokens >=0.3.6,<0.4.0; retain Hugging Face behavior. - Validate 77 CPU tests, 512 canonical matches and 512 unchanged HF matches. Signed-off-by: Xiake Sun <[email protected]>
- Enable Fastokens in the four Qwen3.5 launchers. - Declare the Fastokens 0.3.6 pin once in HIP dependency metadata. - Share the dependency across HIP variants, CI and the evaluation setup. - Validate launch arguments, dependency resolution and 72 CI tests. Signed-off-by: Xiake Sun <[email protected]>
c625fde to
a51a4bf
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The primary fastokens extra still allows versions missing required APIs, which can abort tokenizer or processor loading, and the test base-class change bypasses required CI retry handling.
2 open issues
What changed in this PR
This PR enables Fastokens for Qwen3.5 evaluation to reduce CPU tokenization overhead during prefill while preserving checkpoint token IDs.
Changes:
- Rebuild Fastokens backends when checkpoint components differ, preserving live state and aligning tokenizer loading and repair revisions.
- Enable Fastokens in four Qwen3.5 launchers and add the pinned dependency to alternate HIP installation extras.
- Add local regression coverage and document the tokenizer choices; Qwen3.8 launchers remain unchanged.
| File | Description |
|---|---|
test/registered/unit/utils/test_hf_transformers_fastokens.py |
Adds local fixtures and regression tests for checkpoint IDs, loaders, revisions, and state preservation. |
python/sglang/srt/utils/hf_transformers/tokenizer.py |
Adds Fastokens component rebuilding and revision alignment. |
python/sglang/srt/utils/hf_transformers/processor.py |
Applies Fastokens repair and forwards backend selection through tokenizer routes. |
python/pyproject_other.toml |
Pins Fastokens 0.3.6 and includes it in HIP extras. |
evaluation/Qwen4_Evaluation_Guide.md |
Documents Qwen3.5 and Qwen3.8 tokenizer choices. |
evaluation/launch_qwen3.5-397B-fp8_tp8_disable_prefix_cache.sh |
Enables Fastokens for 397B target-only evaluation. |
evaluation/launch_qwen3.5-397B-fp8_tp8_dflash_with_prefix_cache.sh |
Enables Fastokens for 397B DFlash evaluation. |
evaluation/launch_qwen3.5-35B-fp8_tp4_disable_prefix_cache.sh |
Enables Fastokens for 35B target-only evaluation. |
evaluation/launch_qwen3.5-35B-fp8_tp1_dflash_with_prefix_cache_mfs0.7_bs32.sh |
Enables Fastokens for 35B DFlash evaluation. |
Review effort: Balanced
- Retain the registered test base and its CI retry handling. - Call the base setUp method to preserve CI test logging. Signed-off-by: Xiake Sun <[email protected]>
- Enable Fastokens in TP1, multi-TP and long-context launchers. - Document CI and R-Fork inheritance from the shared launcher. Validation: 72 CPU tests and 11 captured launch scenarios. Signed-off-by: Xiake Sun <[email protected]>
Signed-off-by: Xiake Sun <[email protected]>
|
[Performance Benchmark Run 1]: PR #116 MI308X CI comparison with PR #117
Performance deltas are Accuracy and latency
Throughput and speculative decoding
Takeway
|
|
[Performance Benchmark Run 2] AITER #12 → AITER #12 + AITER #13 + AITER #14 on SGLang #PR116 All six cases passed on both builds. This Run2 mainly focus on BF16 PTPC and FP8 GEMM tuning for Qwen3.8 TP2 (not hit by CI con=1 settings), Qwen3.5 35B TP2 and Qwen3.5 397B TP8. For Qwen3.5-35B TP2 Base at concurrency 8, adding AITER #13 and #14 reduced mean TTFT by 3.39%, mean TPOT by 9.15%, and mean end-to-end latency by 7.87%. QPS increase from 1.4574 to 1.5819 (+8.54%).
Values run from Run1 → Run2. Deltas use unrounded CI artifact values. Each GSM8K score covers 200 examples. Both AITER changes were present in every attempt 6 measurement, so the individual contribution of either PR cannot be inferred. Accuracy and latency
Throughput and speculative decoding
Takeway
|
|
[Performance Benchmark Run 3] AITER #12 + AITER #13 + AITER #14 → +AITER #12 + AITER #13 + AITER #14 + AITER #15 on SGLang #PR116 All six model cases passed on both builds. This benchmark run focus on valid AITER #15 that tunes Qwen3.5 TP2 MoE and optimizes FlyDSL intermediate quantization.
Values run from Run 2 after (attempt 6) → Run 3 (attempt 7). Performance deltas are Accuracy and latency
Throughput and speculative decoding
Findings
|


Motivation
This PR add
--tokenizer-backend fastokensto preserve Qwen3.5's checkpoint tokenization and reduce TTFT CPU host overhead during long context prefill.Root cause:
4.57.1, the HF tokenizer fast loader preservestokenizer.json.5.12.1uses Qwen2's default regex instead of Qwen3.5's combining-mark-aware regex. The transformers v5 refactor transformers#42563 rebuilds Qwen2 from vocabulary/merges without restoring the checkpoint pre-tokenizer, so current base. Fastokens wraps that altered backend, so the flag alone cannot recover the checkpoint IDs.On 256 frozen prompt texts, this produces 4.33% more input tokens: 25,671.61 instead of 24,606.54 on average.
The fix restores the checkpoint components when Fastokens is selected. The default Hugging Face backend keeps its existing behavior.
Modifications
--tokenizer-backend fastokens, covering target-only and DFlash configurations.python/pyproject_other.tomlto installfastokens 0.3.6through sglang installationThe diagram shows the Fastokens loading path. Token counts are means over the same 256 prompt texts.
flowchart LR CK["Checkpoint<br/>tokenizer.json"] --> HF["Transformers v5<br/>rebuilds Qwen2 components"] HF --> FK["Fastokens wraps<br/>the loaded backend"] FK --> OLD["Before: altered components<br/>25,671.61 input tokens"] FK --> FIX["This PR<br/>Compare component contents"] CK -. "checkpoint components" .-> FIX FIX --> NEW["Rebuild Fastokens if different<br/>Preserve live vocabulary and state<br/>24,606.54 checkpoint input tokens"]Sequencewhile containing different regexes.get_tokenizerandget_processor, using the same checkpoint revision for loading and repair.Upstream #49393 adds an existing repair-helper call to processor loading for default huggingface tokenzier.
This PR implements fix for a separate fastokens-specific backend rebuild.
Speed Tests and Profiling
CPU encoding
Validation with Transformers
5.12.1, tokenizers0.22.2, fastokens0.3.6. Each round encodes the same 256 prompts with the server's batch-of-one call after warmup. Ranges cover fresh-process rounds; validation and hashing are outside the timed calls.--tokenizer-backend huggingface--tokenizer-backend fastokensFastokens supplies the encoding speedup; the component repair restores the checkpoint token IDs.
TTFT diagnostic
Setup: 8 × MI308X (80CU), PTL 256 frozen prompt texts, nominal 24K input, C1 / output 1, zero shared prefix, radix cache disabled, 32K chunk prefill budgets and stock GEMM/MoE dispatch. All three runs completed 256/256 requests with zero errors.
Accuracy Tests
Add pytest to check CPU validation of token IDs and loader behavior:
python3 -m unittest discover \ -s test/registered/unit/utils \ -p 'test_hf_transformers*.py' -vQwen3.8 compatibility and state-preservation checks
Both loaders were compared before/after on ten short probes and sixteen long texts per checkpoint:
The export groups have different tokenizer assets. Hugging Face IDs remain unchanged for every tested group. These checks establish tokenization behavior, not full model-accuracy equivalence.
Unit coverage includes runtime-added vocabulary, post-processing, padding/truncation, special-token mode, PCRE2 options, revision handling and repeated repair.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci