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

[Tests] Speed up tokenizer tests #14964

Merged

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Dec 28, 2021

What does this PR do?

This PR speeds up the 7 slowest tokenizer tests significantly which should lead to a speed-up of ca. 3 minutes for every test that runs all tokenizer tests

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.

@patrickvonplaten patrickvonplaten changed the title [Tests] Speed up canine and mluke tokenizer [Tests] Speed up tokenizers Dec 28, 2021

def get_tokenizer(self, **kwargs) -> CanineTokenizer:
return self.tokenizer_class.from_pretrained(self.tmpdirname, **kwargs)
tokenizer = self.tokenizer_class.from_pretrained(self.tmpdirname, **kwargs)
tokenizer._unicode_vocab_size = 1024
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change alone gives a speed up of 2.5 minutes. The reason is that len(tokenizer) is by default > 1,000,000 for every Canine tokenizer and the 4 slowest tests encode every single character in the vocabulary in a for loop.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch!

@patrickvonplaten patrickvonplaten changed the title [Tests] Speed up tokenizers [Tests] Speed up tokenizer tests Dec 28, 2021
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Fantastic! Looking forward to the test speed up!


def get_tokenizer(self, **kwargs) -> CanineTokenizer:
return self.tokenizer_class.from_pretrained(self.tmpdirname, **kwargs)
tokenizer = self.tokenizer_class.from_pretrained(self.tmpdirname, **kwargs)
tokenizer._unicode_vocab_size = 1024
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch!

@patrickvonplaten patrickvonplaten merged commit 1bfa347 into huggingface:master Dec 28, 2021
@patrickvonplaten patrickvonplaten deleted the speed_up_tokenizer_tests branch December 28, 2021 16:02
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jan 6, 2022
* speed up canine and mluke

* speed up mbart and mbart50 toks

* upload files
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.

2 participants