fix(sa-bench): auto-fallback when tokenizer has no chat template#74
Closed
fix(sa-bench): auto-fallback when tokenizer has no chat template#74
Conversation
Models like DeepSeek-V4 ship no Hugging Face chat template; rendering lives entirely inside the engine. With the default `use_chat_template: true` (introduced in #20) and no `custom_tokenizer` plugin, sa-bench called `tokenizer.apply_chat_template(...)` directly and crashed with `ValueError: ... has no chat template`. Detect this case in `main()` after `get_tokenizer` returns: if `use_chat_template` is on but the tokenizer exposes neither `chat_template` nor `default_chat_template`, emit a loud warning and fall back to the raw-text path so the run completes. Users who care about exact token-count parity with the server are pointed at `custom_tokenizer` (e.g. SGLangDeepseekV4Tokenizer added in #73). Recipes that already set `custom_tokenizer` are unaffected.
Collaborator
Author
|
Superseded by #76, which takes a fail-fast approach with an actionable error instead of a silent auto-fallback. Auto-fallback risks producing benchmark numbers from a different code path than the recipe intends (the client/server token counts can diverge, as this PR's own warning notes). #76 also fixes a separate silent bug where bench.sh warmup was missing CHAT_TEMPLATE_ARGS. |
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.
Summary
Some models (e.g. DeepSeek-V4) ship no Hugging Face chat template; their rendering happens entirely inside the engine via a hard-coded encoder. With the project-wide default
use_chat_template: trueintroduced in #20, recipes that don't also setcustom_tokenizerend up callingtokenizer.apply_chat_template(...)directly and crash with:Reported by @ishandhanani while running the dsv4 sa-bench recipes against srt-slurm without the new flags from #73.
Fix
In
benchmark_serving.main(), right afterget_tokenizerreturns, detect the no-template case:use_chat_templateis on and nocustom_tokenizerplugin is configured and the tokenizer exposes neitherchat_templatenordefault_chat_template,warnings.warn(...)pointing atcustom_tokenizer(e.g.SGLangDeepseekV4Tokenizeradded in feat(sa-bench): add sglang DeepSeek-V4 tokenizer #73),args.use_chat_template = Falseso the run completes against the raw-text path.This way:
custom_tokenizer: sa_bench_tokenizers.sglang_deepseek_v4.SGLangDeepseekV4Tokenizer-> unchanged: real DSML rendering, exact parity with sglang server.Test plan
python3 -m py_compile benchmark_serving.pycustom_tokenizer/use_chat_templateoverrides; confirm warning + successful sa-bench completion.recipes/gb300-fp4/1k1k-dsv4/agg-low-latency-chat.yaml) withcustom_tokenizerset; confirm no behavior change vs. main.Made with Cursor