Skip to content

feat(parser): resolve special-token suffix at runtime for compatibility - #29920

Merged
ispobock merged 4 commits into
sgl-project:mainfrom
JustinTong0323:xinyuan/hy3-md5-suffix
Jul 4, 2026
Merged

ispobock merged 4 commits into
sgl-project:mainfrom
JustinTong0323:xinyuan/hy3-md5-suffix

Conversation

@JustinTong0323

@JustinTong0323 JustinTong0323 commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Some tokenizers append a shared suffix to every special token (e.g. <tool_calls:TAG> instead of <tool_calls>). The hunyuan reasoning/tool-call detectors and the --tool-call-parser auto rule 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.
  • Plumb an optional tokenizer through ReasoningParser / FunctionCallParser (via inspect, so non-hunyuan detectors are untouched).
  • _is_hunyuan matches bare or suffixed tool_calls/tool_sep via regex, so --tool-call-parser auto still resolves to hunyuan.
  • structure_info uses the resolved tokens; 16 call-sites pass tokenizer=.

Verification

pre-commit + py_compile pass; tokenizer=None reproduces 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

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 3, 2026
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.
@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/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).
@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

4 similar comments
@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@JustinTong0323

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants