RAIN: Your Language Models Can Align Themselves without Finetuning

Yuhui Li, Fangyun Wei, Jinjing Zhao, Chao Zhang, Hongyang Zhang

Aligning Large Language Models (LLMs) to human preferences usually requires resource-heavy finetuning and massive datasets. This paper introduces RAIN (Rewindable Auto-regressive INference), a novel inference-time algorithm that allows frozen LLMs to align themselves through self-evaluation and tree search. By simply pausing to "think, evaluate, and rewind" before speaking, models can drastically improve their safety and truthfulness without any parameter updates or extra training data.

The Challenge of Self-Alignment

Current alignment techniques like RLHF (Reinforcement Learning from Human Feedback) or DPO (Direct Preference Optimization) are highly effective but notoriously expensive. They require meticulously annotated human preference data and massive computational resources to fine-tune multiple billion-parameter models (such as policy, reward, value, and reference models). Furthermore, fine-tuning risks catastrophic forgetting, where the model overwrites knowledge acquired during pre-training.

The authors tackle the challenge of self-alignment: can we make a frozen, pre-trained LLM generate safe, helpful, and truthful responses without any gradient updates, reinforcement learning, or external alignment data?

Methods: Rewindable Auto-regressive INference (RAIN)

The authors propose RAIN, a plug-and-play inference strategy that treats text generation as a tree search problem. Instead of generating tokens strictly left-to-right and never looking back (vanilla auto-regressive inference), RAIN allows the model to simulate future tokens, evaluate them, and rewind if they lead to poor outcomes.

RAIN Algorithm Overview

Key components of the method include:

  • Self-Evaluation: The frozen LLM acts as its own reward model. It is prompted to score its own simulated continuations (e.g., by asking it, "Is this generated response harmful?").
  • Tree Search: RAIN uses a search algorithm inspired by Monte Carlo Tree Search (specifically the PUCT algorithm) to balance exploitation (following paths the model already thinks are good) and exploration (trying new, unvisited token sequences).
  • Rewind and Update (Inner Loop): The model generates a candidate sequence, self-evaluates it, and rewinds back to the root, updating the "value" of those tokens. To improve efficiency, it also updates the values of semantically similar sibling nodes using Sentence-BERT embeddings.
  • Generation (Outer Loop): After a set number of simulations, the model permanently commits to the token set with the highest visit count, moving the actual generation forward.

Key Insights and Emergent Capabilities

The results of RAIN support the Superficial Alignment Hypothesis, which suggests that pre-trained models already "know" what is safe or truthful; alignment simply teaches them which sub-distribution of their knowledge to output. RAIN proves this selection can happen entirely at inference time.

Modern LLMs are highly capable of recognizing their own toxic or incorrect outputs when explicitly asked to evaluate them, even if their default generation strategy would have produced that bad output anyway. The authors show that RAIN's guided search is vastly superior to naive rejection sampling (generating many responses and picking the best), achieving better safety with far fewer simulated tokens. Furthermore, the effectiveness of RAIN scales with model size. Smaller models lack the self-evaluation capabilities to guide the search effectively, while larger models (30B+ parameters) see massive safety improvements without degrading helpfulness.

Key Results

The authors evaluated RAIN across four distinct tasks: Anthropic's Helpful and Harmless (HH) dataset, AdvBench (for adversarial robustness), TruthfulQA, and the IMDB Dataset (for sentiment control).

Harmlessness Rate Comparison
  • Safety (HH Dataset): RAIN improved the harmlessness rate of the LLaMA 30B model from 82% (vanilla inference) to 97%, without sacrificing its helpfulness score. As shown above, it performed competitively with, and even exceeded, models that underwent full RLHF or RLAIF.
  • Truthfulness (TruthfulQA): When applied to an already-aligned LLaMA-2-chat 13B model, RAIN pushed truthfulness up by an additional 5% (from 69.2% to 74.1%).
  • Adversarial Defense (AdvBench): RAIN drastically reduced the success rate of white-box jailbreak attacks. For Vicuna 33B, the attack success rate plummeted from 94% to just 19%.
  • Sentiment Control (IMDB): RAIN successfully steered LLaMA 7B to generate positive reviews, increasing the positive sentiment ratio from 62.1% to 82.1%.

Limitations and Future Work

While highly effective, RAIN does introduce an inference overhead. Because it simulates multiple future paths before committing to a token, it is computationally heavier at inference time (averaging a 4x slowdown). However, this is often an acceptable trade-off given it completely avoids the massive upfront compute and memory costs of RLHF.

Additionally, the method relies entirely on the model's internal ability to self-evaluate. If a model is too small to accurately judge its own outputs, RAIN provides little to no benefit. Finally, while the authors evaluated robustness against static adversarial attacks, future work is needed to see how RAIN holds up against adaptive attacks specifically designed to trick the self-evaluation mechanism.

Summary updated

BibTeX
@inproceedings{li2024rain,
  author = {Yuhui Li and Fangyun Wei and Jinjing Zhao and Chao Zhang and Hongyang Zhang},
  title = {{RAIN: Your Language Models Can Align Themselves without Finetuning}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=pETSfWMUzy},
}
Figure