Home

Awesome

Simple Preference Optimization (SimPO)

This repository contains the code and released models for our paper SimPO: Simple Preference Optimization with a Reference-Free Reward. We propose a simpler and more effective preference optimization algorithm than DPO (Direct Preference Optimization) without using a reference model. SimPO outperforms DPO and its latest variants across AlpacaEval 2, MT-Bench, and Arena-Hard benchmarks under various settings. Please find all the released model checkpoints at this link.

<img src="./SimPO.png" width="1000px"></img>

🆕 Changelog

🔗 Quick Links

Tips for Running SimPO

Given the various inquiries about SimPO, we provide a list of tips to help you reproduce our paper results and achieve better outcomes for running SimPO on your own tasks.

Environment

We provide an environment file including the python package versions we used in our experiments. For optimal reproducibility, we recommend using the same package versions. However, please note that results may still vary due to differences in hardware configurations and CUDA versions, etc.

Hyperparameter tuning

Hyperparameter tuning is crucial for SimPO (and other preference optimization algorithms in general). The three main hyperparameters of SimPO to focus on are learning_rate, beta, and gamma (we recommend keeping the total batch size fixed at 128).

We used the following hyperparameters for training the released models (note that in our latest update, we changed the hyperparameter gamma to gamma_beta_ratio as the latter is normalized and easier to tune under different beta values).

Settingβγ/βLearning rate
Mistral-Base2.00.83e-7
Mistral-Instruct2.50.15e-7
Llama3-Base2.00.56e-7
Llama3-Instruct2.50.551e-6
Llama3-Instruct v0.2100.31e-6
Gemma100.58e-7

For DPO, the best hyperparameters for each setting are as follows.

SettingβLearning Rate
Mistral-Base0.015e-7
Mistral-Instruct0.015e-7
Llama3-Base0.015e-7
Llama3-Instruct0.017e-7
Llama3-Instruct v0.20.013e-7
Gemma0.015e-7

Training and evaluation consistency in BOS

Our released Llama3 models use the initial version of the Llama3 tokenizer (prior to this PR). We have found that the updated Llama3 tokenizer with vLLM occasionally introduces two BOS tokens, which can affect evaluation results. Therefore, please ensure that only one BOS token is included in the prompt after applying the Llama3 chat template during any evaluation.

Notably, if you are training Llama3 and evaluating the trained models on AlpacaEval 2 and Arena-Hard using the templates provided in this repo, please make sure to use the pre-update Llama3 tokenizer (i.e., the one before the PR).

Reproducing AlpacaEval 2 numbers

Please make sure that you use alpaca-eval==0.6.2 and model configurations in our repo for successfully reproducing AlpacaEval 2 results. AlpacaEval has a major revision for vllm decoding since 0.6.3 and causes a discrepancy from our experiments.

Adding an extra SFT loss

The CPO_SIMPO repository did preliminary experiments and observed that in some cases, adding an additional SFT loss can help improve results. In our own experiments, the SFT regularization helps preserve the reasoning ability (e.g., GSM8K) but degrades chat performance. If you'd like to apply SFT regularization, you can set sft_weight to be a positive value (by default it's 0).

Released Models

Gemma

We release the following two models that are built on top of the strong google/gemma-2-9b-it model by training DPO and SimPO on the on-policy dataset princeton-nlp/gemma2-ultrafeedback-armorm. For GSM and MMLU, we use the ZeroEval repository which aims to evaluate instruction-tuned LLMs (i.e., chat models instead of base models) for their zero-shot performance on reasoning and knowledge heavy tasks. More results on WildBench are coming soon.

modelsAE2 LCAE2 WRAE2 LengthAHAH LengthGSMGSM LengthMMLUMMLU Length
google/gemma-2-9b-it51.138.1157140.854587.439572.7515
princeton-nlp/gemma-2-9b-it-DPO67.865.4201658.971788.539272.2624
princeton-nlp/gemma-2-9b-it-SimPO72.465.9183359.169388.034172.2441

v0.2

We found that using a strong reward model for annotating preference optimization datasets is crucial. In this iteration, we have reannotated the dataset princeton-nlp/llama3-ultrafeedback-armorm using a more powerful reward model, RLHFlow/ArmoRM-Llama3-8B-v0.1. As a result, the v0.2 models demonstrate significantly improved performance compared to the v0.1 models.

Caveat: We have observed that the SimPO v0.2 model often struggles with generating outputs that require adherence to specific structures, such as json. This issue arises from a combination of factors: the llama3-instruct model's tendency to forget and the large learning rate (e.g., 1e-6) used during training, which causes deviation from the original model. To address this, we developed SimPO models based on the google/gemma-2-9b-it. We found that changing the initial model significantly mitigates the forgetting issue and reduces the impact of the learning rate.

