Repository navigation
feat(parser): resolve special-token suffix at runtime for compatibility - #29920
Conversation
Some tokenizers append a shared suffix to every special token (e.g. <tool_calls:TAG> instead of <tool_calls>). The hunyuan detectors and the auto-detection rule hard-coded the bare literals, so both the reasoning/tool-call parsers and --tool-call-parser=auto broke on such tokenizers. - Add resolve_hunyuan_tokens(tokenizer) to scan the vocab for the real (possibly suffixed) token strings, falling back to bare literals so the same detector serves both suffix-less and suffixed tokenizers. - Plumb an optional tokenizer through ReasoningParser / FunctionCallParser into both HunyuanDetector classes; detectors that don't accept it are skipped via inspect, so non-hunyuan paths are untouched. - Add has_vocab_pattern to TemplateDetectionContext; make _is_hunyuan match bare or suffixed tool_calls/tool_sep via regex so auto-detection still resolves to hunyuan. - structure_info now uses the resolved tokens instead of literals.
There was a problem hiding this comment.
Code Review
This pull request updates the reasoning and function call parsers to dynamically resolve Hunyuan special tokens from the tokenizer vocabulary at runtime, allowing compatibility with both preview and shipping Hunyuan v3 tokenizers. The feedback recommends adding type checks when iterating over vocabulary keys to prevent potential TypeError crashes, and pre-compiling regex patterns in has_vocab_pattern to optimize performance over large vocabularies.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/tag-and-rerun-ci |
Mock tokenizers (used in unit tests) return a Mock from get_vocab() which is truthy but not iterable, causing TypeError. Check isinstance(dict) so the resolver falls back to bare literals instead of crashing.
|
/rerun-failed-ci |
The previous refactor dropped tool_call_start_token from structure_info's begin string, breaking test_structure_info_content. Restore it (resolved from vocab, same as the other tokens).
|
/rerun-failed-ci |
4 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
Motivation
Some tokenizers append a shared suffix to every special token (e.g.
<tool_calls:TAG>instead of<tool_calls>). Thehunyuanreasoning/tool-call detectors and the--tool-call-parser autorule hard-coded the bare literals, so both parsing and auto-detection broke on such tokenizers. Resolving the real token strings from the vocab at runtime is preferable to hard-coding a per-model suffix.Changes
resolve_hunyuan_tokens(tokenizer): scan the vocab for the real (possibly suffixed) token strings, falling back to bare literals — one detector serves both suffix-less and suffixed tokenizers.tokenizerthroughReasoningParser/FunctionCallParser(viainspect, so non-hunyuan detectors are untouched)._is_hunyuanmatches bare or suffixedtool_calls/tool_sepvia regex, so--tool-call-parser autostill resolves tohunyuan.structure_infouses the resolved tokens; 16 call-sites passtokenizer=.Verification
pre-commit + py_compile pass;
tokenizer=Nonereproduces the previous token values exactly (backward compatible); e2e confirms auto-detection, tool-call/reasoning parsing, and stop-rate all work on a suffixed tokenizer.CI States
Latest PR Test (Base): ✅ Run #28694968273
Latest PR Test (Extra): ❌ Run #28694968200