Skip to main content
Back

SEA Beats Best-of-64 Sampling by 77% Without Touching Model Weights

A new inference-time alignment method uses gradient descent in continuous logit space instead of sampling, beating Best-of-64 with fewer computations.

Pro

  • SEA replaces Best-of-N sampling with gradient-based optimization on continuous logits guided by a reward model.
  • Achieves up to 77.51% relative improvement on AdvBench safety and 16.36% on MATH reasoning over baselines.
  • Formulates the RLHF optimal policy as an energy-based model, sampled via Langevin MCMC.
  • Solves shallow alignment: maintains 0% attack success rate under prefilling attacks on LLaMA-3.2-1B-Instruct.
  • Runs faster than Best-of-64 while producing better safety, truthfulness, and reasoning outcomes.
  • Code released at github.com/yuanyige/sea for plug-and-play use with any LLM and reward model.

Aligning large language models to human preferences at inference time usually means one thing: generate a bunch of candidate responses and pick the best one according to a reward model. That's Best-of-N sampling in a nutshell, and it works fine until your base model is weak or your candidate pool is small. Then you're stuck searching for a good needle in a haystack that doesn't contain one.

A team from the Chinese Academy of Sciences, University of Washington, and Allen Institute for AI proposes a different approach in Simple Energy Adaptation (SEA). Instead of sampling many discrete responses and ranking them, SEA runs gradient descent directly on the continuous logits of a single response, pushing it toward higher reward using signals from the reward model itself. The method outperforms the second-best baseline with a relative improvement of up to 77.51% on AdvBench and 16.36% on MATH.

Why Best-of-N Hits a Wall

The core issue with search-based inference alignment is combinatorial. If the probability of generating an optimal response under the base policy is sigma, the probability that at least one optimal response appears in N samples is 1 minus (1 minus sigma) to the Nth power, which stays small when sigma is low or N is insufficient. In plain terms: if your base model rarely produces good answers, you need exponentially more samples to stumble onto one.

Empirical analysis on AdvBench shows that as the log probability of good responses decreases, the minimum N required to generate a safe response increases, meaning weaker base models need exponentially larger candidate pools. Discrete search is bottlenecked by whatever the base model can already produce.

Charts showing Best-of-N reward saturation and SEA outperforming across safety, truthfulness, and reasoning tasks

Optimization Instead of Sampling

SEA reframes the problem. Rather than sampling discrete responses and picking one, it treats the RLHF optimal policy as an energy-based model and runs gradient-based sampling on it. An energy-based model defines a probability distribution through an energy function, where lower energy means higher probability. Here the energy combines the base policy's log-probability with the reward, so descending the energy pushes responses toward outputs that are both plausible and highly rewarded.

The catch: tokens are discrete, so you can't take gradients directly. SEA uses the continuous logits (soft outputs) of the LLM as a differentiable representation, feeding them directly to the reference and reward models rather than mapping through the vocabulary, with a straight-through estimator handling the argmax in the forward pass.

The actual sampling uses Langevin dynamics, a well-known MCMC method that combines gradient descent with a bit of Gaussian noise for exploration. The update rule looks like this:

y_next = y_current - eta * grad_E(x, y_current) + noise
grad_E = grad(log pi_ref(y|x) + alpha * r(x, y))

Where pi_ref is the reference model, r is the reward, and alpha controls how aggressively to chase reward versus staying close to the base policy. The chain is initialized from a response sampled from the reference policy rather than random noise, since random initialization converges too slowly. After a fixed number of steps (typically 10 to 50), the final logits get decoded into text.

The Numbers

SEA was tested on three task families using four LLaMA-3 variants (1B, 3B, 8B base models plus a 1B instruct model), with GRM-LLaMA-3.2-3B as the reward model:

  • Safety (AdvBench): On LLaMA-3.2-1B-Base, SEA drops the harmful rate from 65.96% (SFT) to 5.58%, versus 43.85% for Best-of-64.
  • Truthfulness (TruthfulQA): On LLaMA-3.2-1B-Instruct, truthful rate hits 89% versus 77% for Best-of-64, while diversity also improves.
  • Reasoning (MATH): Accuracy jumps to 32% versus 16% for Best-of-64 on LLaMA-3.2-1B-Instruct. On GSM8K, 58% versus 57%.

Interestingly, Best-of-N sometimes hurts reasoning accuracy: BoN-64 scores 16% on MATH versus 27.5% for the SFT baseline. The reward model rewards responses that look good, not necessarily ones that are correct, so ranking many samples can degrade rather than improve performance.

On compute, SEA matches Best-of-64's efficiency at larger Langevin steps and surpasses it with fewer steps, avoiding both the token-by-token search cost of ARGS and the reliance on large candidate sets. A 10-step SEA run takes about 4.7 seconds per sample versus 7.3 seconds for BoN-64.

The Deeper Fix: Beating Shallow Alignment

A subtler but important result concerns what researchers call shallow alignment: safety-trained models tend to concentrate their alignment on the first few tokens of a response. If an attacker can prefill the response with something like "Sure, here's a guide," the auto-regressive model happily continues into harmful territory.

KL divergence heatmap across token positions and iterations, showing SEA distributes alignment across all positions

Because SEA optimizes all token positions simultaneously in continuous space, it doesn't have this bias. The KL budget is evenly distributed across all positions, unlike traditional alignment which focuses on just a few prefix positions, with the largest KL updates in the final SEA iteration actually falling on later token positions. When tested under prefilling attacks, SEA maintained a 0% attack success rate on LLaMA-3.2-1B-Instruct regardless of how many harmful tokens were prefixed, and outperformed BoN-32 by 85.96% on the base model when 7 harmful tokens were prefixed.

What This Is Good For

SEA plugs into any unaligned or partially-aligned LLM without touching its weights, which makes it useful when:

  1. You want to swap reward models frequently without retraining, for instance combining separate helpfulness and harmlessness rewards. The energy-based formulation allows direct composition of reward distributions for multi-dimensional alignment.
  2. Your base model is weak and Best-of-N would need infeasibly large N to find good candidates.
  3. You need robustness against jailbreaks that exploit shallow alignment, such as prefilling attacks.
  4. You're doing reasoning tasks where reward ranking of independent samples degrades rather than improves accuracy.

Limitations Worth Knowing

SEA inherits the standard drawback of inference-time methods: higher per-sample latency than a purely trained-in solution. You're running an MCMC chain at inference, and although the paper shows favorable numbers versus BoN and ARGS, this is still slower than a single forward pass. Hyperparameters (learning rate eta, KL coefficient alpha, softmax temperature, top-k mask) also need per-dataset tuning. And the whole thing still depends on the reward model, though SEA maintains strong performance with a weaker reward model, showing only a 5-point HarmRate increase versus a much larger jump for SFT baseline.

The code is available at the official GitHub repository, and the full paper with derivations and ablations is on arXiv. For anyone building alignment pipelines, SEA is worth a serious look, especially if your current Best-of-N setup is plateauing.