stanford_alpaca icon indicating copy to clipboard operation
stanford_alpaca copied to clipboard

Solve BUG:AttributeError: module transformers has no attribute LLaMATokenizer

Open XuyaoWang opened this issue 2 years ago • 12 comments
trafficstars

I wang to follow the guide below.

Given Hugging Face hasn't officially supported the LLaMA models, we fine-tuned LLaMA with Hugging Face's transformers library by installing it from a particular fork (i.e. this PR to be merged). The hash of the specific commit we installed was 68d640f7c368bcaaaecfc678f11908ebbd3d6176. but while click PR and try to run the example: tokenizer = transformers.LLaMATokenizer.from_pretrained("/output/path/tokenizer/") model = transformers.LLaMAForCausalLM.from_pretrained("/output/path/llama-7b/") batch = tokenizer( "The primary use of LLaMA is research on large language models, including", return_tensors="pt", add_special_tokens=False ) batch = {k: v.cuda() for k, v in batch.items()} generated = model.generate(batch["input_ids"], max_length=100) print(tokenizer.decode(generated[0])) I got an error: AttributeError: module transformers has no attribute LLaMATokenizer if you meet same bug, you just change your code to: tokenizer = transformers.LlamaTokenizer.from_pretrained("/output/path/tokenizer/") model = transformers.LlamaForCausalLM.from_pretrained("/output/path/llama-7b/") batch = tokenizer( "The primary use of LLaMA is research on large language models, including", return_tensors="pt", add_special_tokens=False ) batch = {k: v.cuda() for k, v in batch.items()} generated = model.generate(batch["input_ids"], max_length=100) print(tokenizer.decode(generated[0])) This bug is caused by incorrect letter capitalization

XuyaoWang avatar Mar 16 '23 18:03 XuyaoWang

I see the same but fixing the capitalization didnt fix for me image

teknium1 avatar Mar 17 '23 05:03 teknium1

Am using transformers 4.27.1, is it a different version?

teknium1 avatar Mar 17 '23 05:03 teknium1

even i got the same error , please suggest how to fix this

kiran1501 avatar Mar 17 '23 06:03 kiran1501

68d640f7c368bcaaaecfc678f11908ebbd3d6176

garcesmarc avatar Mar 17 '23 06:03 garcesmarc

we are getting this error, and would appreciate your help

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

bkvijay avatar Mar 17 '23 06:03 bkvijay

Am using transformers 4.27.1, is it a different version?

I didn't install transformers in pip, I download transformers in github in branch "llama_push" an move the downloaded file into conda

XuyaoWang avatar Mar 17 '23 06:03 XuyaoWang

Similar to the previous answers, the following steps works for me:

  1. Git clone from branch llama_push.
  2. cd into this repo, git checkout 68d640f7c368bcaaaecfc678f11908ebbd3d6176
  3. Install the "transformers" package by running the command "python setup.py install".
  4. Consolidate all output files from the two subfolders in the PR (https://github.com/huggingface/transformers/pull/21955) into a single folder.

zywang0108 avatar Mar 17 '23 17:03 zywang0108

Yeah you have to install from Transformers github. I had thought since it was merged it was in an updated pip package but its not yet. pip install git+https://github.com/huggingface/transformers.git works for me

teknium1 avatar Mar 17 '23 21:03 teknium1

LlamaTokenizer instead of LLaMATokenizer

ruian0 avatar Mar 21 '23 04:03 ruian0

@ruian0 Thanks for your idea, I fixed this bug, but I faced an another bug: Exception: Could not find the transformer layer class to wrap in the model. Do you know how to correct this problem?

xiaoweiweixiao avatar Mar 23 '23 12:03 xiaoweiweixiao

Another nice solution: Install transformer lib by running this command: pip install -q git+https://github.com/zphang/transformers@c3dc391 that worked well here

Alro10 avatar Mar 30 '23 23:03 Alro10

transformers.LLaMATokenizer is change to transformers.LlamaTokenizer

sunyoubo avatar Apr 25 '23 03:04 sunyoubo