From 6585acf27e19983758e9806e56f1d2e0de321e15 Mon Sep 17 00:00:00 2001 From: madroid Date: Sat, 10 Jun 2023 14:11:27 +0800 Subject: [PATCH 1/2] add script: merge the lora weights to the base model --- .../example/redpajama-incite-chat-3b_merge.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 training/lora/example/redpajama-incite-chat-3b_merge.py diff --git a/training/lora/example/redpajama-incite-chat-3b_merge.py b/training/lora/example/redpajama-incite-chat-3b_merge.py new file mode 100755 index 0000000..6c37ddf --- /dev/null +++ b/training/lora/example/redpajama-incite-chat-3b_merge.py @@ -0,0 +1,18 @@ +import torch +from peft import PeftModel, PeftConfig +from transformers import AutoModelForCausalLM + +peft_model_path = 'outputs/redpajama-incite-chat-3b-sample-lowrank' + +config = PeftConfig.from_pretrained(peft_model_path) +model = AutoModelForCausalLM.from_pretrained( + config.base_model_name_or_path, + return_dict=True, + device_map='auto') + +# Load the Lora model +model = PeftModel.from_pretrained(model, peft_model_path) + +model = model.merge_and_unload() + +model.save_pretrained('outputs/redpajama-incite-chat-3b-sample-lowrank/merge') From 1d08b77e994baa328c2083c65806b7d5af2eee8c Mon Sep 17 00:00:00 2001 From: Madroid Ma Date: Sat, 10 Jun 2023 17:02:53 +0800 Subject: [PATCH 2/2] Update training/lora/example/redpajama-incite-chat-3b_merge.py Co-authored-by: orangetin <126978607+orangetin@users.noreply.github.com> --- training/lora/example/redpajama-incite-chat-3b_merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/training/lora/example/redpajama-incite-chat-3b_merge.py b/training/lora/example/redpajama-incite-chat-3b_merge.py index 6c37ddf..e6b290b 100755 --- a/training/lora/example/redpajama-incite-chat-3b_merge.py +++ b/training/lora/example/redpajama-incite-chat-3b_merge.py @@ -15,4 +15,4 @@ model = model.merge_and_unload() -model.save_pretrained('outputs/redpajama-incite-chat-3b-sample-lowrank/merge') +model.save_pretrained('outputs/redpajama-incite-chat-3b-sample-lowrank-merged')