Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Apple Machine Learning Research 1 min read Research hardMaster

Theoretical Limits of Language Model Alignment

The maximum expected reward gain achievable under a fixed KL-divergence budget in KL-regularized language model alignment has a closed form governed by a Jeffreys divergence term, not the √KL used in prior analyses. Rewritten as a covariance under the base model, it gives an estimator that predicts achievable alignment gains from base model samples alone. With proxy rewards, the gap from ideal alignment (reward hacking) grows with reward error and with smaller KL penalties, and reward ensembling provably mitigates it. On safety and summarization tasks, best-of-N comes close to the theoretical KL–reward frontier while PPO and GRPO fall well short, which suggests better algorithms are needed to reach optimal alignment without high inference costs.

Assumes: KL divergenceRLHFbest-of-N samplingreward models

Related posts

  • Preference Tuning LLMs with Direct Preference Optimization Methods

    Hugging Face hardMaster

    An empirical comparison of three RL-free preference alignment methods (DPO, IPO and KTO) on two SFT'd 7B models, Zephyr-7b-beta-sft and OpenHermes-2.5-Mistral-7B, sweeping β from 0.01 to 0.9 with TRL's DPOTrainer and scoring the results on MT-Bench. After a fix to TRL's IPO implementation, which now averages rather than sums log-likelihoods, DPO and IPO perform comparably and both beat KTO in the paired-preference setting. The best β varies sharply by model and algorithm: 0.01 works best for Zephyr, while OpenHermes favours 0.6, 0.3 and 0.01. That makes β tuning essential. KTO remains attractive because it only needs thumbs-up/down labels rather than paired preferences, and configs and sweep scripts are published in the alignment-handbook.

  • StackLLaMA: A hands-on guide to train LLaMA with RLHF

    Hugging Face hardMaster

    A 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.

  • Fine-tune Llama 2 with DPO

    Hugging Face hardMaster

    Direct 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.

  • Vision Language Model Alignment in TRL ⚡️

    Hugging Face hardMaster

    TRL adds vision language model support for several alignment methods. New are Mixed Preference Optimization (MPO), Group Relative Policy Optimization (GRPO) and its sequence-level variant GSPO, alongside multimodal RLOO, Online DPO and native SFTTrainer support. MPO is implemented in DPOTrainer as a weighted combination of DPO sigmoid, BCO and SFT losses, which the MPO paper reports gives a 6.2-point MathVista gain. GRPO uses custom format and accuracy reward functions. GSPO is enabled through GRPOConfig with sequence-level importance sampling, which is mainly useful for MoE models. Code snippets show each trainer config, and a vibe-check comparison on Qwen2.5-VL-3B shows the GRPO and GSPO runs reaching the correct geometry answer where the base and MPO models do not.

  • Putting RL back in RLHF

    Hugging Face hardMaster

    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.

The quest for software engineering knowledge.

Look:
Layout: