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

Exporting LoRA to HF format without merging #1878

Open
M1TR opened this issue Dec 20, 2024 · 2 comments
Open

Exporting LoRA to HF format without merging #1878

M1TR opened this issue Dec 20, 2024 · 2 comments
Labels
question Further information is requested

Comments

@M1TR
Copy link

M1TR commented Dec 20, 2024

I am using litgpt to finetune LLMs and the results are better than finetuning with HF TRL (which has far more levers to tweak I guess). I understand that litgpt forces you to merge the LoRA with the base model before exporting to HF format. Can someone guide me on how to export only the LoRA to HF format as I would like to experiment with multi-LoRA in vLLM?

@M1TR M1TR added the question Further information is requested label Dec 20, 2024
@Andrei-Aksionov
Copy link
Collaborator

Hello @M1TR

Yes, the current code requires to merge first.
If you want to convert only LoRA weights to HF format, then you need to do it manually.
Depending on the type of the model it might be either not hard, or quite tricky 🙂: perhaps splitting the combined QKV matrix in a correct way, in some cases splitting a layer in MLP block, and of course layer names renaming.

I would recommend to start with the Lit -> HF conversion script for the type of the target model and to manipulate the weight map.

Another way to do this is to convert the merged model and then subtract from the model that you trained weights of the base model.
Because for LoRA the final merged weights are original weights + LoRA weight updates.

Of course these manipulations need to be done only on layers where LoRA was applied.


Perhaps it's something that could be added on LitGPT side.
cc @rasbt

@M1TR
Copy link
Author

M1TR commented Dec 20, 2024

Hi @Andrei-Aksionov

I did spend some time trying to manually convert the LoRA file. I am working with Phi-3 so QKV needed to be recombined along with the layer renaming from the conversion script. I am still starting out with this so I am not yet super confident in messing around with direct row-level manipulation of the weight tensors. I am happy to spend some time on if you can point me in the direction of some reading materials on the model architecture and terminology.

Also, just from a curiosity standpoint, what might be the reasons why the litgpt finetune performs better than the HF TRL finetune even when using the same configuration from the YAML file in the config_hub directory? I also noticed that the LoRA LTH file is much smaller (~20MB) than the equivalent TRL safetensors file (~200MB).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants