-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Guidance Needed on Two-Stage Fine-Tuning with LoRA(SFT and DPO) for Model Adaptation #2264
Comments
https://github.com/kohya-ss/sd-scripts/blob/main/networks/merge_lora.py |
The answer to your question depends a little bit on what you want to do afterwards. Let me sketch a response. Let's call the base model M, the first LoRA adapter L1 and the second LoRA adapter L2. After you've trained L1 and save it, you have the 1 Continue training on the same adapterfrom peft import PeftModel
base_model = ... # load the base model M as normal
model = PeftModel.from_pretrained(base_model, <path-to-L1>, is_trainable=True) # <= important
... # continue finetuning
model.save_pretrained(<path-to-L2>) After doing this, you have a second LoRA adapter, L2, which is based on the finetuning knowledge from L1 and additionally has been trained for DPO. For inference, you can load the 2nd adapter the same way as the 1st one shown above, but you don't need to set You can also load both adapters at the same time by loading the 2nd adapter with 2 Merging the first adapter into the base modelThe second approach would work like this: from peft import PeftModel
# first merge L1 into M
base_model = ... # load the base model M as normal
model = PeftModel.from_pretrained(base_model, <path-to-L1>)
merged = model.merge_and_unload()
merged.save_pretrained(<path-to-merged>) The merged model combines the weights of M and L1. The checkpoint of merged = ... # load the merged model from <path-to-merged>
lora_config2 = LoraConfig(...) # config for L2
model = get_peft_model(merged, lora_config2)
... # continue finetuning
model.save_pretrained(<path-to-L2>) Here the big difference to the 1st approach is that instead of using the 1st LoRA adapter for further finetuning, we merge it into the base model and create a 2nd LoRA adapter. This 2nd LoRA adapter requires you to load the merged model as the base model instead of loading the original base model as in the 1st approach. One advantage of the 2nd approach is that you can define a completely new Overall, what approach works better for you depends on your use case, hopefully this explanation makes the decision easier for you. |
Thank you very much for your reply; this part is exactly what I needed. Thanks. |
I am planning to perform a two-stage fine-tuning process and need some guidance on how to proceed.
First Stage
Second Stage
My questions are:
What I had now
What I Need
This is
train a base_model to get LoRA_weights_1
base_model_1 = merge(base_model and LoRA_weights_1)
train base_model_1 to get LoRA_weights_2
base_model_2 = merge(base_model_1 and LoRA_weights_2)
how to split the base_model_2 into base_model and LoRA_weights_1_2
Thinks!
The text was updated successfully, but these errors were encountered: