跳到主要內容

Simpo Training

用於大語言模型(LLM)對齊的簡單偏好優化(Simple Preference Optimization)。作為 DPO 的無參考替代方案,性能更優(在 AlpacaEval 2.0 上提升 +6.4 分)。無需參考模型,比 DPO 更高效。當需要比 DPO/PPO 更簡單、更快的訓練時,使用此方法進行偏好對齊。

技能元數據

來源可選 — 使用 hermes skills install official/mlops/simpo 安裝
路徑optional-skills/mlops/simpo
版本1.0.0
作者Orchestra Research
許可證MIT
依賴項torch, transformers, datasets, trl, accelerate
標籤Post-Training, SimPO, Preference Optimization, Alignment, DPO Alternative, Reference-Free, LLM Alignment, Efficient Training

參考:完整 SKILL.md

信息

以下是 Hermes 在觸發此技能時加載的完整技能定義。這是技能激活時代理所看到的指令。

SimPO - 簡單偏好優化

快速開始

SimPO 是一種無參考的偏好優化方法,無需參考模型即可超越 DPO 的性能。

安裝

# Create environment
conda create -n simpo python=3.10 && conda activate simpo

# Install PyTorch 2.2.2
# Visit: https://pytorch.org/get-started/locally/

# Install alignment-handbook
git clone https://github.com/huggingface/alignment-handbook.git
cd alignment-handbook
python -m pip install .

# Install 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)

配置mistral-7b-base-simpo.yaml):

# Model
model_name_or_path: mistralai/Mistral-7B-v0.1
torch_dtype: bfloat16

# Dataset
dataset_mixer:
HuggingFaceH4/ultrafeedback_binarized: 1.0
dataset_splits:
- train_prefs
- test_prefs

# SimPO hyperparameters
beta: 2.0 # Reward scaling (2.0-10.0)
gamma_beta_ratio: 0.5 # Target margin (0-1)
loss_type: sigmoid # sigmoid or hinge
sft_weight: 0.0 # Optional SFT regularization

# Training
learning_rate: 5e-7 # Critical: 3e-7 to 1e-6
num_train_epochs: 1
per_device_train_batch_size: 1
gradient_accumulation_steps: 8

# Output
output_dir: ./outputs/mistral-7b-simpo

啟動訓練

accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml \
scripts/run_simpo.py training_configs/mistral-7b-base-simpo.yaml

工作流 2:微調指令模型(Llama 3 8B)

配置llama3-8b-instruct-simpo.yaml):

model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct

dataset_mixer:
argilla/ultrafeedback-binarized-preferences-cleaned: 1.0

beta: 2.5
gamma_beta_ratio: 0.5
learning_rate: 5e-7
sft_weight: 0.1 # Add SFT loss to preserve capabilities

num_train_epochs: 1
per_device_train_batch_size: 2
gradient_accumulation_steps: 4
output_dir: ./outputs/llama3-8b-simpo

啟動

accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml \
scripts/run_simpo.py training_configs/llama3-8b-instruct-simpo.yaml

工作流 3:推理密集型任務(較低學習率)

適用於數學/代碼任務

model_name_or_path: deepseek-ai/deepseek-math-7b-base

dataset_mixer:
argilla/distilabel-math-preference-dpo: 1.0

beta: 5.0 # Higher for stronger signal
gamma_beta_ratio: 0.7 # Larger margin
learning_rate: 3e-7 # Lower LR for reasoning
sft_weight: 0.0

num_train_epochs: 1
per_device_train_batch_size: 1
gradient_accumulation_steps: 16

何時使用及與替代方案對比

使用 SimPO 的情況

  • 希望比 DPO 更簡單的訓練(無需參考模型)
  • 擁有偏好數據(選擇/拒絕對)
  • 需要比 DPO 更好的性能
  • 計算資源有限
  • 單節點訓練已足夠

算法選擇

  • SimPO:最簡單,性能最佳,無需參考模型
  • DPO:需要參考模型基線,更保守
  • PPO:最大控制力,需要獎勵模型,設置複雜
  • GRPO:內存高效的強化學習,無需評論家模型(critic)

改用替代方案的情況

  • OpenRLHF:多節點分佈式訓練,PPO/GRPO
  • TRL:需要在一個框架中使用多種方法
  • DPO:需要既定的基線進行比較

常見問題

問題:損失發散

降低學習率:

learning_rate: 3e-7  # Reduce from 5e-7

降低 beta:

beta: 1.0  # Reduce from 2.0

問題:模型遺忘原有能力

添加 SFT 正則化:

sft_weight: 0.1  # Add SFT loss component

問題:偏好區分度差

增加 beta 和 margin:

beta: 5.0            # Increase from 2.0
gamma_beta_ratio: 0.8 # Increase from 0.5

問題:訓練期間顯存溢出(OOM)

減小批量大小(batch size):

per_device_train_batch_size: 1
gradient_accumulation_steps: 16 # Maintain effective batch

啟用梯度檢查點(gradient checkpointing):

gradient_checkpointing: true

高級主題

損失函數:參見 references/loss-functions.md 瞭解 sigmoid 與 hinge 損失、數學公式以及各自的使用場景。

超參數調優:參見 references/hyperparameters.md 獲取 beta、gamma、學習率選擇指南以及針對特定模型規模的建議。

數據集準備:參見 references/datasets.md 瞭解偏好數據格式、質量過濾以及自定義數據集創建。

硬件要求

  • GPU:推薦 NVIDIA A100/H100
  • 顯存 (VRAM)
    • 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

資源