Fix Hermes chat template validation error#4246
Conversation
Summary of ChangesHello, 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 addresses a Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request correctly adds hermes to the list of models that bypass the chat template validation, which resolves a RuntimeError. The change is straightforward and aligns with the existing implementation for mistral and qwen3guard. I have one suggestion to improve the code's maintainability by extracting the hardcoded list of model names into a constant.
| if any( | ||
| s in str(getattr(tokenizer, "name_or_path", "")).lower() | ||
| for s in ["mistral", "qwen3guard"] | ||
| for s in ["mistral", "qwen3guard", "hermes"] | ||
| ): |
There was a problem hiding this comment.
For better readability and maintainability, it's good practice to extract this list of model names into a well-named constant. This makes the code easier to understand and modify in the future. Using a tuple instead of a list is also slightly more performant for this kind of check.
| if any( | |
| s in str(getattr(tokenizer, "name_or_path", "")).lower() | |
| for s in ["mistral", "qwen3guard"] | |
| for s in ["mistral", "qwen3guard", "hermes"] | |
| ): | |
| MODELS_BYPASSING_CHAT_TEMPLATE_FIX = ("mistral", "qwen3guard", "hermes") | |
| if any( | |
| s in str(getattr(tokenizer, "name_or_path", "")).lower() | |
| for s in MODELS_BYPASSING_CHAT_TEMPLATE_FIX | |
| ): |
Replacement for #4183 due to Studio rebasing
Fixes #4150
Summary
Hermes models use ChatML-style templates that don't require the
{% if add_generation_prompt %}validation check. This PR addshermesto the list of models that bypass this check, similar to howmistralandqwen3guardare already handled.Changes
hermesto the model bypass list inload_correct_tokenizerfunction inunsloth/tokenizer_utils.pyRoot Cause
When loading a Hermes model (or a LoRA adapter trained with Hermes/ChatML template), the
fix_chat_templatefunction was raising aRuntimeErrorbecause:{% if add_generation_prompt %}in a format the auto-fixer expects_fix_chat_templatecouldn't patch it automaticallyTesting
The fix follows the existing pattern used for mistral and qwen3guard models, which have similar template structures that don't require this validation.
Diff Stats