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

Encountered an issue while loading the model using transformers #179

Open
Yukang-Lin opened this issue Apr 23, 2024 · 1 comment
Open

Encountered an issue while loading the model using transformers #179

Yukang-Lin opened this issue Apr 23, 2024 · 1 comment

Comments

@Yukang-Lin
Copy link

I try to load the model with transformers,
small_model = AutoModelForCausalLM.from_pretrained(approx_model_name, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True)

but error occurs,
OSError: Unable to load weights from pytorch checkpoint file for '/mnt/data3/lyk/models/tinyllama-1.1b/pytorch_model.bin' at '/mnt/data3/lyk/models/tinyllama-1.1b/pytorch_model.bin'. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

and when I set from_tf=True, another error occurs
AttributeError: module transformers has no attribute TFLlamaForCausalLM

My package is torch2.1.0, transformers 4.39.3

@RmZeta2718
Copy link

I encountered the same issue. It seems to be a bug in scripts/convert_lit_checkpoint.py. The model cannot be loaded due to UnicodeDecodeError (transformers 4.40.1).

Traceback (most recent call last):
  File "/home/user/.conda/envs/py39pt23/lib/python3.9/site-packages/transformers/modeling_utils.py", line 542, in load_state_dict
    if f.read(7) == "version":
  File "/home/user/.conda/envs/py39pt23/lib/python3.9/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 64: invalid start byte

It works in transformers 4.35.0, so I load the model in this version and save it again using standard API, then the model can be loaded from future transformers versions. Note that I have safetensors installed, so the local model is saved as model.safetensors

# transformers 4.35.0
model = AutoModelForCausalLM.from_pretrained(model_path)
model.save_pretrained("local/path")
# transformers 4.40.1
model = AutoModelForCausalLM.from_pretrained("local/path")  # ok
# model = AutoModelForCausalLM.from_pretrained(model_path)  # UnicodeDecodeError, OSError

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

No branches or pull requests

2 participants