微调#
完整参数#
完整训练会更新所有参数以微调语言模型。以下是一个微调GPT-2基础模型的示例。
cd data && ./download.sh alpaca && cd -
./scripts/run_finetune.sh \
--model_name_or_path gpt2 \
--dataset_path data/alpaca/train_conversation \
--output_model_path output_models/finetuned_gpt2
对话模板
对于对话数据集,通过添加--conversation_template参数来指定对话模板以获得更好的性能。
Llama-3-8B conversation dataset example
cd data && ./download.sh alpaca && cd -
./scripts/run_finetune.sh \
--model_name_or_path meta-llama/Meta-Llama-3-8B \
--dataset_path data/alpaca/train_conversation \
--conversation_template llama3 \
--output_model_path output_models/finetuned_llama3_8b
分层重要性采样AdamW优化器(LISA)#
LISA 是一种内存高效的微调算法,可在内存和随机解冻层数之间进行权衡。该脚本目前仅在单GPU环境下测试通过。请持续关注我们的最新动态!
cd data && ./download.sh alpaca && cd -
./scripts/run_finetune_with_lisa.sh \
--model_name_or_path meta-llama/Llama-2-7b-hf \
--dataset_path data/alpaca/train_conversation \
--output_model_path output_models/finetuned_llama2_7b \
--lisa_activated_layers 1 \
--lisa_interval_steps 20
Llama-2-7B conversation dataset example
cd data && ./download.sh alpaca && cd -
./scripts/run_finetune_with_lisa.sh \
--model_name_or_path meta-llama/Llama-2-7b-hf \
--dataset_path data/alpaca/train_conversation \
--conversation_template llama2 \
--output_model_path output_models/finetuned_llama2_7b_lisa \
--lisa_activated_layers 1 \
--lisa_interval_steps 20
低秩适配 (LoRA)#
LoRA是一种参数高效的微调算法,比全参数微调更高效。
cd data && ./download.sh alpaca && cd -
./scripts/run_finetune_with_lora.sh \
--model_name_or_path facebook/galactica-1.3b \
--dataset_path data/alpaca/train_conversation \
--output_lora_path output_models/finetuned_galactica_lora
合并LoRA权重
使用以下方法将LoRA权重与基础模型合并为一个:
./scripts/run_merge_lora.sh \
--model_name_or_path Qwen/Qwen1.5-1.8B \
--lora_model_path output_models/lora \
--output_model_path output_models/lora_merged \
Llama-2-7B conversation dataset example
cd data && ./download.sh alpaca && cd -
./scripts/run_finetune_with_lora.sh \
--model_name_or_path meta-llama/Llama-2-7b-hf \
--dataset_path data/alpaca/train_conversation \
--conversation_template llama2 \
--output_model_path output_models/finetuned_llama2_7b_lora \