modelsAE2 LCAE2 WRAH
Llama 3 Instruct 8B RRHF v0.2princeton-nlp/Llama-3-Instruct-8B-RRHF-v2.037.931.628.8
Llama 3 Instruct 8B SLiC-HF v0.2princeton-nlp/Llama-3-Instruct-8B-SLiC-HF-v2.033.932.529.3
Llama 3 Instruct 8B DPO v0.2princeton-nlp/Llama-3-Instruct-8B-DPO-v0.248.247.535.2
Llama 3 Instruct 8B IPO v0.2princeton-nlp/Llama-3-Instruct-8B-IPO-v0.246.842.436.6
Llama 3 Instruct 8B CPO v0.2princeton-nlp/Llama-3-Instruct-8B-CPO-v0.234.136.430.9
Llama 3 Instruct 8B KTO v0.2princeton-nlp/Llama-3-Instruct-8B-KTO-v0.234.132.127.3
Llama 3 Instruct 8B ORPO v0.2princeton-nlp/Llama-3-Instruct-8B-ORPO-v0.238.133.828.2
Llama 3 Instruct 8B R-DPO v0.2princeton-nlp/Llama-3-Instruct-8B-RDPO-v0.248.045.835.1
Llama 3 Instruct 8B SimPO v0.2princeton-nlp/Llama-3-Instruct-8B-SimPO-v0.253.747.536.5

v0.1

Below is the complete list of models evaluated in our preprint. We used the HuggingFaceH4/ultrafeedback_binarized dataset to train the Mistral Base and Llama3 Base models, the princeton-nlp/mistral-instruct-ultrafeedback dataset to train the Mistral Instruct models, and the princeton-nlp/llama3-ultrafeedback dataset to train the Llama3 Instruct models. The latter two datasets are annotated by the llm-blender/PairRM model.

modelsAE2 LCAE2 WRAH
Mistral Base 7B SFTalignment-handbook/zephyr-7b-sft-full8.46.21.3
Mistral Base 7B RRHFprinceton-nlp/Mistral-7B-Base-SFT-RRHF11.610.26.9
Mistral Base 7B SLiC-HFprinceton-nlp/Mistral-7B-Base-SFT-SLiC-HF10.98.97.3
Mistral Base 7B DPO (Zephyr)princeton-nlp/Mistral-7B-Base-SFT-DPO15.112.510.4
Mistral Base 7B IPOprinceton-nlp/Mistral-7B-Base-SFT-IPO11.89.47.5
Mistral Base 7B CPOprinceton-nlp/Mistral-7B-Base-SFT-CPO9.88.96.9
Mistral Base 7B KTOprinceton-nlp/Mistral-7B-Base-SFT-KTO13.19.15.6
Mistral Base 7B ORPOkaist-ai/mistral-orpo-beta14.712.27.0
Mistral Base 7B R-DPOprinceton-nlp/Mistral-7B-Base-SFT-RDPO17.412.89.9
Mistral Base 7B SimPOprinceton-nlp/Mistral-7B-Base-SFT-SimPO21.420.816.6
Mistral Instruct 7B SFTmistralai/Mistral-7B-Instruct-v0.217.114.712.6
Mistral Instruct 7B RRHFprinceton-nlp/Mistral-7B-Instruct-RRHF25.324.818.1
Mistral Instruct 7B SLiC-HFprinceton-nlp/Mistral-7B-Instruct-SLiC-HF24.124.618.9
Mistral Instruct 7B DPOprinceton-nlp/Mistral-7B-Instruct-DPO26.824.916.3
Mistral Instruct 7B IPOprinceton-nlp/Mistral-7B-Instruct-IPO20.320.316.2
Mistral Instruct 7B CPOprinceton-nlp/Mistral-7B-Instruct-CPO23.828.822.6
Mistral Instruct 7B KTOprinceton-nlp/Mistral-7B-Instruct-KTO24.523.617.9
Mistral Instruct 7B ORPOprinceton-nlp/Mistral-7B-Instruct-ORPO24.524.920.8
Mistral Instruct 7B R-DPOprinceton-nlp/Mistral-7B-Instruct-RDPO27.324.516.1
Mistral Instruct 7B SimPOprinceton-nlp/Mistral-7B-Instruct-SimPO32.134.821.0
Llama3 Base 8B SFTprinceton-nlp/Llama-3-Base-8B-SFT6.24.63.3
Llama3 Base 8B RRHFprinceton-nlp/Llama-3-Base-8B-RRHF10.88.16.6
Llama3 Base 8B SLiC-HFprinceton-nlp/Llama-3-Base-8B-SLiC-HF12.110.110.3
Llama3 Base 8B DPOprinceton-nlp/Llama-3-Base-8B-SFT-DPO18.215.515.9
Llama3 Base 8B IPOprinceton-nlp/Llama-3-Base-8B-SFT-IPO14.414.217.8
Llama3 Base 8B CPOprinceton-nlp/Llama-3-Base-8B-SFT-CPO10.88.15.8
Llama3 Base 8B KTOprinceton-nlp/Llama-3-Base-8B-SFT-KTO14.212.412.5
Llama3 Base 8B ORPOprinceton-nlp/Llama-3-Base-8B-SFT-ORPO12.210.610.8
Llama3 Base 8B R-DPOprinceton-nlp/Llama-3-Base-8B-SFT-RDPO17.614.417.2
Llama3 Base 8B SimPOprinceton-nlp/Llama-3-Base-8B-SFT-SimPO22.020.323.4
Llama3 Instruct 8B SFTmeta-llama/Meta-Llama-3-Instruct-8B26.025.322.3
Llama3 Instruct 8B RRHFprinceton-nlp/Llama-3-Instruct-8B-RRHF31.328.426.5
Llama3 Instruct 8B SLiC-HFprinceton-nlp/Llama-3-Instruct-8B-SLiC-HF26.927.526.2
Llama3 Instruct 8B DPOprinceton-nlp/Llama-3-Instruct-8B-DPO40.337.932.6
Llama3 Instruct 8B IPOprinceton-nlp/Llama-3-Instruct-8B-IPO35.635.630.5
Llama3 Instruct 8B CPOprinceton-nlp/Llama-3-Instruct-8B-CPO33.131.826.4
Llama3 Instruct 8B KTOprinceton-nlp/Llama-3-Instruct-8B-KTO33.131.826.4
Llama3 Instruct 8B ORPOprinceton-nlp/Llama-3-Instruct-8B-ORPO28.527.425.8
Llama3 Instruct 8B R-DPOprinceton-nlp/Llama-3-Instruct-8B-RDPO41.137.833.1
Llama3 Instruct 8B SimPOprinceton-nlp/Llama-3-Instruct-8B-SimPO44.740.533.8

Use our models for inference

Please refer to the generate.py script for detailed instructions on loading the model with the appropriate chat template.

Install Requirements

Our codebase is built upon the alignment-handbook repo. The following steps will guide you through the installation process.

First, create a Python virtual environment using e.g. Conda:

conda create -n handbook python=3.10 && conda activate handbook

Next, install PyTorch v2.2.2. Since this is hardware-dependent, we direct you to the PyTorch Installation Page.

You can then install the remaining package dependencies of alignment-handbook as follows:

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

You will also need Flash Attention 2 installed, which can be done by running:

python -m pip install flash-attn --no-build-isolation

Training Scripts

We provide four training config files for the four training setups reported in our paper. The training config is set for 4xH100 GPUs. You may need to adjust num_processes and per_device_train_batch_size based on your computation environment.

ACCELERATE_LOG_LEVEL=info accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml scripts/run_simpo.py training_configs/mistral-7b-base-simpo.yaml
ACCELERATE_LOG_LEVEL=info accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml scripts/run_simpo.py training_configs/mistral-7b-instruct-simpo.yaml
ACCELERATE_LOG_LEVEL=info accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml scripts/run_simpo.py training_configs/llama-3-8b-base-simpo.yaml
ACCELERATE_LOG_LEVEL=info accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml scripts/run_simpo.py training_configs/llama-3-8b-instruct-simpo.yaml
ACCELERATE_LOG_LEVEL=info accelerate launch --config_file accelerate_configs/deepspeed_zero3.yaml scripts/run_simpo.py training_configs/llama-3-8b-instruct-simpo-v2.yaml

Evaluation

We follow the official implementation for evaluation on AlpacaEval 2, Arena-Hard, and MT-Bench, as follows (more details can be found under the eval directory):

Bugs or Questions?

If you have any questions related to the code or the paper, feel free to email Yu (yumeng5@virginia.edu). If you encounter any problems when using the code, or want to report a bug, feel free to open an issue! Please try to specify the problem with details so we can help you better and quicker!

Citation

Please cite our paper if you find the repo helpful in your work:

@inproceedings{meng2024simpo,
   title={SimPO: Simple Preference Optimization with a Reference-Free Reward},
   author={Meng, Yu and Xia, Mengzhou and Chen, Danqi},
   booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
   year={2024}
}