用 LoRA 对 Qwen2.5-VL 模型进行SFT - qwen2_5vl_lora_sft.yaml

用 LoRA 对 Qwen2.5-VL 模型进行SFT - qwen2_5vl_lora_sft.yaml

flyfish

FORCE_TORCHRUN=1 llamafactory-cli train examples/train_lora/qwen2_5vl_lora_sft.yaml
qwen2_5vl_lora_sft.yaml
│    │   │    │    └── SFT: 有监督微调 (Supervised Fine-Tuning)
│    │   │    └── LoRA: 低秩适应 (Low-Rank Adaptation)
│    │   └── VL: 视觉语言 (Vision-Language)
│    └── 2_5: Qwen2.5 模型
└── Qwen: (Qwen) 模型系列

qwen2_5vl_lora_sft.yaml 文件内容

### model
model_name_or_path: Qwen/Qwen2.5-VL-7B-Instruct
image_max_pixels: 262144
video_max_pixels: 16384
trust_remote_code: true

### method
stage: sft
do_train: true
finetuning_type: lora
lora_rank: 8
lora_target: all

### dataset
dataset: mllm_demo,identity,alpaca_en_demo  # video: mllm_video_demo
template: qwen2_vl
cutoff_len: 2048
max_samples: 1000
overwrite_cache: true
preprocessing_num_workers: 16
dataloader_num_workers: 4

### output
output_dir: saves/qwen2_5vl-7b/lora/sft
logging_steps: 10
save_steps: 500
plot_loss: true
overwrite_output_dir: true
save_only_model: false
report_to: none  # choices: [none, wandb, tensorboard, swanlab, mlflow]

### train
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
resume_from_checkpoint: null

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

1. 模型配置(model 部分)

model_name_or_path: Qwen/Qwen2.5-VL-7B-Instruct  # 基础模型路径(Hugging Face 仓库名)
image_max_pixels: 262144  # 输入图像的最大像素数(262144=512×512)
video_max_pixels: 16384   # 输入视频帧的最大像素数
trust_remote_code: true   # 允许加载模型的自定义代码(如特殊分词器)

2. 训练方法配置(method 部分)

stage: sft                 # 训练阶段:有监督微调(Supervised Fine-Tuning)
do_train: true             # 启用训练模式
finetuning_type: lora      # 微调类型:低秩适应(LoRA)
lora_rank: 8               # LoRA 矩阵的秩(秩越小,可训练参数越少)
lora_target: all           # LoRA 要训练的目标参数("all" 表示所有可训练层)
  • LoRA 原理:通过向模型插入低秩矩阵(AB),仅训练这些矩阵而冻结原始参数,大幅减少训练成本。

3. 数据集配置(dataset 部分)

dataset: mllm_demo,identity,alpaca_en_demo  # 训练数据集(多数据集混合)
template: qwen2_vl                          # 数据模板(适配 Qwen2-VL 的格式)
cutoff_len: 2048                            # 输入序列的最大长度(token数)
max_samples: 1000                           # 最大样本数(用于调试,设为-1使用全量数据)
overwrite_cache: true                       # 强制重新处理缓存数据
preprocessing_num_workers: 16               # 数据预处理的并行工作线程数
dataloader_num_workers: 4                   # 数据加载器的并行工作线程数

4. 输出配置(output 部分)

output_dir: saves/qwen2_5vl-7b/lora/sft     # 训练输出目录
logging_steps: 10                           # 每10步记录一次日志
save_steps: 500                             # 每500步保存一次模型
plot_loss: true                             # 绘制训练损失曲线
overwrite_output_dir: true                  # 覆盖输出目录(如果已存在)
save_only_model: false                      # 同时保存优化器状态(设为true仅保存模型权重)
report_to: none                             # 不使用外部日志工具(可选 wandb、tensorboard 等)

5. 训练超参数(train 部分)

per_device_train_batch_size: 1    # 每个设备的训练批次大小
gradient_accumulation_steps: 8    # 梯度累积步数(等效批次大小=1×8=8)
learning_rate: 1.0e-4             # 学习率(LoRA 通常使用较小的学习率)
num_train_epochs: 3.0             # 训练轮数
lr_scheduler_type: cosine         # 学习率调度器:余弦退火
warmup_ratio: 0.1                 # 预热比例(前10%的步数使用线性预热)
bf16: true                        # 使用 BF16 混合精度训练(减少显存占用)
ddp_timeout: 180000000            # 分布式训练超时时间(毫秒)
resume_from_checkpoint: null      # 从检查点恢复训练(设为检查点路径)

你可能感兴趣的:(Qwen,LoRA,Qwen,qwen)