Upload 2 files
Browse files- merge.sh +11 -0
- merge_peft_adapters.py +45 -0
merge.sh
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# beam_size=1
|
2 |
+
# output_size=1
|
3 |
+
# input_dir=/data3/HuangKai/Dataset/TRANSFER_dataset/template_sec
|
4 |
+
output_dir=Model/Program_Repair
|
5 |
+
|
6 |
+
# mkdir -p $output_dir
|
7 |
+
|
8 |
+
python merge_peft_adapters.py \
|
9 |
+
--base_model_name_or_path bigcode/starcoderbase \
|
10 |
+
--peft_model_path $output_dir/Epoch_1/ \
|
11 |
+
--push_to_hub \
|
merge_peft_adapters.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
from peft import PeftModel
|
3 |
+
import torch
|
4 |
+
|
5 |
+
import os
|
6 |
+
import argparse
|
7 |
+
|
8 |
+
def get_args():
|
9 |
+
parser = argparse.ArgumentParser()
|
10 |
+
parser.add_argument("--base_model_name_or_path", type=str, default="bigcode/large-model")
|
11 |
+
parser.add_argument("--peft_model_path", type=str, default="/")
|
12 |
+
parser.add_argument("--push_to_hub", action="store_true", default=True)
|
13 |
+
|
14 |
+
return parser.parse_args()
|
15 |
+
|
16 |
+
def main():
|
17 |
+
args = get_args()
|
18 |
+
|
19 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
20 |
+
args.base_model_name_or_path,
|
21 |
+
return_dict=True,
|
22 |
+
torch_dtype=torch.float16
|
23 |
+
)
|
24 |
+
|
25 |
+
model = PeftModel.from_pretrained(base_model, args.peft_model_path)
|
26 |
+
model = model.merge_and_unload()
|
27 |
+
|
28 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained(args.base_model_name_or_path)
|
30 |
+
|
31 |
+
# if args.push_to_hub:
|
32 |
+
# print(f"Saving to hub ...")
|
33 |
+
# model.push_to_hub(f"{args.base_model_name_or_path}-merged", use_temp_dir=False, private=True)
|
34 |
+
# tokenizer.push_to_hub(f"{args.base_model_name_or_path}-merged", use_temp_dir=False, private=True)
|
35 |
+
# else:
|
36 |
+
# model.save_pretrained(f"{args.base_model_name_or_path}-merged")
|
37 |
+
# tokenizer.save_pretrained(f"{args.base_model_name_or_path}-merged")
|
38 |
+
# print(f"Model saved to {args.base_model_name_or_path}-merged")
|
39 |
+
|
40 |
+
model.save_pretrained(f"{args.peft_model_path}-merged")
|
41 |
+
tokenizer.save_pretrained(f"{args.peft_model_path}-merged")
|
42 |
+
print(f"Model saved to {args.peft_model_path}-merged")
|
43 |
+
|
44 |
+
if __name__ == "__main__" :
|
45 |
+
main()
|