Putting RL back in RLHF
RLOO (REINFORCE Leave-One-Out) is now available as a trainer in Hugging Face TRL. It is an online RLHF algorithm that drops PPO's value model. It treats the whole completion as a single action, uses the REINFORCE loss, and computes each sample's baseline as the mean reward of the other k−1 completions for the same prompt. That cuts vRAM by roughly 50-70% and makes training 2-3x faster than PPO on Pythia 1B and 6.9B, while matching PPO's GPT-4-judged win rate (78.7% for 6.9B on TL;DR) and beating DPO. Code walkthroughs show the advantage computation and that REINFORCE is a special case of the PPO loss. There is a caveat: bf16 numerical mismatches between generation and training logprobs hurt RLOO more than PPO.
Related posts
- StackLLaMA: A hands-on guide to train LLaMA with RLHF
Hugging Face hardMasterA 7B LLaMA model is trained to answer Stack Exchange questions with the full RLHF pipeline: supervised fine-tuning on packed Stack Exchange text, a pairwise reward model trained on upvote-derived preference scores, and PPO with a KL penalty against a frozen reference model. Memory is kept manageable by loading the model in 8-bit and training only LoRA adapters via peft, which needs roughly 1.2-1.4GB per billion parameters. The same frozen base serves as both policy and reference model, and data parallelism through accelerate or torchrun speeds up training. The reward model reaches 67% accuracy, and the RL run takes about 20 hours on 24 A100s. The post closes with practical notes on reward hacking and training instabilities.
- The N Implementation Details of RLHF with PPO
Hugging Face hardMasterA from-scratch PyTorch reproduction of OpenAI's 2019 lm-human-preferences RLHF codebase closely matches the original learning curves on stylistic tasks like sentiment and descriptiveness. Along the way it catalogs the implementation details that matter for faithful replication: reward model and value head scoring the concatenated query and response, a dedicated out-of-vocabulary padding token, position-index adjustment for padding, fixed-length sampling that ignores EOS, learning-rate annealing, per-process seeds, reward normalization, rejection sampling and reward whitening. It also documents a TensorFlow vs PyTorch Adam numerical difference that causes overly aggressive updates, and how different base models behave when reward labels come from gpt2-large. Practical notes show how to replicate each behaviour with Hugging Face transformers, along with the hardware constraints of running the original TF1 code.
- Fine-tune Llama 2 with DPO
Hugging Face hardMasterDirect Preference Optimization (DPO) replaces the reward-model and RL steps of RLHF with a simple binary cross-entropy loss over preference pairs, using a frozen reference model to provide an implicit reward. With TRL's DPOTrainer, data is formatted as prompt/chosen/rejected triples and training is controlled by a beta temperature, typically 0.1 to 0.5. The walkthrough fine-tunes Llama 2 7B on the stack-exchange preference dataset: first SFT with QLoRA (4-bit NF4 plus LoRA adapters), then DPO using the SFT model as both policy and reference. Progress is monitored with logged reward metrics (chosen, rejected, accuracies, margins), where margins should grow and accuracies should approach 1.0.
- TRL v1.0: Post-Training Library Built to Move with the Field
Hugging Face mediumAdeptTRL v1.0 turns Hugging Face's post-training codebase, now covering 75+ methods and downloaded 3M times a month, into a library with an explicit stability contract. A semver-governed stable core (SFT, DPO, reward modeling, RLOO, GRPO trainers) sits alongside a fast-moving trl.experimental namespace. Methods are promoted based on the ratio of usage to maintenance cost. Because post-training paradigms keep shifting (PPO to DPO to RLVR/GRPO), the design deliberately avoids shared base classes and generic abstractions and accepts near line-for-line duplication between trainers like RLOO and GRPO, illustrated by the failed Judge abstraction. A comparison against OpenRLHF, veRL, PRIME-RL, Tinker, LLaMA-Factory and others positions TRL as broad, low-infrastructure and stable but lacking native tensor parallelism, with asynchronous GRPO planned next.
- vLLM V0 to V1: Correctness Before Corrections in RL
Hugging Face hardMasterMigrating PipelineRL's rollout generation from vLLM V0 (0.8.5) to V1 (0.18.1) caused training metrics (clip rate, KL, entropy, reward) to diverge. Matching the V0 reference took four backend fixes: setting logprobs-mode=processed_logprobs so returned logprobs reflect temperature and top-k/top-p processing, explicitly disabling V1's default prefix caching and async scheduling, reproducing V0's inflight weight-update semantics with pause_generation(mode="keep", clear_cache=False), and computing the lm_head in fp32 to match the trainer. Batch invariance and the logprob-mode fix alone did not close the gap. The broader recommendation is to restore inference-backend correctness before adding objective-side off-policy corrections such as truncated importance sampling, so those corrections don't hide backend bugs.