Long Horizon Temperature Scaling

Andy Shih, Dorsa Sadigh, Stefano Ermon

Abstract

In generative AI, temperature scaling is the standard method for controlling the trade-off between sample quality and diversity. However, in autoregressive models, this scaling is typically applied "myopically" to the next-token distribution, failing to account for the global probability of the entire sequence. We present Long Horizon Temperature Scaling (LHTS), a novel approach that scales the joint probability of the full output sequence. By treating temperature scaling as an optimization problem solved via importance sampling and a variance-reduced finetuning objective, LHTS produces models that effectively "look ahead" to find higher-likelihood outcomes. Our experiments across image generation, character-level modeling, and language tasks demonstrate that LHTS improves reasoning accuracy by 10% and achieves superior Pareto frontiers for likelihood and diversity.

1. Introduction

Autoregressive models generate sequences one element at a time, typically using a temperature parameter $T$ to rescale the logits of the next-token distribution. While effective for controlling local variance, this approach is fundamentally myopic: it optimizes for the immediate next step without considering how that choice constrains the remainder of the sequence. This often leads to suboptimal global outcomes, where a model may favor a common prefix that leads to a low-probability conclusion over a less common prefix that leads to a highly probable sequence.

Researchers from Stanford University have proposed Long Horizon Temperature Scaling (LHTS) to address this limitation. By shifting the focus from the next token to the entire "horizon" of the generated sequence, LHTS allows models to approximate the ideal joint distribution $p_T(x) \propto p(x)^{1/T}$, resulting in outputs that are both more accurate and more coherent.

2. The Problem: Myopic vs. Global Scaling

Standard temperature scaling modifies the probability of the next token $x_{t+1}$ given the history $x_{<t}$. This is a local adjustment. The primary issue is that a likely next token does not always lead to a likely sequence.

Consider a scenario where a model must choose between "tap cabinet," "tap door," and "close door." Because the first two options share the prefix "tap," myopic scaling at $T < 1$ will heavily favor "tap" simply because it aggregates the probability of two potential paths. This occurs even if "close door" is individually more probable than either "tap" option. Ideally, we want to scale the joint distribution—the probability of the entire sentence or image—but calculating this for high-dimensional outputs is mathematically intractable for most model families at inference time.

3. Methodology

LHTS treats temperature scaling as an amortized optimization problem. Instead of an ad-hoc adjustment during sampling, the model is finetuned to internalize the desired temperature scaling.

3.1 The Objective

The goal is to train a model $q_T$ that matches the ideal temperature-scaled joint distribution $p_T(x)$. Since direct sampling from $p_T(x)$ is impossible, the authors employ importance sampling. The original model is finetuned using training samples weighted by their relative likelihood under the target temperature.

3.2 Variance Reduction and Suffix Log-Likelihoods

To maintain stability during training on long sequences, the authors derived a variance-reduced objective. This involves using "suffix log-likelihoods," which require the model to account for the probability of the rest of the sequence when updating its current state. This effectively teaches the model the "value" of future paths during the finetuning phase.

3.3 The Temperature Embedding

Rather than training a separate model for every desired temperature, LHTS utilizes a "temperature token" or embedding. This allows a single model to handle a continuous range of temperatures at inference time, providing a controllable knob that can even extrapolate to temperatures not seen during the finetuning process.

4. Experimental Results

The researchers evaluated LHTS across three distinct domains: image generation (CIFAR-10 with DDPM), character-level modeling (Text8), and language modeling (GPT-2 on OpenWebText).

4.1 Reasoning and Accuracy

On a benchmark of 1,400 multiple-choice analogy questions (e.g., "Athens:Greece :: Moscow:?"), LHTS provided a significant performance boost. GPT-2 models finetuned with LHTS showed a 10% increase in accuracy over standard myopic scaling. This suggests that global scaling helps the model navigate complex reasoning paths that myopic scaling might prematurely abandon.

4.2 Pareto Frontiers

In both image and text domains, LHTS achieved a more favorable trade-off between likelihood (correctness) and diversity. In image generation, this was reflected in improved FID scores; in text, it resulted in lower repetition scores without sacrificing the coherence of the output. LHTS effectively finds sequences that are globally likely but locally diverse.

4.3 Extrapolation

A notable finding was the model's ability to extrapolate. Models finetuned on a narrow range of temperatures (e.g., $T \in [0.9, 1.1]$) were able to generate high-quality, high-likelihood samples at extreme settings like $T=0.1$, outperforming standard models at those same settings.

5. Discussion and Limitations

While LHTS offers a mathematically grounded improvement over standard scaling, it introduces a one-time finetuning cost. Although this is significantly cheaper than training a model from scratch, it remains a consideration for massive frontier models. Additionally, as $T$ approaches zero (the argmax limit), importance weights become high-variance, making the absolute mathematical optimum difficult to reach.

Future work will involve scaling LHTS to larger architectures like GPT-4 or Llama-3 to determine if the 10% accuracy gains persist as base model capability increases. Nevertheless, LHTS represents a significant step toward moving generative AI beyond the next token and toward global sequence optimization.

Summary updated

BibTeX
@inproceedings{shih2023long,
  author = {Andy Shih and Dorsa Sadigh and Stefano Ermon},
  title = {{Long Horizon Temperature Scaling}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=vSqzYxbITL},
}
Figure