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

ValueError: Tokenizer class T5Tokenizer does not exist or is not currently imported. #9250

Closed
1 task
nsankar opened this issue Dec 22, 2020 · 10 comments
Closed
1 task
Labels

Comments

@nsankar
Copy link

nsankar commented Dec 22, 2020

@mfuntowicz

Environment info

  • transformers version: Latest transformers==4.2.0.dev0
  • Platform: Colab
  • Python version: Python 3.6.9
  • PyTorch version (GPU?): torch==1.7.0+cu101
  • Tensorflow version (GPU?):
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No

Who can help

@mfuntowicz

Information

The following code indicated in the latest HF news letter seems to have isssues when I tried
I get tokenizer error both under Fast and Slow (True/Flase tokenizer parameter) conditions when I had checked

The problem arises when using:

  • the official example scripts: (give details below)
  • [ ]
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM 

tokenizer = AutoTokenizer.from_pretrained("mrm8488/mT5-small-finetuned-tydiqa-for-xqa",use_fast=False )

model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/mT5-small-finetuned-tydiqa-for-xqa")

context = "HuggingFace won the best Demo paper at EMNLP2020."
question = "What won HuggingFace?"
input_text = 'question: %s context: %s' % (question, context)
features = tokenizer([input_text], return_tensors='pt')
output = model.generate(**features)
tokenizer.decode(output[0])

To reproduce

Steps to reproduce the behavior:

  1. Run the above code on Google Colab

ERROR reported

`ValueError Traceback (most recent call last)
in ()
10 from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
11
---> 12 tokenizer = AutoTokenizer.from_pretrained("mrm8488/mT5-small-finetuned-tydiqa-for-xqa",use_fast=False )
13
14 model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/mT5-small-finetuned-tydiqa-for-xqa")

/usr/local/lib/python3.6/dist-packages/transformers/models/auto/tokenization_auto.py in from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
358 if tokenizer_class is None:
359 raise ValueError(
--> 360 "Tokenizer class {} does not exist or is not currently imported.".format(tokenizer_class_candidate)
361 )
362 return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)

ValueError: Tokenizer class T5Tokenizer does not exist or is not currently imported.`

@patrickvonplaten
Copy link
Contributor

Hey @nsankar,

I cannot reproduce the above error concerning the tokenizer. The tokenizer is loaded correctly in my command line.
However it seems like the model weights are not 100% correct.

@mrm8488 when I load the model via:

model = AutoModelForSeq2SeqLM.from_pretrained("mrm8488/mT5-small-finetuned-tydiqa-for-xqa")

I get the following warning:

2020-12-22 11:59:05.111580: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-12-22 11:59:05.111618: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Some weights of the model checkpoint at mrm8488/mT5-small-finetuned-tydiqa-for-xqa were not used when initializing T5ForConditionalGeneration: ['encoder.block.0.layer.1.DenseReluDense.wi.weight', 'encoder.block.1.layer.1.DenseReluDense.wi.weight', 'encoder.block.2.layer.1.DenseReluDense.wi.weight', 'encoder.block.3.layer.1.DenseReluDense.wi.weight', 'encoder.block.4.layer.1.DenseReluDense.wi.weight', 'encoder.block.5.layer.1.DenseReluDense.wi.weight', 'encoder.block.6.layer.1.DenseReluDense.wi.weight', 'encoder.block.7.layer.1.DenseReluDense.wi.weight', 'decoder.block.0.layer.1.EncDecAttention.relative_attention_bias.weight', 'decoder.block.0.layer.2.DenseReluDense.wi.weight', 'decoder.block.1.layer.2.DenseReluDense.wi.weight', 'decoder.block.2.layer.2.DenseReluDense.wi.weight', 'decoder.block.3.layer.2.DenseReluDense.wi.weight', 'decoder.block.4.layer.2.DenseReluDense.wi.weight', 'decoder.block.5.layer.2.DenseReluDense.wi.weight', 'decoder.block.6.layer.2.DenseReluDense.wi.weight', 'decoder.block.7.layer.2.DenseReluDense.wi.weight']
- This IS expected if you are initializing T5ForConditionalGeneration from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing T5ForConditionalGeneration from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of T5ForConditionalGeneration were not initialized from the model checkpoint at mrm8488/mT5-small-finetuned-tydiqa-for-xqa and are newly initialized: ['encoder.block.0.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.0.layer.1.DenseReluDense.wi_1.weight', 'encoder.block.1.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.1.layer.1.DenseReluDense.wi_1.weight', 'encoder.block.2.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.2.layer.1.DenseReluDense.wi_1.weight', 'encoder.block.3.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.3.layer.1.DenseReluDense.wi_1.weight', 'encoder.block.4.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.4.layer.1.DenseReluDense.wi_1.weight', 'encoder.block.5.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.5.layer.1.DenseReluDense.wi_1.weight', 'encoder.block.6.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.6.layer.1.DenseReluDense.wi_1.weight', 'encoder.block.7.layer.1.DenseReluDense.wi_0.weight', 'encoder.block.7.layer.1.DenseReluDense.wi_1.weight', 'decoder.block.0.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.0.layer.2.DenseReluDense.wi_1.weight', 'decoder.block.1.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.1.layer.2.DenseReluDense.wi_1.weight', 'decoder.block.2.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.2.layer.2.DenseReluDense.wi_1.weight', 'decoder.block.3.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.3.layer.2.DenseReluDense.wi_1.weight', 'decoder.block.4.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.4.layer.2.DenseReluDense.wi_1.weight', 'decoder.block.5.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.5.layer.2.DenseReluDense.wi_1.weight', 'decoder.block.6.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.6.layer.2.DenseReluDense.wi_1.weight', 'decoder.block.7.layer.2.DenseReluDense.wi_0.weight', 'decoder.block.7.layer.2.DenseReluDense.wi_1.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

-> I think the weights uploaded here correspond to the "old" T5 version. It would be awesome if you could check the weights :-)
Also in the config: https://huggingface.co/mrm8488/mT5-small-finetuned-tydiqa-for-xqa/blob/main/config.json, the architecture "T5ForConditionalGeneration" is used as well as "t5" for the model type, but it should be "MT5ForConditionalGeneration" and "mt5" I think :-)

