RuntimeError: Error(s) in loading state_dict for Qwen2ForCausalLM:

#42
by XuehangCang - opened

使用 autotrain 微调,但是无法运行

from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
import torch

model_name = "XuehangCang/autotrain-u9u6w-ehmyh"

加载模型和分词器

model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained(model_name)

创建生成pipeline

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)

调用pipeline

messages = [{"role": "user", "content": "Who are you?"}]
result = pipe(messages)
print(result)

RuntimeError: Error(s) in loading state_dict for Qwen2ForCausalLM:
size mismatch for model.embed_tokens.weight: copying a param with shape torch.Size([151669, 5120]) from checkpoint, the shape in current model is torch.Size([152064, 5120]).
size mismatch for lm_head.weight: copying a param with shape torch.Size([151669, 5120]) from checkpoint, the shape in current model is torch.Size([152064, 5120]).

Sign up or log in to comment