Hugging Face TRL RLOO Trainer Release

Hugging Face has introduced the RLOO (REINFORCE Leave One-Out) Trainer in the TRL library. RLOO is an online RLHF training algorithm designed to be a more accessible and efficient alternative to Proximal Policy Optimization (PPO), requiring significantly less GPU memory and shorter convergence times.

Performance and Efficiency Gains

RLOO provides substantial improvements in resource utilization and training speed compared to PPO:

  • Memory Efficiency: RLOO uses approximately 50-70% less vRAM than PPO, depending on the model size.
  • Training Speed: RLOO runs 2x faster than PPO with 1B parameter models and up to 3x faster with 6.9B models.
  • Model Quality: RLOO performs competitively with PPO in terms of response win rate (as judged by GPT-4) and consistently outperforms offline methods such as Direct Preference Optimization (DPO).

Technical Architecture and Motivation

Traditional PPO is resource-intensive because it requires loading four model copies into memory: the policy model, the reference policy model, the reward model, and the value model. RLOO simplifies this architecture by removing the value model, requiring only three copies: the policy model, the reference policy model, and the reward model.

Key Algorithmic Differences

RLOO differs from PPO in how it handles actions and rewards:

  1. Completion-Level Actions: While PPO treats each completion token as an individual action, RLOO treats the entire model completion as a single action. This addresses the issue of sparse rewards, where typically only the EOS (end-of-sentence) token receives a true reward; RLOO attributes the EOS reward to the entire completion.
  2. REINFORCE Loss: RLOO utilizes the REINFORCE loss, which multiplies the difference between the reward and a baseline by the log probability of the actions. This eliminates the need for the value model and Generalized Advantage Estimation (GAE) required by PPO.
  3. Leave-One-Out Baselines: RLOO calculates baselines by using the rewards of all other samples in a batch as the baseline for a specific sample. For a given prompt, the baseline for one completion is the average reward of all other completions generated for that same prompt.

Implementation in TRL

The RLOO Trainer is built upon an experimental PPOv2Trainer. Although RLOO is conceptually based on the REINFORCE algorithm, the TRL implementation uses the PPO loss because the REINFORCE loss is a special case of the PPO loss.

Benchmarking Results

Experiments conducted on Pythia 1B and 6.9B models demonstrate the efficacy of the RLOO implementation:

  • Pythia 6.9B: Achieved a 78.7% preferred rate (k=2) using GPT-4 as a judge, exceeding the original paper's reported performance of 77.9% (k=4) and 74.2% (k=2).
  • Pythia 1B: Achieved a 40.1% win rate compared to the SFT (Supervised Fine-Tuning) checkpoint's 21.3% win rate.

Numerical Stability Challenges with bf16

RLOO exhibits significant numerical stability issues when using bf16 precision. Log probabilities obtained during generation can differ slightly from those obtained during training forward passes.

In PPO, the clipping coefficient (typically 0.2) nulls the gradient for individual tokens where the ratio exceeds 1.2 or falls below 0.8. In RLOO, because the entire completion is treated as one action, these numerical discrepancies are compounded. This results in the gradient for the entire sequence being nulled more frequently. Empirical observations show that PPO nulls approximately 3% of batch data, whereas RLOO nulls between 20-40% of batch data under bf16.

Sources