I am trying to fine-tune llama2 on my M2 macos, when I run this snippet of code
tokenizer = AutoTokenizer.from_pretrained(base_model, use_fast=True)
tokenizer.pad_token = tokenizer.unk_token
tokenizer.padding_side = "right"
I get this error:
Traceback (most recent call last):
File "/Users/salmakhaled/Pobot/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3550, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "/var/folders/67/wk5jj9q91n3g7llmbclsf6wm0000gp/T/ipykernel_24144/1335867970.py", line 2, in <module>
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
File "/Users/salmakhaled/Pobot/venv/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py", line 787, in from_pretrained
File "/Users/salmakhaled/Pobot/venv/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 2028, in from_pretrained
if isinstance(value, dict):
File "/Users/salmakhaled/Pobot/venv/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 2260, in _from_pretrained
save_directory, (filename_prefix + "-" if filename_prefix else "") + ADDED_TOKENS_FILE
File "/Users/salmakhaled/Pobot/venv/lib/python3.9/site-packages/transformers/models/llama/tokenization_llama_fast.py", line 129, in __init__
self.can_save_slow_tokenizer = False if not self.vocab_file else True
AttributeError: can't set attribute
My model name is llama2-7b-chat-hf
Python 3.9.6
transformers 4.36.1
accelerate 0.25.0
torch 2.3.0.dev20240118
I tried to upgrade the libraries versions but I still encounter this error. So I don't know is this issue with a dependencies conflict or another thing.
The error AttributeError: can't set attribute
is raised when you attempt to change a property (see more here)
From the error message this line is the cause of the problem :
self.can_save_slow_tokenizer = False if not self.vocab_file else True
The can_save_slow_tokenizer
is updated to be a property in this commit, The line does not exist in transformers >= 4.33.0
, it was replaced with :
@property
def can_save_slow_tokenizer(self) -> bool:
return os.path.isfile(self.vocab_file) if self.vocab_file else False
as you mentioned you may have dependencies conflict, consider creating a new virtual environment and install transformers
.