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

model merge_and_unload do not support layer_replication #1707

Open
4 tasks done
CrazyBoyM opened this issue May 3, 2024 · 6 comments
Open
4 tasks done

model merge_and_unload do not support layer_replication #1707

CrazyBoyM opened this issue May 3, 2024 · 6 comments

Comments

@CrazyBoyM
Copy link

CrazyBoyM commented May 3, 2024

System Info

when you trained a model with layer_replication in LoRAConfig,you will find that can not be merge to the base model in a right way

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder
  • My own task or dataset (give details below)

Reproduction

just set layer_replication in LoraConfig, train a sample lora and merge it to the base model

Expected behavior

generate a modeling_config.py script that can work properly with "layer_replication"

@BenjaminBossan
Copy link
Member

This is not easily possible. The reason is that those replicated layers share the underlying base weights between multiple layers. Therefore, we cannot merge LoRA weights, as different LoRA weights would be merged into the base weights, resulting in incorrect outputs.

@CrazyBoyM
Copy link
Author

CrazyBoyM commented May 6, 2024 via email

@BenjaminBossan
Copy link
Member

What I mean is when I create a lora with layer_replication for expanding blocks from 22 to 32, I merge and save it, but when I load the output model, I find there are only 22 blocks in the final model.

As mentioned, merging with layer replication isn't really possible.

Also, when you load the model, make sure that you first load the base model, then the LoRA adapter using PeftModel.from_pretrained(...). This should restore the replicated layers.

@CrazyBoyM
Copy link
Author

CrazyBoyM commented May 6, 2024 via email

@BenjaminBossan
Copy link
Member

what I mean is that I want to load the base model and the lora model then merge_and_unload,get a new 1.5B model with 32 block,not a original 1B model with 22 block.

This is not really an option right now with PEFT. I guess what you could try is to create clones of the weights that are currently being shared, edit the adapter_config.json to remove the layer_replication entry, then try to load the LoRA adapter and try if merge_and_onload works.

Copy link

github-actions bot commented Jun 3, 2024

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

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