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

add warning to let the user know that the __call__ method is faster than encode + pad for a fast tokenizer #18693

Merged
merged 5 commits into from
Aug 24, 2022

Conversation

SaulLu
Copy link
Contributor

@SaulLu SaulLu commented Aug 19, 2022

What does this PR do?

In this PR I propose to specify in the docstring of the pad method and to log a warning when the pad method is called with a fast tokenizer. The goal is to encourage the user to use the __call__ method to encode and pad their input at the same time since it will be faster then encoding and then padding it with the method pad (because it is not using the rust backend).

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@SaulLu SaulLu changed the title [WIP] add warning to let the user know that the __call__ method is fast than encode + pad for a fast tokenizer [WIP] add warning to let the user know that the __call__ method is faster than encode + pad for a fast tokenizer Aug 19, 2022
@@ -2869,6 +2872,12 @@ def pad(
verbose (`bool`, *optional*, defaults to `True`):
Whether or not to print more information and warnings.
"""
if self.__class__.__name__.endswith("Fast"):
warnings.warn(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use warnings.warn instead of logger.warning so that the warning can be issued only once.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@SaulLu SaulLu changed the title [WIP] add warning to let the user know that the __call__ method is faster than encode + pad for a fast tokenizer add warning to let the user know that the __call__ method is faster than encode + pad for a fast tokenizer Aug 19, 2022
@SaulLu SaulLu requested review from sgugger and LysandreJik August 19, 2022 13:59
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! I'd rather we use logging.warning instead of warnings.warn as the former can be managed by the centralized logging system.

We have a system in place to only send these once, see how it's implemented in the base tokenization file:

self.deprecation_warnings = (
{}
) # Use to store when we have already noticed a deprecation warning (avoid overlogging).

I would implement something similar here :)

@SaulLu
Copy link
Contributor Author

SaulLu commented Aug 23, 2022

Thanks a lot for the advice @LysandreJik 🤗 ! Indeed, since this attribute deprecation_warnings exists, I have no reason to prefer warnings.warn to logger.warning. I made the change in 775002f.

@SaulLu SaulLu requested a review from LysandreJik August 23, 2022 14:18
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Great! Thanks for your PR, @SaulLu. Merging!

@LysandreJik LysandreJik merged commit 6667b0d into huggingface:main Aug 24, 2022
oneraghavan pushed a commit to oneraghavan/transformers that referenced this pull request Sep 26, 2022
… than `encode` + `pad` for a fast tokenizer (huggingface#18693)

* add warning to let the user know that the  method is slower that  for a fast tokenizer

* user warnings

* fix layoutlmv2

* fix layout*

* change warnings into logger.warning
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.

3 participants