SuperAPI AI 工具集

simpo-training

智能体与模型

查看项目

更新于 10-15 13:03

技能介绍

SimPO(Simple Preference Optimization,简单偏好优化)是一种用于大语言模型对齐的偏好优化方法。根据资料,它是一种无参考模型(reference-free)的方法,不需要参考模型即可运行,并且性能优于 DPO,在 AlpacaEval 2.0 上提升约 6.4 分。

用途 SimPO 用于大语言模型的偏好对齐训练。资料给出的适用场景包括:希望比 DPO 更简单的训练流程(无需参考模型)、拥有偏好数据(chosen/rejected 成对数据)、需要比 DPO 更好的性能、计算资源有限、单节点训练即可满足需求。

主要能力

  • 无参考模型的偏好优化,简化训练流程。
  • 支持从基础模型训练(如 Mistral 7B)。
  • 支持对指令模型进行微调(如 Llama 3 8B Instruct)。
  • 支持推理密集型任务(如数学/代码),可通过调整学习率等超参数适配。
  • 提供 sigmoid 与 hinge 两种损失类型。
  • 支持可选的 SFT 正则化(sft_weight),用于保留模型原有能力。

使用方式 安装步骤(资料提供):

  1. 创建环境:conda create -n simpo python=3.10 && conda activate simpo
  2. 安装 PyTorch 2.2.2(参考 https://pytorch.org/get-started/locally/)
  3. 安装 alignment-handbook:git clone https://github.com/huggingface/alignment-handbook.git,进入目录后执行 python -m pip install .
  4. 安装 Flash Attention 2:python -m pip install flash-attn --no-build-isolation

训练启动命令(Mistral 7B 示例): ACCELERATE_LOG_LEVEL=info accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml scripts/run_simpo.py training_configs/mistral-7b-base-simpo.yaml

资料给出三种常见工作流:

  • 工作流 1:从基础模型训练(Mistral 7B)。配置示例包含 model_name_or_path: mistralai/Mistral-7B-v0.1、torch_dtype: bfloat16、数据集 HuggingFaceH4/ultrafeedback_binarized、beta: 2.0、gamma_beta_ratio: 0.5、loss_type: sigmoid、sft_weight: 0.0、learning_rate: 5e-7、num_train_epochs: 1、per_device_train_batch_size: 1、gradient_accumulation_steps: 8、output_dir: ./outputs/mistral-7b-simpo。
  • 工作流 2:微调指令模型(Llama 3 8B)。配置示例包含 model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct、数据集 argilla/ultrafeedback-binarized-preferences-cleaned、beta: 2.5、gamma_beta_ratio: 0.5、learning_rate: 5e-7、sft_weight: 0.1、num_train_epochs: 1、per_device_train_batch_size: 2、gradient_accumulation_steps: 4、output_dir: ./outputs/llama3-8b-simpo。
  • 工作流 3:推理密集型任务(较低学习率)。配置示例包含 model_name_or_path: deepseek-ai/deepseek-math-7b-base、数据集 argilla/distilabel-math-preference-dpo、beta: 5.0、gamma_beta_ratio: 0.7、learning_rate: 3e-7、sft_weight: 0.0、num_train_epochs: 1、per_device_train_batch_size: 1、gradient_accumulation_steps: 16。

算法选择建议(资料提供):SimPO 最简单、性能最好、无参考模型;DPO 需要参考模型基线、更保守;PPO 控制力最强、需要奖励模型、设置复杂;GRPO 内存高效的 RL、无 critic。若需要多节点分布式训练(PPO/GRPO)可考虑 OpenRLHF;若需要在一个框架中使用多种方法可考虑 TRL;若需要已建立的基线对比可考虑 DPO。

常见问题与处理(资料提供):

  • 损失发散:降低学习率(如从 5e-7 降至 3e-7)或降低 beta(如从 2.0 降至 1.0)。
  • 模型遗忘能力:添加 SFT 正则化(sft_weight: 0.1)。
  • 偏好区分度差:提高 beta 和 margin(如 beta 从 2.0 升至 5.0,gamma_beta_ratio 从 0.5 升至 0.8)。
  • 训练时 OOM:减小 batch size(per_device_train_batch_size: 1,gradient_accumulation_steps: 16 以维持有效 batch),启用 gradient_checkpointing: true。

高级主题(资料提供):损失函数见 references/loss-functions.md(sigmoid 与 hinge 损失、数学公式及使用场景);超参数调优见 references/hyperparameters.md(beta、gamma、学习率选择指南及按模型规模的建议);数据集准备见 references/datasets.md(偏好数据格式、质量过滤、自定义数据集创建)。

硬件需求(资料提供):推荐 GPU 为 NVIDIA A100/H100;显存方面,7B 模型需 1× A100 40GB(DeepSpeed ZeRO-3),8B 模型需 2× A100 40GB,70B 模型需 8× A100 80GB;单节点使用 DeepSpeed ZeRO-3 即可;推荐混合精度 BF16;内存优化手段包括 DeepSpeed ZeRO-3(默认配置)、梯度检查点、Flash Attention 2。

适用场景与限制 适用场景:拥有偏好数据、希望简化训练流程、追求优于 DPO 的性能、计算资源有限、单节点训练。 限制:资料未提供多节点分布式训练支持;若需要 PPO/GRPO 或多方法统一框架,资料建议改用 OpenRLHF 或 TRL。关于收费、价格、平台支持范围等信息,资料暂未提供。

资源 论文:https://arxiv.org/abs/2405.14734(NeurIPS 2024) GitHub:https://github.com/princeton-nlp/SimPO 模型:https://huggingface.co/princeton-nlp Alignment Handbook:https://github.com/huggingface/alignment-handbook