-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/llama factory llama2 pipeline (#89)
* added llama-factory under llm_rl * added sft training bash * added datasets from llama-factory; will delete later * finished llama-2-13b train and inference * fixed minor errors * changed config * added deepspeed config * added more training config to train bash * adding fix for wandb tags and distributed ranks * added fastchat data to replicate training for 2k (cherry picked from commit c769638)
- Loading branch information
1 parent
2cfe135
commit 865873a
Showing
15 changed files
with
202 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
python src/cli_demo.py \ | ||
--model_name_or_path meta-llama/Llama-2-13b-hf \ | ||
--cache_dir ./model_cache \ | ||
--template llama2-sotopia \ | ||
--finetuning_type lora \ | ||
--checkpoint_dir /workspace/sotopia-llm/llm_rl/llama2-13b-sft_cache/checkpoint-35 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"train_batch_size": "auto", | ||
"train_micro_batch_size_per_gpu": "auto", | ||
"gradient_accumulation_steps": "auto", | ||
"gradient_clipping": "auto", | ||
"zero_allow_untested_optimizer": true, | ||
"fp16": { | ||
"enabled": "auto", | ||
"loss_scale": 0, | ||
"initial_scale_power": 16, | ||
"loss_scale_window": 1000, | ||
"hysteresis": 2, | ||
"min_loss_scale": 1 | ||
}, | ||
"zero_optimization": { | ||
"stage": 2, | ||
"allgather_partitions": true, | ||
"allgather_bucket_size": 5e8, | ||
"reduce_scatter": true, | ||
"reduce_bucket_size": 5e8, | ||
"overlap_comm": false, | ||
"contiguous_gradients": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
deepspeed src/train_bash.py \ | ||
--stage sft \ | ||
--model_name_or_path meta-llama/Llama-2-13b-hf \ | ||
--dataset sotopia_easy_sft \ | ||
--dataset_dir ./data/ \ | ||
--val_size 0.1 \ | ||
--cutoff_len 4096 \ | ||
--template llama2-sotopia \ | ||
--wandb_project "llama-factory-sft" \ | ||
--wandb_tags "['llama-2-13b-hf']" \ | ||
--use_fast_tokenizer False \ | ||
--do_train \ | ||
--num_train_epochs 15.0 \ | ||
--per_device_train_batch_size 8 \ | ||
--gradient_accumulation_steps 8 \ | ||
--finetuning_type lora \ | ||
--lora_target q_proj,v_proj \ | ||
--lora_rank 8 \ | ||
--lora_alpha 16 \ | ||
--lora_dropout 0.05 \ | ||
--learning_rate 5e-5 \ | ||
--lr_scheduler_type cosine \ | ||
--weight_decay 0. \ | ||
--warmup_ratio 0.03 \ | ||
--quantization_bit 4 \ | ||
--quantization_type nf4 \ | ||
--double_quantization \ | ||
--flash_attn True \ | ||
--gradient_checkpointing True \ | ||
--bf16 \ | ||
--cache_dir ./model_cache \ | ||
--overwrite_cache \ | ||
--output_dir ./llama2-13b-sft_cache \ | ||
--overwrite_output_dir \ | ||
--logging_steps 1 \ | ||
--evaluation_strategy "steps" \ | ||
--per_device_eval_batch_size 32 \ | ||
--eval_accumulation_steps 32 \ | ||
--save_strategy "epoch" \ | ||
--save_total_limit 5 \ | ||
--use_auth_token True \ | ||
--wandb_token "99caa13ec9552adf0e92e5c30021307ce3cf7fa4" \ | ||
--hf_auth_token "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" \ | ||
--deepspeed ./deepspeed_config_s2.json | ||
|
||
# --dataset alpaca_gpt4_en \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import json | ||
|
||
dummy_qa = { | ||
"instruction": "How old is Haofei? ", | ||
"input": "", | ||
"output": "Haofei is one year old. " | ||
} | ||
|
||
res = [] | ||
for i in range(1000): | ||
new_qa = dict(dummy_qa) | ||
res.append(new_qa) | ||
|
||
with open("../data/dummy_convs.json", "w") as f: | ||
json.dump(res, f, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import json | ||
|
||
def join_json_files(directory_path): | ||
# List to hold all the joined data | ||
joined_data = [] | ||
|
||
# Iterating through each file in the directory | ||
for filename in os.listdir(directory_path): | ||
# Constructing full file path | ||
file_path = os.path.join(directory_path, filename) | ||
|
||
# Ensuring it's a file and has a .json extension | ||
if os.path.isfile(file_path) and file_path.endswith('.json'): | ||
with open(file_path, 'r') as file: | ||
# Load the content of the file | ||
data = json.load(file) | ||
new_data = {"instruction": data["prompt"], | ||
"input": "", | ||
"output": data["result"] | ||
} | ||
joined_data.append(new_data) | ||
return joined_data | ||
|
||
joined_data = join_json_files("./GPT4-4_Redis_Easy_No_Slide/") | ||
with open("../data/GPT4-4_Redis_Easy_No_Slide.json", "w") as f: | ||
json.dump(joined_data, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
|
||
with open("./fastchat-ft-gp4-gpt4-easy-truncated.json", 'r') as f: | ||
data = json.load(f) | ||
|
||
result = [] | ||
for dp in data: | ||
new_dp = {} | ||
convs = dp['conversations'] | ||
new_dp['instruction'] = convs[0]['value'] | ||
new_dp['input'] = "" | ||
new_dp['output'] = convs[1]['value'] | ||
|
||
result.append(new_dp) | ||
|
||
with open("../data/fastchat-ft-gp4-gpt4-easy-truncated.json", 'w') as f: | ||
json.dump(result, f, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
python src/train_bash.py \ | ||
CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \ | ||
--stage rm \ | ||
--model_name_or_path meta-llama/Llama-2-13b \ | ||
--model_name_or_path meta-llama/Llama-2-13b-hf \ | ||
--do_train \ | ||
--dataset comparison_gpt4_en \ | ||
--template default \ | ||
--finetuning_type lora \ | ||
--lora_target q_proj,v_proj \ | ||
--resume_lora_training False \ | ||
--checkpoint_dir ./llama-2-13b-rm \ | ||
--output_dir ./llama-2-13b-rm \ | ||
--per_device_train_batch_size 2 \ | ||
--gradient_accumulation_steps 4 \ | ||
--per_device_train_batch_size 8 \ | ||
--gradient_accumulation_steps 8 \ | ||
--lr_scheduler_type cosine \ | ||
--logging_steps 10 \ | ||
--save_steps 1000 \ | ||
--learning_rate 1e-6 \ | ||
--num_train_epochs 1.0 \ | ||
--plot_loss \ | ||
--fp16 \ | ||
--hf_auth_token "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" | ||
--use_auth_token True \ | ||
--wandb_token "99caa13ec9552adf0e92e5c30021307ce3cf7fa4" \ | ||
--hf_auth_token "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" \ | ||
--deepspeed ./deepspeed_config_s2.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters