Simpo
目次
参照モデルなしで好みに合わせる、DPO より手軽な手法です。
skill の情報
| 提供元 | 追加インストール — hermes skills install official/mlops/simpo で導入します |
| パス | optional-skills/mlops/simpo |
| バージョン | 1.0.0 |
| 作者 | Orchestra Research |
| ライセンス | MIT |
| 依存関係 | torch, transformers, datasets, trl, accelerate |
| 対応プラットフォーム | linux, macos, windows |
| タグ | Post-Training, SimPO, Preference Optimization, Alignment, DPO Alternative, Reference-Free, LLM Alignment, Efficient Training |
参考: SKILL.md 全文
SimPO - Simple Preference Optimization
すぐ試す
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 より良い成績がほしい
- 使える計算資源が限られている
- 1 台のマシンでの学習で足りる
手法の選び方:
- SimPO: いちばん手軽で成績も良く、参照モデルが要りません
- DPO: 参照モデルを基準にしたいとき。より控えめな挙動になります
- PPO: いちばん細かく制御できます。報酬モデルが必要で、準備も大がかりです
- GRPO: メモリに優しい強化学習で、critic が要りません
別のものを使ったほうがよいとき:
- OpenRLHF: 複数の端末に分散した学習、PPO や GRPO を使いたいとき
- TRL: 複数の手法を一つの枠組みで扱いたいとき
- DPO: 定番の基準として比べたいとき
よくある問題
問題: 損失が発散する
学習率を下げます。
learning_rate: 3e-7 # Reduce from 5e-7beta を下げます。
beta: 1.0 # Reduce from 2.0問題: もともとできていたことを忘れてしまう
SFT の正則化を加えます。
sft_weight: 0.1 # Add SFT loss component問題: 好みの差がうまくつかない
beta とマージンを上げます。
beta: 5.0 # Increase from 2.0
gamma_beta_ratio: 0.8 # Increase from 0.5問題: 学習中にメモリが足りない
バッチサイズを下げます。
per_device_train_batch_size: 1
gradient_accumulation_steps: 16 # Maintain effective batch勾配チェックポイントを有効にします。
gradient_checkpointing: true進んだ話題
損失関数: sigmoid と hinge の違い、数式、どちらをいつ使うかは references/loss-functions.md を参照してください。
ハイパーパラメータの調整: beta、gamma、学習率の選び方と、モデルの大きさごとのおすすめは references/hyperparameters.md を参照してください。
データの準備: 好みデータの形式、質でのふるい分け、自前のデータセットの作り方は references/datasets.md を参照してください。
必要なハードウェア
- GPU: NVIDIA A100 か H100 をおすすめします
- VRAM:
- 7B モデル: A100 40GB × 1(DeepSpeed ZeRO-3)
- 8B モデル: A100 40GB × 2
- 70B モデル: A100 80GB × 8
- 1 台構成: DeepSpeed ZeRO-3 で足ります
- 混合精度: BF16 をおすすめします
メモリの節約:
- DeepSpeed ZeRO-3(既定の設定)
- 勾配チェックポイント
- Flash Attention 2
参考情報
- 論文: 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