Skip to content

[GPT2Tokenizer] Raise ValueError for Fast GPT2Tokenizer with bos token for now - #17498

Merged
patrickvonplaten merged 1 commit into
huggingface:mainfrom
patrickvonplaten:raise_incorrect_gpt2_behavior
May 31, 2022
Merged

patrickvonplaten merged 1 commit into
huggingface:mainfrom
patrickvonplaten:raise_incorrect_gpt2_behavior

Conversation

@patrickvonplaten

@patrickvonplaten patrickvonplaten commented May 31, 2022 •

Copy link
Copy Markdown
Contributor

What does this PR do?

@sgugger - As discussed offline the best fix here will be to make sure GPT2TokenizerFast works correctly which is however dependent on huggingface/tokenizers#1005 and will probs take some time. Think it's important that we raise a ValueError though as otherwise users will run into silently not adding BOS to OPT which I'd like to avoid.

The error message should be clear enough for the user to understand how to change.

@LysandreJik @sgugger also make it's worth doing a patch release here actually (not sure maybe not super important though)

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 requested a review from sgugger May 31, 2022 16:30
**kwargs,
)

if kwargs.pop("add_bos_token", False):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gives:

Traceback (most recent call last):
  File "/home/patrick/hf/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3369, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-8-69932b6461cf>", line 1, in <cell line: 1>
    gpt2 = GPT2TokenizerFast.from_pretrained("facebook/opt-30b")
  File "/home/patrick/python_bin/transformers/tokenization_utils_base.py", line 1783, in from_pretrained
    return cls._from_pretrained(
  File "/home/patrick/python_bin/transformers/tokenization_utils_base.py", line 1928, in _from_pretrained
    tokenizer = cls(*init_inputs, **init_kwargs)
  File "/home/patrick/python_bin/transformers/models/gpt2/tokenization_gpt2_fast.py", line 151, in __init__
    raise ValueError(
ValueError: Currenty GPT2's fast tokenizer does NOT support adding a BOS token.Instead you should use GPT2's slow tokenizer class `GPT2Tokenizer` as follows: 
`GPT2Tokenizer.from_pretrained('facebook/opt-incorrect')`
or
`AutoTokenizer.from_pretrained('facebook/opt-incorrect', use_fast=False)`
This issue will be fixed soon, see: https://github.com/huggingface/tokenizers/pull/1005. so that the fast tokenizer works correctly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting so the error wasn't raised correctly when loading the tokenizer configuration?

@patrickvonplaten

Copy link
Copy Markdown
Contributor Author

@HuggingFaceDocBuilderDev

HuggingFaceDocBuilderDev commented May 31, 2022 •

Copy link
Copy Markdown

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten patrickvonplaten changed the title [GPT2Tokenizer] Fix GPT2 with bos token [GPT2Tokenizer] Raise ValueError for Fast GPT2Tokenizer with bos token for now May 31, 2022

@sgugger sgugger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM as a temp fix, thanks!

@SaulLu

SaulLu commented May 31, 2022

Copy link
Copy Markdown
Contributor

Thanks @patrickvonplaten ! It seems really good to have this error raised while figuring out how to do the processor.

@patrickvonplaten
patrickvonplaten merged commit ba286fe into huggingface:main May 31, 2022
@patrickvonplaten
patrickvonplaten deleted the raise_incorrect_gpt2_behavior branch May 31, 2022 18:06
@LysandreJik

Copy link
Copy Markdown
Member

Also make it's worth doing a patch release here actually (not sure maybe not super important though)

We're likely going to release tomorrow or as soon as BLOOM is merged, so this will be included in it!

Narsil pushed a commit to Narsil/transformers that referenced this pull request Jun 7, 2022
elusenji pushed a commit to elusenji/transformers that referenced this pull request Jun 12, 2022
asartran pushed a commit to asartran/transformers that referenced this pull request Jun 16, 2022
@dhansmair

Copy link
Copy Markdown
Contributor

Hello! when using the GPT2TokenizerFast for the OPT model, I get a warning that the fast version of the tokenizer is working incorrectly. I'm wondering what is the status of this problem, or is it okay to use the fast tokenizer now?

@patrickvonplaten

Copy link
Copy Markdown
Contributor Author

I think the fast OPTTokenizer should work now after it has been merged to tokenizers no? cc @Narsil

@Narsil

Narsil commented Oct 31, 2022

Copy link
Copy Markdown
Contributor

Actually no need for any modifications or tokenizers specific version. Everything should have been fixed within transformers.

But I am not sure about every single OPT model on the hub, I didn't make modifications there (nor am I sure how I should do that).
So if we are using an old incorrect tokenizer, the warning might still be valid.

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.

8 participants