@mrm8488
Copy link
Contributor

mrm8488 commented Dec 22, 2020

Thanks @patrickvonplaten. I will check it out, ASAP.

@pommedeterresautee
Copy link
Contributor

pommedeterresautee commented Dec 25, 2020

It seems to happen with other models:

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("moussaKam/mbarthez")

Traceback (most recent call last):
  File "/home/user/.local/share/virtualenvs/project/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-028660e65504>", line 3, in <module>
    tokenizer = AutoTokenizer.from_pretrained("moussaKam/mbarthez")
  File "/home/user/.local/share/virtualenvs/project/lib/python3.8/site-packages/transformers/models/auto/tokenization_auto.py", line 359, in from_pretrained
    raise ValueError(
ValueError: Tokenizer class BarthezTokenizer does not exist or is not currently imported.

And:

(project) user@ubuntu:/mnt/workspace/project$ pip list | grep transformers
transformers             4.1.1

@github-actions
Copy link

github-actions bot commented Mar 6, 2021

This issue has been automatically marked as stale and been closed because it has not had recent activity. Thank you for your contributions.

If you think this still needs to be addressed please comment on this thread.

@simon-ging
Copy link

I had a similar problem ValueError: Tokenizer class M2M100Tokenizer does not exist or is not currently imported. and solved it by running pip install sentencepiece

Seems that when missing the sentencepiece package, AutoTokenizer.from_pretrained will silently not load the tokenizer and then crash later.

@johnpaulbin
Copy link

I had a similar problem ValueError: Tokenizer class M2M100Tokenizer does not exist or is not currently imported. and solved it by running pip install sentencepiece

Seems that when missing the sentencepiece package, AutoTokenizer.from_pretrained will silently not load the tokenizer and then crash later.

This works fabulously with DeBerta models as well, seems that the error isn't very descriptive.

@patrickvonplaten
Copy link
Contributor

I think on current master a better error message is given when from_pretrained(...) is called from a dummy object cc @sgugger :-)

@480284856
Copy link

480284856 commented Aug 19, 2022

I had a similar problem ValueError: Tokenizer class M2M100Tokenizer does not exist or is not currently imported. and solved it by running pip install sentencepiece

Seems that when missing the sentencepiece package, AutoTokenizer.from_pretrained will silently not load the tokenizer and then crash later.

while it doesn't work for me. :-(

`
tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom-560m")

ValueError: Tokenizer class BloomTokenizerFast does not exist or is not currently imported.
`

@480284856
Copy link

I had a similar problem ValueError: Tokenizer class M2M100Tokenizer does not exist or is not currently imported. and solved it by running pip install sentencepiece
Seems that when missing the sentencepiece package, AutoTokenizer.from_pretrained will silently not load the tokenizer and then crash later.

while it doesn't work for me. :-(

` tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom-560m")

ValueError: Tokenizer class BloomTokenizerFast does not exist or is not currently imported. `

well, newest version of transformers works for me.

@MoritzLaurer
Copy link

MoritzLaurer commented Feb 11, 2023

I'm getting the same error with transformers==4.26 when trying to load ernie-m-base with

MODEL_NAME = "PaddlePaddle/ernie-m-base"  
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True, model_max_length=max_length)  # model_max_length=512
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME, label2id=label2id, id2label=id2label).to(device)  
Traceback (most recent call last):
  File "/gpfs/home5/laurerm/nli-scratch/nli_training.py", line 41, in <module>
    tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True, model_max_length=max_length)  # model_max_length=512
  File "/home/laurerm/.local/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py", line 655, in from_pretrained
    raise ValueError(
ValueError: Tokenizer class ErnieMTokenizer does not exist or is not currently imported.

The exact same code worked two days ago with XLM-V. I've made sure that sentencepiece is installed.

Edit: Ah I think the error currently comes up because ernie-m is on the hub, but not yet merged into master for transformers #21349 (?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants