-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,494 additions
and
469 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
Binary file not shown.
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,39 @@ | ||
# Supervised Fine-Tuning (SFT) | ||
|
||
## Data Preparation | ||
|
||
Download [Deita 6K](https://huggingface.co/datasets/hkust-nlp/deita-6k-v0) to `data/deita/deita_6k.jsonl`. | ||
|
||
## Training | ||
|
||
Start training in Slurm clusters: `sbatch scripts/sft/2_8.sh`. | ||
|
||
## Inference | ||
|
||
```python | ||
from transformers import AutoModelForCausalLM | ||
from transformers import AutoTokenizer | ||
|
||
from src.utils.conversation import Conversation | ||
|
||
conv = Conversation() | ||
conv.append_message("human", "Give me a three-day plan in Suzhou.") | ||
conv.append_message("gpt", None) | ||
prompt = conv.get_prompt() | ||
print(prompt) | ||
print(prompt[-1] == " ") | ||
|
||
model_dir = "llama-moe/LLaMA-MoE-v1-3_5B-2_8-sft" | ||
|
||
tok = AutoTokenizer.from_pretrained(model_dir) | ||
m = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True) | ||
m.eval() | ||
m.cuda() | ||
|
||
inputs = tok(prompt, return_tensors="pt") | ||
input_ids = inputs["input_ids"].cuda() | ||
|
||
output = m.generate(input_ids, max_length=100, temperature=1.0, do_sample=True, use_cache=True) | ||
response = tok.decode(output[0], skip_special_tokens=True) | ||
print(response) | ||
``` |
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,80 @@ | ||
#!/usr/bin/bash | ||
|
||
#SBATCH --job-name=llama_moe_2_16_deita | ||
#SBATCH --output=logs/%x-%j.log | ||
#SBATCH --error=logs/%x-%j.log | ||
|
||
#SBATCH --partition=MoE | ||
#SBATCH --ntasks-per-node=1 | ||
#SBATCH --cpus-per-task=16 | ||
#SBATCH --mem=64G | ||
|
||
#SBATCH --nodes=1 | ||
#SBATCH --gres=gpu:4 | ||
#SBATCH --quotatype=auto | ||
|
||
export WANDB_PROJECT="llama_moe_sft" | ||
num_gpus=4 | ||
|
||
{ | ||
task_name="llama_moe_2_16_deita" | ||
model_type="auto" | ||
model_name_or_path="/mnt/petrelfs/zhutong/llama-moe-models/LLaMA-MoE-v1-3_0B-2_16" | ||
dataset_dir_or_path="data/deita/deita_6k.jsonl" | ||
|
||
comment="llama-moe 2/16, deita, w/ balance loss, w/ freeze gate, w/ gate noise" | ||
base_dir="outputs/llama_moe_sft" | ||
output_dir="${base_dir}/${task_name}/$SLURM_JOB_NAME-$SLURM_JOB_ID" | ||
mkdir -p $output_dir | ||
scontrol write batch_script $SLURM_JOBID $output_dir/sbatch.sh | ||
git diff > $output_dir/diff.patch | ||
env > $output_dir/env | ||
echo -e "Job ID: ${SLURM_JOB_ID}\n\nLog: logs/llama_moe_2_16_deita-$SLURM_JOB_ID.log\n\nGit commit: $(git log -1 --oneline)\n\nGit branch: $(git branch | grep "*")\n\nComment: ${comment}" > $output_dir/comment.txt | ||
ln -snf $(scontrol show job $SLURM_JOB_ID | grep "StdOut=" | cut -d '=' -f 2) $output_dir/log.log | ||
echo "$SLURM_JOB_ID" > $base_dir/latest.jobid | ||
ln -snf $output_dir $base_dir/latest.dir | ||
ln -snf $(scontrol show job $SLURM_JOB_ID | grep "StdOut=" | cut -d '=' -f 2) $base_dir/latest.log | ||
|
||
nodes=($(scontrol show hostnames $SLURM_JOB_NODELIS)) | ||
nodes_array=($nodes) | ||
head_node=${nodes_array[0]} | ||
echo "Node: $head_node" | ||
|
||
torchrun \ | ||
--nnodes 1 \ | ||
--nproc_per_node $num_gpus \ | ||
--node_rank $SLURM_NODEID \ | ||
--rdzv_id $RANDOM \ | ||
--rdzv_backend c10d \ | ||
--rdzv_endpoint $head_node:29522 \ | ||
-m smoe.entrypoint.sft.train_sft \ | ||
--do_train \ | ||
--freeze_gate True \ | ||
--evaluation_strategy no \ | ||
--run_name $task_name \ | ||
--model_type $model_type \ | ||
--model_name_or_path $model_name_or_path \ | ||
--dataset_dir_or_path $dataset_dir_or_path \ | ||
--output_dir $output_dir \ | ||
--deepspeed conf/ds_bf16_zero1.json \ | ||
--seed 12306 \ | ||
--bf16 True \ | ||
--tf32 True \ | ||
--torch_dtype bfloat16 \ | ||
--per_device_train_batch_size 4 \ | ||
--per_device_eval_batch_size 4 \ | ||
--gradient_accumulation_steps 8 \ | ||
--num_train_epochs 2 \ | ||
--save_strategy steps \ | ||
--save_steps 9999999999999 \ | ||
--save_total_limit 1 \ | ||
--learning_rate 2e-5 \ | ||
--weight_decay 0. \ | ||
--warmup_ratio 0.03 \ | ||
--lr_scheduler_type cosine \ | ||
--logging_steps 1 \ | ||
--model_max_length 2048 \ | ||
--gradient_checkpointing True \ | ||
--report_to wandb | ||
|
||
} |
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,80 @@ | ||
#!/usr/bin/bash | ||
|
||
#SBATCH --job-name=llama_moe_2_8_deita | ||
#SBATCH --output=logs/%x-%j.log | ||
#SBATCH --error=logs/%x-%j.log | ||
|
||
#SBATCH --partition=MoE | ||
#SBATCH --ntasks-per-node=1 | ||
#SBATCH --cpus-per-task=16 | ||
#SBATCH --mem=64G | ||
|
||
#SBATCH --nodes=1 | ||
#SBATCH --gres=gpu:4 | ||
#SBATCH --quotatype=auto | ||
|
||
export WANDB_PROJECT="llama_moe_sft" | ||
num_gpus=4 | ||
|
||
{ | ||
task_name="llama_moe_2_8_deita" | ||
model_type="auto" | ||
model_name_or_path="/mnt/petrelfs/zhutong/llama-moe-models/LLaMA-MoE-v1-3_5B-2_8-new" | ||
dataset_dir_or_path="data/deita/deita_6k.jsonl" | ||
|
||
comment="llama-moe 2/8, deita, w/ balance loss, w/ freeze gate, w/ gate noise" | ||
base_dir="outputs/llama_moe_sft" | ||
output_dir="${base_dir}/${task_name}/$SLURM_JOB_NAME-$SLURM_JOB_ID" | ||
mkdir -p $output_dir | ||
scontrol write batch_script $SLURM_JOBID $output_dir/sbatch.sh | ||
git diff > $output_dir/diff.patch | ||
env > $output_dir/env | ||
echo -e "Job ID: ${SLURM_JOB_ID}\n\nLog: logs/llama_moe_2_8_deita-$SLURM_JOB_ID.log\n\nGit commit: $(git log -1 --oneline)\n\nGit branch: $(git branch | grep "*")\n\nComment: ${comment}" > $output_dir/comment.txt | ||
ln -snf $(scontrol show job $SLURM_JOB_ID | grep "StdOut=" | cut -d '=' -f 2) $output_dir/log.log | ||
echo "$SLURM_JOB_ID" > $base_dir/latest.jobid | ||
ln -snf $output_dir $base_dir/latest.dir | ||
ln -snf $(scontrol show job $SLURM_JOB_ID | grep "StdOut=" | cut -d '=' -f 2) $base_dir/latest.log | ||
|
||
nodes=($(scontrol show hostnames $SLURM_JOB_NODELIS)) | ||
nodes_array=($nodes) | ||
head_node=${nodes_array[0]} | ||
echo "Node: $head_node" | ||
|
||
torchrun \ | ||
--nnodes 1 \ | ||
--nproc_per_node $num_gpus \ | ||
--node_rank $SLURM_NODEID \ | ||
--rdzv_id $RANDOM \ | ||
--rdzv_backend c10d \ | ||
--rdzv_endpoint $head_node:29522 \ | ||
-m smoe.entrypoint.sft.train_sft \ | ||
--do_train \ | ||
--freeze_gate True \ | ||
--evaluation_strategy no \ | ||
--run_name $task_name \ | ||
--model_type $model_type \ | ||
--model_name_or_path $model_name_or_path \ | ||
--dataset_dir_or_path $dataset_dir_or_path \ | ||
--output_dir $output_dir \ | ||
--deepspeed conf/deepspeed/bf16_zero1.json \ | ||
--seed 12306 \ | ||
--bf16 True \ | ||
--tf32 True \ | ||
--torch_dtype bfloat16 \ | ||
--per_device_train_batch_size 4 \ | ||
--per_device_eval_batch_size 4 \ | ||
--gradient_accumulation_steps 8 \ | ||
--num_train_epochs 2 \ | ||
--save_strategy steps \ | ||
--save_steps 9999999999999 \ | ||
--save_total_limit 1 \ | ||
--learning_rate 2e-5 \ | ||
--weight_decay 0. \ | ||
--warmup_ratio 0.03 \ | ||
--lr_scheduler_type cosine \ | ||
--logging_steps 1 \ | ||
--model_max_length 2048 \ | ||
--gradient_checkpointing True \ | ||
--report_to wandb | ||
|
||
} |
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,80 @@ | ||
#!/usr/bin/bash | ||
|
||
#SBATCH --job-name=llama_moe_4_16_deita | ||
#SBATCH --output=logs/%x-%j.log | ||
#SBATCH --error=logs/%x-%j.log | ||
|
||
#SBATCH --partition=MoE | ||
#SBATCH --ntasks-per-node=1 | ||
#SBATCH --cpus-per-task=16 | ||
#SBATCH --mem=64G | ||
|
||
#SBATCH --nodes=1 | ||
#SBATCH --gres=gpu:4 | ||
#SBATCH --quotatype=auto | ||
|
||
export WANDB_PROJECT="llama_moe_sft" | ||
num_gpus=4 | ||
|
||
{ | ||
task_name="llama_moe_4_16_deita" | ||
model_type="auto" | ||
model_name_or_path="/mnt/petrelfs/zhutong/llama-moe-models/LLaMA-MoE-v1-3_5B-4_16-new" | ||
dataset_dir_or_path="data/deita/deita_6k.jsonl" | ||
|
||
comment="llama-moe 4/16, deita, w/ balance loss, w/ freeze gate, w/ gate noise" | ||
base_dir="outputs/llama_moe_sft" | ||
output_dir="${base_dir}/${task_name}/$SLURM_JOB_NAME-$SLURM_JOB_ID" | ||
mkdir -p $output_dir | ||
scontrol write batch_script $SLURM_JOBID $output_dir/sbatch.sh | ||
git diff > $output_dir/diff.patch | ||
env > $output_dir/env | ||
echo -e "Job ID: ${SLURM_JOB_ID}\n\nLog: logs/llama_moe_4_16_deita-$SLURM_JOB_ID.log\n\nGit commit: $(git log -1 --oneline)\n\nGit branch: $(git branch | grep "*")\n\nComment: ${comment}" > $output_dir/comment.txt | ||
ln -snf $(scontrol show job $SLURM_JOB_ID | grep "StdOut=" | cut -d '=' -f 2) $output_dir/log.log | ||
echo "$SLURM_JOB_ID" > $base_dir/latest.jobid | ||
ln -snf $output_dir $base_dir/latest.dir | ||
ln -snf $(scontrol show job $SLURM_JOB_ID | grep "StdOut=" | cut -d '=' -f 2) $base_dir/latest.log | ||
|
||
nodes=($(scontrol show hostnames $SLURM_JOB_NODELIS)) | ||
nodes_array=($nodes) | ||
head_node=${nodes_array[0]} | ||
echo "Node: $head_node" | ||
|
||
torchrun \ | ||
--nnodes 1 \ | ||
--nproc_per_node $num_gpus \ | ||
--node_rank $SLURM_NODEID \ | ||
--rdzv_id $RANDOM \ | ||
--rdzv_backend c10d \ | ||
--rdzv_endpoint $head_node:29522 \ | ||
-m smoe.entrypoint.sft.train_sft \ | ||
--do_train \ | ||
--freeze_gate True \ | ||
--evaluation_strategy no \ | ||
--run_name $task_name \ | ||
--model_type $model_type \ | ||
--model_name_or_path $model_name_or_path \ | ||
--dataset_dir_or_path $dataset_dir_or_path \ | ||
--output_dir $output_dir \ | ||
--deepspeed conf/ds_bf16_zero1.json \ | ||
--seed 12306 \ | ||
--bf16 True \ | ||
--tf32 True \ | ||
--torch_dtype bfloat16 \ | ||
--per_device_train_batch_size 4 \ | ||
--per_device_eval_batch_size 4 \ | ||
--gradient_accumulation_steps 8 \ | ||
--num_train_epochs 2 \ | ||
--save_strategy steps \ | ||
--save_steps 9999999999999 \ | ||
--save_total_limit 1 \ | ||
--learning_rate 2e-5 \ | ||
--weight_decay 0. \ | ||
--warmup_ratio 0.03 \ | ||
--lr_scheduler_type cosine \ | ||
--logging_steps 1 \ | ||
--model_max_length 2048 \ | ||
--gradient_checkpointing True \ | ||
--report_to wandb | ||
|
||
} |
Empty file.
Oops, something went wrong.