Skip to content

Allow arbitrary template kwargs in processors#44881

Merged
zucchini-nlp merged 9 commits intohuggingface:mainfrom
zucchini-nlp:chat-template-arbitrarykwargs
Mar 24, 2026
Merged

Allow arbitrary template kwargs in processors#44881
zucchini-nlp merged 9 commits intohuggingface:mainfrom
zucchini-nlp:chat-template-arbitrarykwargs

Conversation

@zucchini-nlp
Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp commented Mar 20, 2026

What does this PR do?

As per title, we don't need a weird way to filter out kwargs anymore because now we don't rely on tokenizer.apply_chat_template. I didn't delete the unused TypedDict yet and will deprecate for at least 3 minor releases, they might be used by some remote code models

Credits to #44817 for jinja2.meta

TODO: make sure other models don't have the patch

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@@ -475,6 +472,7 @@ class CustomProcessorKwargs(ProcessingKwargs, total=False):

class TokenizerChatTemplateKwargs(TypedDict, total=False):
"""
NOTE: `TokenizerChatTemplateKwargs` is deprecated and will be removed in future versions
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can't seem to find a proper way to deprecate a TypedDict when it's used only as typing hint 🥲

Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Looks good with some things that felt a little weird to me - I'm not sure they're bugs, but it might be good to double-check them!

logger.warning(
"Kwargs passed to `processor.__call__` have to be in `processor_kwargs` dict, not in `**kwargs`"
)
processor_kwargs = processor_kwargs_from_kwargs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be a dict merge and not a dict replacement? If processor_kwargs is not empty in this line then it gets clobbered.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ahh right, good catch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

on a second thought, I don't want to allow passing both. For new releases, users need to pass only processor_kwargs, or following deprecated behavior pass simply as arbitrary **kwargs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some values have to be passed twice now, right? Like return_tensors and load_audio_from_video can be passed directly here as well as in processor_kwargs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I followed the tokenizer so we sync in API and split out return_tensors away from processing kwargs. And load_audio_from_video is not used by processor, it's only chat template arg for loading audios

Comment thread src/transformers/models/voxtral/processing_voxtral.py
Comment thread src/transformers/models/voxtral/processing_voxtral.py
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: aria, smolvlm, voxtral

@zucchini-nlp zucchini-nlp added this pull request to the merge queue Mar 24, 2026
Merged via the queue into huggingface:main with commit 9ef15d7 Mar 24, 2026
28 checks passed
@zucchini-nlp zucchini-nlp deleted the chat-template-arbitrarykwargs branch March 24, 2026 11:14
zucchini-nlp added a commit to zucchini-nlp/transformers that referenced this pull request Mar 27, 2026
* .

* warn

* only common tests

* .

* .

* dont import deprecated typed dicts

* print...

* merge dicts if both are passed

* Revert "merge dicts if both are passed"

This reverts commit 2d46cc5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants