Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor default chat template warnings #30551

Merged
merged 4 commits into from
May 1, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/transformers/models/idefics2/processing_idefics2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Processor class for IDEFICS2.
"""

import warnings
from typing import TYPE_CHECKING, Dict, List, Optional, Union

from ...feature_extraction_utils import BatchFeature
Expand Down Expand Up @@ -285,10 +286,14 @@ def apply_chat_template(
chat_template = self.chat_template
else:
chat_template = self.default_chat_template

return self.tokenizer.apply_chat_template(
conversation, chat_template=chat_template, tokenize=tokenize, **kwargs
)
with warnings.catch_warnings():
# TODO Matt: This is a workaround to avoid annoying warnings until we properly remove default
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you open an issue so this work is tracked and we don't forget?

Copy link
Member Author

Choose a reason for hiding this comment

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

The short answer is that because the chat_template arg can also be the name of a template in the template dict, as well as a full template string, we still sniff tokenizer.default_chat_template even if we receive a chat_template arg, to check if the chat template matches one of the dict keys.

This is definitely suboptimal, but I'll open an issue and clean it up once we can get rid of default chat templates, which have been causing other problems too!

Copy link
Collaborator

Choose a reason for hiding this comment

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

eek - that's not good. That also means anyone is going to get this error if they pass in a proper template. This should really be addressed at the moment, rather than waiting two months for the deprecation cycle

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, you're right - I was banking on that being an uncommon path, but I'll try to make a proper fix in this PR!

Copy link
Member Author

Choose a reason for hiding this comment

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

@amyeroberts should be fixed now! I moved the warnings out of the default templates and into the apply_chat_template logic itself, so it should now only fire when appropriate. This means the TODO is no longer necessary either.

# chat templates, which are already deprecated. Once they are removed in v4.43, we can remove
# this and clean up Tokenizer.apply_chat_template as well.
warnings.simplefilter("ignore")
return self.tokenizer.apply_chat_template(
conversation, chat_template=chat_template, tokenize=tokenize, **kwargs
)

@property
def default_chat_template(self):
Expand Down