deepspeedai / deepspeedai/DeepSpeed
How can I merge the original model weights with LoRA weights?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 43.1k
- Forks
- 5k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 112
Description
I'm currently fine-tuning Qwen2.5_VL. Specifically, I used PEFT for LoRA fine-tuning on the linear layers of the LLM part. Meanwhile, I performed regular fine-tuning on other components like visual.merger and embed_tokens (with param.requires_grad set to True). After generating the files, as follow:
I exported pytorch_model.bin using zero_to_fp32.py. When I printed the weight keys of the pytorch_model.bin file, I noticed that the original weights and LoRA weights weren't merged. Here's an example:
base_model.model.model.language_model.layers.0.self_attn.q_proj.base_layer.weight: shape=(2048, 2048), dtype=torch.bfloat16
base_model.model.model.language_model.layers.0.self_attn.q_proj.base_layer.bias: shape=(2048,), dtype=torch.bfloat16
base_model.model.model.language_model.layers.0.self_attn.q_proj.lora_A.default.weight: shape=(8, 2048), dtype=torch.bfloat16
base_model.model.model.language_model.layers.0.self_attn.q_proj.lora_B.default.weight: shape=(2048, 8), dtype=torch.bfloat16
Could you tell me how to merge them? If I use
model = model.merge_and_unload()
I need the base_model. However, I no longer have the original base_model, and the original Qwen_2.5_VL model isn't suitable because apart from LoRA fine-tuning the linear layers, I also fine-tuned visual.merger and embed_tokens.
How can I solve this problem? Thank you!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the exported pytorch_model.bin and zero_to_fp32.py, then trace the PEFT merge_and_unload entry point described in the issue. A useful outcome would document a reproducible way to combine the LoRA parameters with the separately fine-tuned visual.merger and embed_tokens weights without relying on the unavailable original base model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- distributed-systems, machine-learning
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100