Skip to content

[router] fix chat template loading and tokenizer path#10999

Merged
slin1237 merged 3 commits intomainfrom
tokenizer-chat-template-fix
Sep 28, 2025
Merged

[router] fix chat template loading and tokenizer path#10999
slin1237 merged 3 commits intomainfrom
tokenizer-chat-template-fix

Conversation

@slin1237
Copy link
Collaborator

  1. fix chat template detection
  2. fix to tokenizer path
  3. add chat template order
  4. add bunch of UT for horribly standardized tokenizer config and chat template in HF _(ツ)_/¯

Checklist

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @slin1237, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refines the tokenizer loading mechanism, particularly for models that utilize chat templates. It addresses the diverse ways Hugging Face models store their chat templates and tokenizer configurations, ensuring the router can reliably discover and apply the correct template. The changes also improve the robustness of identifying the core tokenizer files within complex cache structures, leading to more consistent and accurate model initialization.

Highlights

  • Chat Template Detection: Improved the logic for detecting chat templates, introducing a priority order to find chat_template.json, chat_template.jinja, or any other .jinja file, and handling templates embedded within tokenizer_config.json.
  • Tokenizer Path Resolution: Enhanced the resolution of tokenizer file paths within the Hugging Face cache, correctly identifying the base model directory even when files are nested in subfolders like 'original'.
  • JSON Chat Template Support: Added support for parsing chat templates from chat_template.json files, which can contain the Jinja template string directly or within a 'chat_template' field.
  • Comprehensive Unit Tests: Introduced a suite of new unit and integration tests to cover various scenarios of chat template discovery and tokenizer loading for different Hugging Face models (e.g., TinyLlama, Qwen3-Next, Qwen3-VL, LLaVA).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@slin1237 slin1237 added router bug Something isn't working labels Sep 28, 2025
Copy link
Contributor

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

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 introduces significant improvements to tokenizer and chat template loading, particularly for models from Hugging Face. The changes include a more robust discovery mechanism for chat templates with a clear priority order, and better handling of different HF cache directory structures. The addition of extensive integration tests for various models is a great step towards ensuring correctness. My review focuses on a few areas for improvement: reducing code duplication in the template discovery logic, addressing potential panics from unsafe unwraps, fixing a potential logic issue in path resolution, and making the new integration tests more robust in a CI environment.

@slin1237
Copy link
Collaborator Author

Screenshot 2025-09-27 at 6 23 44 PM

@slin1237 slin1237 merged commit 5519766 into main Sep 28, 2025
77 of 90 checks passed
@slin1237 slin1237 deleted the tokenizer-chat-template-fix branch September 28, 2025 03:54
Lekro-xsy pushed a commit to Lekro-xsy/sglang that referenced this pull request Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working router run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments