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

merge_and_unload docs do not clarify behaviour for quantized base models #2105

Open
2 of 4 tasks
RonanKMcGovern opened this issue Sep 26, 2024 · 7 comments
Open
2 of 4 tasks

Comments

@RonanKMcGovern
Copy link

System Info

NA

Who can help?

@BenjaminBossan could you add a note to the docs to explain the default behaviour, and also any work arounds (e.g. loading a base model and dequantizing and loading the adapter and then merging) for best performance? Thanks

https://huggingface.co/docs/peft/main/en/package_reference/lora#peft.LoraModel.merge_and_unload

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

NA

Expected behavior

NA

@BenjaminBossan
Copy link
Member

I agree that the information is a bit sparse. Could you expand on what exactly you would like to see? What is the workaround for that you mentioned, do you mean quantization methods that don't support merging? What type of performance do you have in mind?

@RonanKMcGovern
Copy link
Author

RonanKMcGovern commented Oct 4, 2024 via email

@BenjaminBossan
Copy link
Member

Thanks for the suggestion. To clarify, is this what you're suggesting:

Approach 1 (wrong):

  1. I start with a 16 bit model
  2. I quantize the model (using bnb) to 4 or 8 bit.
  3. I add a LoRA adapter (16 bit)
  4. I train the model with LoRA
  5. I merge the 16 bit LoRA weights into the 4 bit base model weights

Approach 2 (correct):

  1. I start with a 16 bit model
  2. I quantize the model (using bnb) to 4 or 8 bit.
  3. I add a LoRA adapter (16 bit)
  4. I train the model with LoRA
  5. I dequantize the base model to 16 bit
  6. I merge the 16 bit LoRA weights into the 16 bit base model weights
  7. I quantize again to 4/8 bit??

Not sure about step 7, as it would surprise me if approach 2 would actually work better than approach 1 if step 7 is included. If you mean that we omit that step and leave the model in 16 bit, it would be a different story. Of course, this assumes that for inference, we have enough memory to run the model at 16 bit. If we don't, approach 1 still looks reasonable to me.

If you have further resources that show that approach 2 works better, please share them.

Also, from what you wrote, it feels almost more like a feature request to have a method to dequantize + merge, rather than just a docs update, is that right?

@RonanKMcGovern
Copy link
Author

RonanKMcGovern commented Oct 7, 2024 via email

@BenjaminBossan
Copy link
Member

Okay, got it thanks.

although there's already a dequantize method, so I think it could be sufficient to just show the steps using that in the docs

Are you referring to what you mentioned earlier?

The workaround, albeit painful, is to save a lora adapter, load the base model freshly in quantized form, dequantize that base model, load the trained adapter and then merge.

If you already have some code for this, could you share it? Also, if you have any references that this works better than merging into the quantized weights, that would be greatly appreciated. Of course, even if it's just for speed reasons, it would be good to include in the docs.

Copy link

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.

@RonanKMcGovern
Copy link
Author

RonanKMcGovern commented Oct 31, 2024 via email

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