-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
size mismatch for lm_head when fintune QWEN2.5 #36550
Comments
Hi @minmie, it's possible there's a bug here, but can you simplify the reproducer code a little bit? For example, does making a PEFT adapter for a Qwen result in the bug, or do you need |
hi @Rocketknight1 ,thank you for your help. But sorry, I don't known how to simplify the reproducer code, the error is directly cause by load the adapter using AutoPeftModelForCausalLM, if I use the following code to load model, everything work fine. from peft import PeftConfig, PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_model_name ='/home/models/qwen/Qwen2.5-0.5B'
adapter_model_name = "/home/chenjq/pythonWork/nlp/Qwen2.5-0.5B-SFT-Capybara/checkpoint-31"
model = AutoModelForCausalLM.from_pretrained(base_model_name)
model = PeftModel.from_pretrained(model, adapter_model_name)
tokenizer = AutoTokenizer.from_pretrained(base_model_name) you can get the adapter using the training code with a small dataset, and then load the adapter to reproduce this error. |
cc @BenjaminBossan @sayakpaul in that case! |
@minmie I think you could further minimize the training procedure. Does it happen during loading or training? In any case, if you suspect the bug to be stemming from |
It looks like the vocab / embedding size was extended. Not sure if trl may do this under the hood. When loading the model, we thus need to ensure that the vocab size is again extended to the same size it had before. The code would be something like: base_model = AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-0.5B')
base_model.resize_token_embeddings(151936)
model = PeftModel.from_pretrained(base_model, peft_model_id) |
Hi everyone! I did some research and found out that the error occurs because the |
my reproduce on transformers==4.49.0: from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig, AutoConfig
from transformers.models.qwen2.modeling_qwen2 import Qwen2ForCausalLM
import torch
model_dir = "./Qwen2.5-3B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
config = AutoConfig.from_pretrained(model_dir)
model: Qwen2ForCausalLM = AutoModelForCausalLM.from_pretrained(
model_dir,
config=config,
torch_dtype=torch.bfloat16,
device_map="cuda",
trust_remote_code=True
) which prompt: After downgrade to 4.48.0 the warning disappeared. |
hi @sayakpaul, thanks for your help. This error occur during loading. I have open an issue in peft. |
System Info
Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.
transformers
version: 4.49.0Who can help?
@ArthurZucker
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
I finetune qwen2.5 using follow code:
and I use follow code to inference:
an error occur when load model with AutoPeftModelForCausalLM:
Expected behavior
expecte model can predict normally.
The text was updated successfully, but these errors were encountered: