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

运行微调后的int4模型失败:KeyError: 'transformer.h.0.attn.c_attn.weight.data' #49

Open
Jingzhenzxz opened this issue Nov 6, 2023 · 0 comments

Comments

@Jingzhenzxz
Copy link

Jingzhenzxz commented Nov 6, 2023

我微调了int4模型,目录为:
image
我执行了下述测试代码(test.py):

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

device = 'cuda' if torch.cuda.is_available() else 'cpu'
tokenizer = AutoTokenizer.from_pretrained("output_models", local_files_only=True)
model = AutoModelForCausalLM.from_pretrained("output_models", trust_remote_code=True, local_files_only=True).to(device)

history = []
query = '你能为我推荐一些书吗?'
response = model.chat(query, history, tokenizer)
print(response)
history.append((query, response))

提示错误:

Traceback (most recent call last):
  File "/opt/ai/WisdomShell/CodeShell-7B-Chat-int4/finetune/test.py", line 8, in <module>
    model = AutoModelForCausalLM.from_pretrained("output_models", trust_remote_code=True, local_files_only=True).to(device)
  File "/root/anaconda3/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 560, in from_pretrained
    return model_class.from_pretrained(
  File "/root/.cache/huggingface/modules/transformers_modules/output_models/modeling_codeshell.py", line 1056, in from_pretrained
    model = load_state_dict_for_qunantied_model(model, state_dict)
  File "/root/.cache/huggingface/modules/transformers_modules/output_models/quantizer.py", line 379, in load_state_dict_for_qunantied_model
    set_value(model, name, state_dict, is_4bit)
  File "/root/.cache/huggingface/modules/transformers_modules/output_models/quantizer.py", line 293, in set_value
    weight_data = state_dict[f'{name}.data']
KeyError: 'transformer.h.0.attn.c_attn.weight.data'

请问这是怎么回事?

@Jingzhenzxz Jingzhenzxz changed the title 请问怎么运行微调后的模型? 运行微调后的int4模型失败:KeyError: 'transformer.h.0.attn.c_attn.weight.data' Nov 6, 2023
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

1 participant