Repository navigation
Conversation
A ChatTemplate instance passed as chat_template (as the onnxruntime tutorial and the str | ChatTemplate | None annotations suggest) fell through to the ChatML fallback, replacing the user's template with ChatML despite the warning. Use the instance's class so it is treated like a passed-in class.
This branch has not been deployed
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
load_template_classnow uses the class of aChatTemplateinstance passed aschat_template, instead of discarding it and falling back to ChatML.Why
load_template_class(guidance/chat.py:47) only handled chat template classes (guidance/chat.py:57) and template strings (guidance/chat.py:62). AChatTemplateinstance matched neither branch, so it fell through to the ChatML default (guidance/chat.py:80) with a "was unable to be loaded" warning, replacing the caller's template with ChatML.The public API annotates the parameter as
str | ChatTemplate | None(guidance/models/_engine/_tokenizer.py:36, alsoguidance/models/_transformers.py:61andguidance/models/_llama_cpp.py:62), and the onnxruntime tutorial passes an instance (chat_template=Phi4MiniChatTemplate()innotebooks/tutorials/onnxruntime_models.ipynb). With that documented usage, Phi-4-mini prompts were formatted with ChatML markers (<|im_start|>user) instead of the model's own markers (ammad).Changes
guidance/chat.py: inload_template_class, ifchat_templateis aChatTemplateinstance, use its class so it is handled by the existing class branch; documented the added precedence in the docstring.tests/unit/test_chat.py: new regression tests coveringload_template_classwith an instance (must not warn, must preserve role markers) and aTokenizerconstructed with an instance.Testing
New tests on the unpatched tree (both fail — the instance falls through to the ChatML fallback):
New tests on the patched tree:
Existing unit suite (no regressions):
Format and lint (per
CONTRIBUTING.md):