test: add regression test for chat_template kwarg override (issue #40913)#40954
Closed
qizwiz wants to merge 6 commits into
Closed
test: add regression test for chat_template kwarg override (issue #40913)#40954qizwiz wants to merge 6 commits into
qizwiz wants to merge 6 commits into
Conversation
This PR fixes a bug where user-provided chat_template parameters were being overwritten by model defaults when creating a processor. The fix ensures that user-provided values take precedence over model defaults. Fixes huggingface#40913
4 tasks
zucchini-nlp
left a comment
Member
There was a problem hiding this comment.
Can you add a proper test please?
Comment on lines
+1
to
+2
| # Test file for chat template override fix | ||
| print("Test file created successfully!") |
| chat_templates = chat_templates["default"] # Flatten when we just have a single template/file | ||
|
|
||
| if chat_templates: | ||
| if chat_templates and "chat_template" not in kwargs: |
Member
There was a problem hiding this comment.
can do kwargs.set_default("chat_template", chat_templates)
This was referenced Apr 29, 2026
Adds TestChatTemplateKwargOverride with two cases: - user-supplied chat_template wins over model default - model's chat_template.jinja is loaded when no kwarg supplied Addresses reviewer request from zucchini-nlp on PR huggingface#40954.
Author
|
Done — added The test creates a tmpdir with
That second case is the bug this PR fixes. |
9a1f421 to
096db3c
Compare
- Second test now checks processor_dict["chat_template"] (not returned_kwargs), matching the actual contract: the model's on-disk template is loaded into processor_dict, not kwargs. - Remove redundant class docstring and inline comments. - Collapse MODEL_TEMPLATE string to single line (ruff format).
096db3c to
0514a84
Compare
Member
|
I will just fix it with another PR, sorry bot |
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
Adds
tests/utils/test_processing_utils.pyas a regression guard for #40913.The bug:
get_processor_dictwas overwriting a caller-suppliedchat_templatekwarg with the model's on-disk default template (viakwargs["chat_template"] = chat_templatesunconditionally). This meantProcessorMixin.from_pretrained(path, chat_template=user_template)silently ignored the user's template.The fix: Already landed in
mainvia theprocessing_utilsrefactor — the model's template now goes intoprocessor_dict, while caller kwargs are left untouched, andfrom_args_and_dictlets kwargs win viaprocessor_dict.update(kwargs).This PR: Adds two regression tests to prevent the bug from coming back:
test_user_chat_template_preserved_in_returned_kwargs— caller's kwarg survivesget_processor_dictinreturned_kwargstest_model_chat_template_loaded_into_processor_dict— model's on-disk template is loaded intoprocessor_dictwhen no kwarg is suppliedFixes #40913