Inference-time Alignment in Continuous Space

Yige Yuan, Teng Xiao, Li Yunfan, Bingbing Xu, Shuchang Tao, Yunqi Qiu, Huawei Shen, Xueqi Cheng

TL;DR

Most Large Language Model (LLM) alignment happens during expensive training phases or through "Best-of-N" sampling at inference time. This paper introduces Simple Energy Adaptation (SEA), a method that aligns models during inference by treating the response space as continuous rather than discrete. By using gradients from a reward model to iteratively "nudge" a response’s logits toward higher-reward regions, SEA achieves significantly better alignment than traditional search methods, especially when the base model is weak.

Aligning LLMs with human values—such as safety, helpfulness, and truthfulness—typically requires Reinforcement Learning from Human Feedback (RLHF), which is computationally heavy and inflexible. As an alternative, "inference-time alignment" has gained popularity. The standard approach, Best-of-N (BoN), involves generating $N$ different responses and picking the one with the highest reward.

However, the authors identify a fundamental flaw: BoN is a search within a discrete space. It relies entirely on the base model's ability to accidentally generate a good response within a limited number of tries. If the base model is weak or the task is difficult (like complex math), the probability of generating even one high-quality candidate is near zero. In these cases, searching a discrete set of samples is like looking for a needle in a haystack where the needle might not even exist.

Methods: Moving to Continuous Optimization

The core innovation of SEA is moving from discrete search to continuous optimization.

Conceptual comparison of discrete search versus continuous gradient-based optimization (SEA).
  1. Logit-Space Optimization: Instead of working with discrete text tokens, SEA operates on the "logits" (the raw, unnormalized scores the model produces before picking a word). Because logits are continuous, they are differentiable.
  2. Energy-Based Formulation: The authors formulate the optimal alignment policy as an Energy-Based Model (EBM). In this framework, the "energy" of a response is a combination of how likely the base model thinks the response is and how high the reward model scores it.
  3. Langevin Dynamics: To find the "minimum energy" (the best response), SEA uses Langevin Markov Chain Monte Carlo (MCMC). It starts with an initial response from the base model and iteratively updates the logits using the gradient of the reward model. Essentially, it "slides" the response toward a version that satisfies the reward model better.
  4. Global Receptive Field: Unlike autoregressive decoding (which generates text one word at a time), SEA optimizes the entire sequence simultaneously. This allows the model to correct harmful or incorrect paths even if they started "shallowly" (e.g., a model starting a harmful response with "Sure!" can be steered back to a refusal).

Key Insights and Ideas

  • Gradients > Random Samples: The "aha moment" is that the reward model contains much more information than a single scalar score. By looking at the gradient of the reward, the system knows exactly how to change the response to make it better, rather than just guessing with new samples.
  • Mitigating "Shallow Alignment": Many aligned models are only "safe" because they've learned to start responses with a refusal. If a user forces the model to start with "Sure, here is...", the safety often breaks. Because SEA optimizes the whole sequence at once, it can recover from these "prefilling attacks" by steering the later parts of the sentence toward safety.
  • Efficiency at Scale: While iterative optimization sounds slow, the authors found that SEA-n4-s10 (4 chains, 10 steps) is actually faster and uses less memory than BoN-128 while producing superior results.

Key Results

The authors evaluated SEA across three critical domains: Safety (AdvBench, HH-RLHF), Truthfulness (TruthfulQA), and Reasoning (GSM8K, MATH). SEA consistently outperformed state-of-the-art inference-time baselines.

Relative improvement in rate and reward for SEA compared to Best-of-N (BoN) across AdvBench, TruthfulQA, and GSM8K.
  • Safety: On AdvBench, SEA achieved a relative improvement of 77.51% in reducing harmful rates compared to the second-best baseline.
  • Reasoning: On the challenging MATH dataset, SEA saw a 16.36% relative improvement in accuracy.
  • Robustness: SEA maintained a 0% Attack Success Rate on LLaMA-3.2-Instruct even when subjected to prefix attacks that caused other models to fail.
  • Visualizing the "Slide": The paper notes that responses can be observed starting as a detailed plan for a harmful prompt and gradually "melting" into a firm refusal as the continuous iterations progress.

Limitations and Future Work

  • Inference Latency: Although more efficient than massive sampling, iterative optimization is still slower than a standard single-pass generation. Future work could involve "amortized inference"—training a smaller model to predict the result of the SEA optimization in a single step.
  • Non-Autoregressive Artifacts: Optimizing all tokens at once can sometimes lead to repetitive language or unfinished sentences. To combat this, the authors currently use a "revision prompt" to clean up the final text, adding a small amount of overhead.
  • Reward Model Dependency: Like all reward-guided methods, SEA is only as good as the reward model it uses. If the reward model has "blind spots," the gradient-based optimization might exploit them, though tests suggest SEA is more resistant to reward hacking than Best-of-N.

Summary updated

BibTeX
@inproceedings{yuan2025inference,
  author = {Yige Yuan and Teng Xiao and Li Yunfan and Bingbing Xu and Shuchang Tao and Yunqi Qiu and Huawei Shen and Xueqi Cheng},
  title = {{Inference-time Alignment in Continuous Space}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=aokiuaM7Lt},
}
Figure