-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
[AutoTokenizer] Allow creation of tokenizers by tokenizer type #13668
[AutoTokenizer] Allow creation of tokenizers by tokenizer type #13668
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for updating this new API!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the addition @patrickvonplaten 🙌
I just left 2 small questions in comments
# If we have the tokenizer_type we can leverage it | ||
if tokenizer_type is not None: | ||
tokenizer_class = None | ||
tokenizer_class_tuple = TOKENIZER_MAPPING_NAMES.get(tokenizer_type, None) | ||
|
||
if tokenizer_class_tuple is None: | ||
raise ValueError( | ||
f"Passed `tokenizer_type` {tokenizer_type} does not exist. `tokenizer_type` should be one of " | ||
f"{', '.join(c for c in TOKENIZER_MAPPING_NAMES.keys())}." | ||
) | ||
|
||
tokenizer_class_name, tokenizer_fast_class_name = tokenizer_class_tuple | ||
|
||
if use_fast and tokenizer_fast_class_name is not None: | ||
tokenizer_class = tokenizer_class_from_name(tokenizer_fast_class_name) | ||
|
||
if tokenizer_class is None: | ||
tokenizer_class = tokenizer_class_from_name(tokenizer_class_name) | ||
|
||
if tokenizer_class is None: | ||
raise ValueError(f"Tokenizer class {tokenizer_class_name} is not currently imported.") | ||
|
||
return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if all these added lines could not be put before the line 432. It seems to me that tokenizer_config
and config_tokenizer_class
are not used in this if and it would "save" loading the tokenizer_config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree! Changed it
tokenizer_class = tokenizer_class_from_name(tokenizer_class_name) | ||
|
||
if tokenizer_class is None: | ||
raise ValueError(f"Tokenizer class {tokenizer_class_name} is not currently imported.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm not sure I figured out why this error message isn't exactly (about the existence of the tokenizer) like the one on the line 478.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tokenizer_class_name
has to exist as it's mapped from the tokenizer_type so the only reason this could fail is if the class cannot be important due to some missing packages like tokenizers
or sentencepiece
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I agree with Lucile's comments.
What does this PR do?
This PR enables the
Case #4
as discussed here: #13623 (comment)Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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.