-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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 LLaMATokenizer does not exist or is not currently imported. #22222
Comments
I face the same issue |
Hi @candowu, thanks for raising this issue. This is arising, because the This is likely due to the configuration files being created before the final PR was merged in. |
I cloned the repo and changed the tokenizer in the config file to LlamaTokenizer |
For anybody interested I was able to load an earlier saved model with the same issue using my fork with the capitalization restored. That being said for future it's probably better to try find or save a new model with the new naming. |
@yhifny Are you able to import the tokenizer directly using If not, can you make sure that you are working from the development branch in your environment using: more details here. |
I can import the |
As the error message probably mentions, you need to install sentencepiece: |
Working now. I swear I had sentencepiece, but probably forgot to reset the runtime 🤦 My bad! |
Thanks, man, your link solved all the problem |
Change the LLaMATokenizer in tokenizer_config.json into lowercase LlamaTokenizer and it works like a charm. |
Thank you so much for this! Works! |
I assume this is applied to the llama-7b cloned repo from HuggingFace right? How can I instantiate the model and the tokenizer after doing that please? |
you are a life saver. There docs on the site should be updated for this reference. |
Thank you so much for this! Works! That's amazing! |
You can try this for a ather crazy way to find out what is the right casing for the module: import transformers
from itertools import product
import importlib
def find_variable_case(s, max_tries=1000):
var_permutations = list(map("".join, product(*zip(s.upper(), s.lower()))))
# Intuitively, any camel casing should minimize the no. of upper chars.
# From https://stackoverflow.com/a/58789587/610569
var_permutations.sort(key=lambda ss: (sum(map(str.isupper, ss)), len(ss)))
for i, v in enumerate(var_permutations):
if i > max_tries:
return
try:
dir(transformers).index(v)
return v
except:
continue
v = find_variable_case('LLaMatokenizer')
exec(f"from transformers import {v}")
vars()[v] [out]:
|
I encountered the same issue identified at the thread today 4/2/2023. The post #22222 (comment) fixed the problem for me. Thank you. |
Hi! I am facing the same problem. I try to import LlamaTokenizer, ImportError: cannot import name 'LlamaTokenizer' from 'transformers' (/usr/local/anaconda3/envs/abc/lib/python3.10/site-packages/transformers/init.py) and the version of transformers is "transformers 4.28.0.dev0 pypi_0 pypi" plz tell me how to fix it. |
You need to install the library from source to be able to use the LLaMA model. |
Can you please enlighten me on how this could be achieved please? I'm new to this |
Hi, @nameless0704. First, I would like to thank you for the insightful comment of I could not figure it out and would like to seek your help. Any information is appreciated. Thank you very much in advance! |
I share a experiment, Just replace your llama model to https://huggingface.co/elinas/llama-7b-hf-transformers-4.29 will solve the error like ImportError: cannot import name 'LLaMATokenizer' from 'transformers' |
Example of how to use LLaMA AutoTokenizer
|
the specified error file in the error message. |
Where is the tokenizer_config.json? |
I think this is the location: |
Please. Im facing the same issue. Can anyone help ? I tried all the above methods. |
I had the same issue and it was solved by: |
in my code, transformer==4.30.0 can fix it |
looked at
I had to install |
I had similar issues. root cause was that I was using python3.7 where pip install transformers was older version 4.18. Once I upgraded to python3.9 pip3 install transformers install 4.30.0 Also make sure you have recent cuda drivers, running only on CPU was very slow for me. |
Do we need to load the tokenizer using LlamaTokenizer or can we use it with AutoTokenizer? If the latter is possible, what is the fully qualified tokenizer model on the hub? I get: |
@ndvbd you should be able to use For anyone still getting the same error:
If you have a different issue, make sure to open a new issue and ping me 🤗 |
same error on model codellama/CodeLlama-13b-hf |
No, the json is valid, you are just not working on |
I got the same error. I read that we have to edit 'tokenizer_config.json'. I did that on huggingface by changing the json file available in 'Files and versions' of the 'decapoda-research/llama-7b-hf', but I am not sure how to use the edited changes. This is my code: `import torch print("Import Complete") model = "meta-llama/Llama-2-7b-hf I get the same error- ValueError: Tokenizer class LLaMATokenizer does not exist or is not currently imported. |
You should use |
Any solution to this error ValueError: Tokenizer class LlamaTokenizer does not exist or is not currently imported. ? |
Install this library |
System Info
4.27.1
Who can help?
No response
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
i test llama in colab here is my code and output:
!pip install git+https://github.com/huggingface/transformers
!pip install sentencepiece
import torch
from transformers import pipeline,LlamaTokenizer,LlamaForCausalLM
device = "cuda:0" if torch.cuda.is_available() else "cpu"
print(device)
tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
model = LlamaForCausalLM.from_pretrained("decapoda-research/llama-7b-hf")
generator = pipeline(model="decapoda-research/llama-7b-hf", device=device)
generator("I can't believe you did such a ")
ValueError Traceback (most recent call last)
in
7 # tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
8 # model = LlamaForCausalLM.from_pretrained("decapoda-research/llama-7b-hf")
----> 9 generator = pipeline(model="decapoda-research/llama-7b-hf", device=device)
10 generator("I can't believe you did such a ")
1 frames
/usr/local/lib/python3.9/dist-packages/transformers/models/auto/tokenization_auto.py in from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
675
676 if tokenizer_class is None:
--> 677 raise ValueError(
678 f"Tokenizer class {tokenizer_class_candidate} does not exist or is not currently imported."
679 )
ValueError: Tokenizer class LLaMATokenizer does not exist or is not currently imported.
Expected behavior
expect output generated info
The text was updated successfully, but these errors were encountered: