[ICLR'25

June 6, 2025View on GitHub

Huggingface Paper ICLR 2025

The official repository which contains the source code for our paper MA-RLHF.

馃敟 News

  • 22 January, 2025: 馃帀 We release the official codebase (ernie-research/MA-RLHF). Stay tuned!馃敟
  • 22 January, 2025: 馃帀 Our work has been accepted to ICLR 2025!

Get Started

Prerequisites

For Gemma-2B and Gemma-7B:

  • Pytorch == 1.12.1
  • Python version == 3.10.14
  • deepspeed == 0.13.1
  • transformers == 4.41.0

For Gemma-2-27B:

  • Pytorch == 2.2.0
  • transformers == 4.44.0

We also provide the environments used in our experiments in requirements.txt, which can be easily installed with

cd ma-rlhf
pip install -r requirements.txt

Installation

  1. Installing our implemented deepspeed-chat:
cd MA-RLHF/applications/DeepSpeed-Chat
pip install -e .
  1. Installing constituent_treelib for parsing based termination (Option)
cd MA-RLHF/Constituent-Treelib
pip install -e .

Dataset

We conduct experiments on four datasets: OpenAI TL;DR, Anthropic HH-RLHF, OpenAI WebGPT, and APPS.

When training on TL;DR, HH-RLHF, and WebGPT, we split each dataset into three parts to carry out Supervised Fine-Tuning (SFT), reward modeling, and Reinforcement Learning with Human Feedback (RLHF) fine-tuning. The data is partitioned as follows: 20% for SFT, 40% for reward modeling, and 40% for RLHF fine-tuning. This partitioning is automated using Deepspeed-Chat codes with a random seed set to 1234.

For the APPS dataset, we divide the data into two parts: 20% for SFT fine-tuning and 80% for RLHF fine-tuning.

Training

SFT Training

cd applications/DeepSpeed-Chat/training/step1_supervised_finetuning && bash training_scripts/run_gemma.sh

Reward Modeling

cd applications/DeepSpeed-Chat/training/step2_reward_model_finetuning && bash training_scripts/run_gemma.sh

PPO Training

cd applications/DeepSpeed-Chat/training/step3_rlhf_finetuning && bash training_scripts/run_gemma.sh

We implement 4 macro action termination conditions in this code, the default is fixed n-gram based termination. This can be changed by passing --termination_condition argument chosen from [fixed, randomized, parsing, ppl]. The hyper-parameters involved in the termination conditions can be specified with --ngram for fixed n-gram based termination, --repeat_times for randomized n-gram based termination, and --parsing_cutoff for parsing based termination.

If the termination condition is set to fixed and --ngram=1, the code will initiate vanilla PPO training instead of MA-PPO.

Note that when training Gemma-2-27B, the --bf16 flag should be enabled.

Hyper-Parameters

Hyper-ParameterGemmaCodeGemma
2B7B27B2B7B
SFTBatch size64 for WebGPT 512 for others1281281632
Epochs35 for WebGPT 1 for others311
Learning rate1e-4 for WebGPT 5e-5 for others2e-55e-65e-62e-6
LR schedulercosinecosinecosinecosinecosine
Warmup ratio0.10.10.100
RMBatch size32 for WebGPT 64 for others128 for TL;DR 64 for HH-RLHF 32 for WebGPT128--
Epochs111--
Learning rate2e-5 for WebGPT 1e-5 for others1e-68e-6--
LR schedulercosinecosinecosine--
Warmup ratio0.10.10.1--
PPOBatch size2562562561616
Policy learning rate1.5e-51e-67e-75e-75e-7
Critic learning rate1.5e-51e-61e-65e-55e-5
Epochs11111
PPO epochs11111
Rollout11111
Clip ratio0.20.20.20.20.2
\lambda in GAE0.950.950.950.950.95
\gamma in GAE11111
KL coefficient0.050.1 for WebGPT 0.05 for others0.10.050.05
Max prompt length512512512600600
Max response length512512512512512
Warmup steps20020002020
Temperature0.80.80.81.01.0
Top-p1.01.01.01.01.0
Top-k50505055

Inference

We provide a Python file for inference located at MA-RLHF/inference/inference_with_rewards.py. In this file, we randomly select 2000 instances from the validation sets (using seed 1234) for inference. The generated responses are then scored with the reward model.

You can run the inference script with the following command:

cd MA-RLHF
python inference/inference_with_rewards.py \
    --proj-path ${PROJ_PATH} \
    --dataset summarize \
    --model ${actor_model_path} \
    --reward-model ${reward_model_path} \
    --temperature 0.8 \
    --gpu 0 \
    --batch-size 16

The --dataset argument can be chosen from [summarize, hh-rlhf, webgpt], corresponding to openai/summarize_from_feedback, Dahoas/full-hh-rlhf, and openai/webgpt_comparisons, respectively. The inference results will be saved in ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name}.jsonl.

Evaluation

RM Scores

The RM scores have already been computed during the inference stage.

GPT-4 Evaluation

For GPT-4 evaluations, we randomly select 50 instances from the inference results. This can be done with the following command:

python evaluation/tools/sample_from_dataset.py \
    --data-path ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name}.jsonl \
    --save-path ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name}-sampled.jsonl \
    --dataset summarize

Specifically, we select 50 instances for the summarization task based on the provided SubReddit information by passing the --dataset summarize argument for a comprehensive evaluation.

The GPT-4 evaluation results can be obtained using:

# TL;DR and HH-RLHF
python evaluation/gpt4-eval.py \
    --model_name_a ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name_a}-sampled.jsonl \
    --model_name_b ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name_b}-sampled.jsonl \
    --dataset summarize \
    --output ${PROJ_PATH}/results/sumamrize/${actor_model_name_a}-v.s.-${actor_model_name_b}.jsonl \
    --sk ${OPENAI_SK}

# WebGPT
python evaluation/gpt4-webgpt-eval.py \
    --model_name_a ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name_a}-sampled.jsonl \
    --model_name_b ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name_b}-sampled.jsonl \
    --dataset summarize \
    --output ${PROJ_PATH}/results/sumamrize/gpt4-${actor_model_name_a}-v.s.-${actor_model_name_b}.jsonl \
    --sk ${OPENAI_SK}

The human evaluation results can be obtained using:

python evaluation/human-eval.py \
    --model_name_a ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name_a}-sampled.jsonl \
    --model_name_b ${PROJ_PATH}/results/${dataset}/temperature=${temperature}/${actor_model_name_b}-sampled.jsonl \
    --output ${PROJ_PATH}/results/${dataset}/human-${actor_model_name_a}-v.s.-${actor_model_name_b}.jsonl

Citation

@inproceedings{chai2025marlhf,
   title={{MA}-{RLHF}: Reinforcement Learning from Human Feedback with Macro Actions},
   author={Yekun Chai and Haoran Sun and Huang Fang and Shuohuan Wang and Yu Sun and Hua Wu},
   booktitle={The Thirteenth International Conference on Learning Representations},
   year={2025},
   url={https://openreview.net/forum?id=WWXjMYZxfH}
}