【LLaMa-Factory】监督微调训练方法

命令行

您可以使用以下命令进行微调:

复制代码
llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml

examples/train_lora/llama3_lora_sft.yaml 提供了微调时的配置示例。该配置指定了模型参数、微调方法参数、数据集参数以及评估参数等。您需要根据自身需求自行配置。

复制代码
### examples/train_lora/llama3_lora_sft.yaml
model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct

stage: sft
do_train: true
finetuning_type: lora
lora_target: all

dataset: identity,alpaca_en_demo
template: llama3
cutoff_len: 1024
max_samples: 1000
overwrite_cache: true
preprocessing_num_workers: 16

output_dir: saves/llama3-8b/lora/sft
logging_steps: 10
save_steps: 500
plot_loss: true
overwrite_output_dir: true

per_device_train_batch_size: 1
gradient_accumulation_steps: 8
learning_rate: 1.0e-4
num_train_epochs: 3.0
lr_scheduler_type: cosine
warmup_ratio: 0.1
bf16: true
ddp_timeout: 180000000

val_size: 0.1
per_device_eval_batch_size: 1
eval_strategy: steps
eval_steps: 500

备注

模型 model_name_or_path 、数据集 dateset 需要存在且与 template 相对应。

名称 描述
model_name_or_path 模型名称或路径
stage 训练阶段,可选: rm(reward modeling), pt(pretrain), sft(Supervised Fine-Tuning), PPO, DPO, KTO, ORPO
do_train true用于训练, false用于评估
finetuning_type 微调方式。可选: freeze, lora, full
lora_target 采取LoRA方法的目标模块,默认值为 all
dataset 使用的数据集,使用","分隔多个数据集
template 数据集模板,请保证数据集模板与模型相对应。
output_dir 输出路径
logging_steps 日志输出步数间隔
save_steps 模型断点保存间隔
overwrite_output_dir 是否允许覆盖输出目录
per_device_train_batch_size 每个设备上训练的批次大小
gradient_accumulation_steps 梯度积累步数
max_grad_norm 梯度裁剪阈值
learning_rate 学习率
lr_scheduler_type 学习率曲线,可选 linear, cosine, polynomial, constant 等。
num_train_epochs 训练周期数
bf16 是否使用 bf16 格式
warmup_ratio 学习率预热比例
warmup_steps 学习率预热步数
push_to_hub 是否推送模型到 Huggingface
[重要训练参数]

摘自SFT 训练 - LLaMA Factory 方面后面查找阅读。

相关推荐
roamingcode2 分钟前
我是如何 Vibe Coding,将 AI CLI 工具从 Node.js 迁移到 Rust 并成功发布的
人工智能·rust·node.js·github·claude·github copilot
下午写HelloWorld5 分钟前
生成对抗网络GAN的简要理解
人工智能·神经网络·生成对抗网络
Lethehong9 分钟前
探索高效工作流的秘密:GLM-4.7 与 Dify 平台深度集成实践
大数据·人工智能·算法
Yeats_Liao10 分钟前
微调决策树:何时使用Prompt Engineering,何时选择Fine-tuning?
前端·人工智能·深度学习·算法·决策树·机器学习·prompt
传说故事11 分钟前
【论文自动阅读】GREAT MARCH 100:100项细节导向任务用于评估具身AI agent
人工智能·具身智能
李昊哲小课14 分钟前
基于NLP的检索式聊天机器人
人工智能·自然语言处理·机器人
听麟16 分钟前
HarmonyOS 6.0+ PC端智能监控助手开发实战:摄像头联动与异常行为识别落地
人工智能·深度学习·华为·harmonyos
wasp52020 分钟前
【开源】Banana Slide:一个基于nano banana pro[特殊字符]的原生AI PPT生成应用,迈向真正的"Vibe PPT"
人工智能·开源
说私域21 分钟前
破局互联网产品开发困境:开源AI智能名片链动2+1模式S2B2C商城小程序的实践与启示
人工智能·小程序·开源·私域运营
开源技术1 小时前
深入了解Turso,这个“用Rust重写的SQLite”
人工智能·python