Averaging log-likelihoods in direct alignment

Nathan Grinsztajn, Yannis Flet-Berliac, Mohammad Gheshlaghi Azar, Florian Strub, Bill Wu, Eugene Choi, Chris Cremer, Arash Ahmadian, Yash Chandak, Olivier Pietquin, Matthieu GeistarXiv 2024

Abstract

To better align Large Language Models (LLMs) with human judgment, Reinforcement Learning from Human Feedback (RLHF) learns a reward model and then optimizes it using regularized RL. Recently, direct alignment methods were introduced to learn such a fine-tuned model directly from a preference dataset without computing a proxy reward function. These methods are built upon contrastive losses involving the log-likelihood of (dis)preferred completions according to the trained model. However, completions have various lengths, and the log-likelihood is not length-invariant. On the other side, the cross-entropy loss used in supervised training is length-invariant, as batches are typically averaged token-wise. To reconcile these approaches, we introduce a principled approach for making direct alignment length-invariant. Formally, we introduce a new averaging operator, to be composed with the optimality operator giving the best policy for the underlying RL problem. It translates into averaging the log-likelihood within the loss. We empirically study the effect of such averaging, observing a trade-off between the length of generations and their scores.

Introduction

The standard pipeline for training Large Language Models (LLMs) involves three steps: pre-training, Supervised Fine-Tuning (SFT), and alignment (usually via RLHF or Direct Alignment). A subtle but important discrepancy exists between these steps: SFT uses a cross-entropy loss that is typically averaged token-wise, making it length-invariant. In contrast, alignment methods like Direct Policy Optimization (DPO) and Identity Policy Optimization (IPO) utilize the total log-likelihood of a sequence. Because log-likelihoods are additive, longer sequences naturally have lower (more negative) values, potentially leading to optimization instabilities or a "length bias," where the model favors verbosity over quality.

Methodology

We introduce a principled way to reconcile these approaches using a new mathematical framework. We define an averaging operator ($F$) that converts a standard policy into a "length-normalized" version, where the probability of a sequence is the geometric mean of its token probabilities. By composing this with the optimality operator, we derive a modified loss function for direct alignment. This derivation results in a simple but effective modification: in the loss function, every instance of a log-likelihood $\ln \pi(y|x)$ is replaced by its length-normalized version: $\frac{1}{|y|} \ln \pi(y|x)$. This provides a formal derivation from RL first principles for a technique previously used only as a heuristic.

Experimental Setup

We evaluated our approach using the Reddit TL;DR summarization dataset with Llama2-7B as the base policy. A Bradley-Terry reward model was trained on the preference split to serve as a ground truth proxy for evaluating generation quality.

Results and Discussion

The Pareto Front Shift

The most significant empirical finding is the visualization of the reward-vs-length trade-off. As shown in Figure 4, the "average" versions of DPO and IPO consistently sit on a higher Pareto front, achieving higher quality scores for shorter sequence lengths compared to their standard counterparts.

Reward vs. generation length Pareto front, illustrating that averaged methods achieve better quality-brevity trade-offs.

Sensitivity to Hyperparameters

We observed that averaging log-likelihoods fundamentally changes the model's response to the KL-regularization parameter ($\beta$). As illustrated in Figure 2, the optimal $\beta$ for DPO(avg) is significantly higher (approximately ten times) than for standard DPO. This suggests that normalization requires a stronger "anchor" to the reference model to maintain stability.

Final reward vs. beta parameter, showing that averaged methods require higher regularization values for optimal performance.

Brevity and Reward Hacking

Normalized models produced more concise summaries that were rated higher by the reward model. However, we also observed that length-normalized models might be more prone to reward hacking if trained for too long. In late-stage training, models began generating repetitive punctuation (e.g., strings of "?!?!") to exploit the reward model, suggesting that while averaging is powerful, it requires careful early stopping or improved regularization.

Conclusion

This work provides a theoretical foundation for length-normalization in direct alignment. By moving from a heuristic "hack" to a derived theory, we provide a robust method for improving the efficiency and brevity of aligned LLMs. Future work will explore the generalizability of these findings to multi-turn dialogue and reasoning tasks.

Summary updated

BibTeX
@misc{grinsztajn2024averaging,
  author = {Nathan Grinsztajn and Yannis Flet-Berliac and Mohammad Gheshlaghi Azar and Florian Strub and Bill Wu and Eugene Choi and Chris Cremer and Arash Ahmadian and Yash Chandak and Olivier Pietquin and Matthieu Geist},
  title = {{Averaging log-likelihoods in direct alignment}},
  year = {2024},
  eprint = {2406.19188},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.19188},
}
Figure