How Much is Left? LLMs Linearly Encode Their Remaining Output Length

Mohamed Amine Merzouk, Dmitri Carpov, Mirko Bronzi, Damiano Fornasiere, Adam Oberman

TL;DR

Even though Large Language Models (LLMs) generate text one word at a time without an explicit "fuel gauge," their internal states linearly encode how many tokens are left in their response—even before the first output word is generated. When a model second-guesses itself (emitting a word like "Wait"), this internal estimate jumps upward, and researchers can actively dial response lengths up or down simply by nudging the model along this newly discovered internal direction.

What Problem Does This Paper Address?

When you talk to an LLM, does it already have a rough commitment to how much it's going to say before it begins, or is it purely improvising token-by-token? Beyond satisfying our curiosity, this "commitment question" matters for AI safety—for instance, helping us detect "decorative reasoning," where a model pretends to rethink an answer in its chain-of-thought without actually changing its trajectory.

Previous research in batch scheduling showed that you can statistically guess output length using complex, nonlinear neural networks. However, a complex probe might be computing the length for the model from weak clues. To prove the LLM itself maintains an explicit, accessible representation of remaining length, you have to show it can be read out with the simplest possible tool: a single linear layer.

Methods

The authors freeze several instruction-tuned LLMs (primarily 7B–8B parameter models like Llama-3.1-8B, Olmo-3-7B, and Mistral-7B, plus Qwen3-4B and 32B for targeted tests) and attach linear probes—essentially linear regressions—directly to the models' hidden states (concatenated across all layers in the residual stream).

Figure 1: The three predictors on a four-token answer to “How old is the son?”, followed by EOS (ground-truth remaining counts 4, 3, 2, 1; dashed line, hollow markers). The legend’s “Baseline”, “Prompt-only” and “Count probe” are the constant-median baseline, the Completion Length Probe with exact countdown, and the Remaining Count Probe. The constant-median baseline outputs the dataset median at every position. The Completion Length Probe reads the prompt’s last hidden state once and counts down by one per token, capturing the shape with a fixed offset (9, 8, 7, 6). The Remaining Count Probe reads the hidden state at every position; its predictions (6, 3, 4, 1) are not monotonic, yet it has the lowest MAE (mean absolute error, in tokens; lower is better): 1.0 against 5.0 and 5.5. Toy example for exposition.

They compare three setups, evaluated by Mean Absolute Error (MAE) in tokens on naturally terminated sequences:

  • Constant-median baseline: Always guesses the dataset's median remaining length—the mathematically strictest constant guess under MAE.
  • Completion Length Probe (Prompt-only): Reads the very last token of the prompt to predict total length $T$, then blindly counts down by 1 as each token is generated.
  • Remaining Count Probe: Reads the hidden state at every generated token to dynamically estimate how much text is left.

Finally, they test activation steering: taking the learned probe weights at a single layer and adding or subtracting that vector directly into the model's residual stream during generation to see if it controls verbosity.

Datasets

To test both in-distribution accuracy and cross-dataset generalization, the authors evaluate across seven datasets:

  • Two synthetic datasets: Count and Countdown, where prompts explicitly instruct the model to count up or down to a number $n \in [0, 300]$, making target length deterministic.
  • Five natural-language benchmarks: Spanning short factual retrieval to long reasoning traces—TriviaQA, GSM8K, MATH, MMLU-Pro, and OpenThoughts-1k.

Key Insights and Ideas

  • Before speaking, the model already has a ballpark length: Total output length is linearly decodable from the prompt's final hidden state across every model and dataset tested.
  • The estimate updates on the fly: Because the per-token probe isn't forced to count down monotonically, it adapts. In most model-dataset pairs, reading mid-generation states beats blindly counting down from the initial prompt estimate.
  • Self-correction triggers a sudden "time extension": When a model catches a mistake and emits a retraction token ("Wait"), its internal estimate of remaining tokens spikes upward—offering a clean, quantitative signature of genuine mid-flight course correction.
Distribution of one-step changes in predicted remaining tokens at "Wait" vs. matched controls
  • Generalization is a one-way street: Probes trained on messy, natural-language reasoning transfer surprisingly well to other datasets (even synthetic counting tasks), whereas probes trained on synthetic counting fail completely on natural language.
  • The representation can steer behavior: Pushing the hidden state along the probe's vector smoothly lengthens or shortens completions without wrecking text quality (measured via negative log-likelihood).

Key Results

  • Prompt-end & per-token accuracy: On natural-language tasks, the Completion Length Probe achieves 0.57 to 0.88 of the constant-median baseline's error. During generation, the Remaining Count Probe beats the baseline in all 20 model-dataset cells, and beats the prompt-only countdown by >1 token in 13 of them.
  • Asymmetric transfer: Pooled across models, natural-language probes beat the target dataset's baseline floor in 29 of 44 off-diagonal transfer tests (and 10 of 18 natural-to-synthetic tests). Synthetic-trained probes succeed in 0 of 22 synthetic-to-natural tests.
  • The "Wait" jump: On Qwen3-4B solving GSM8K, emitting "Wait" causes the predicted remaining length to jump by an average of +72.8 tokens, compared to -0.7 tokens at matched control positions ($p < 10^{-4}$, Cohen's $d = 3.10$).
  • Monotonic steering: Steering Llama-3.1-8B at layer 24 on GSM8K shifts average response lengths monotonically from 155 tokens (negative steering) to 283 tokens (positive steering), compared to 227 tokens unsteered, while keeping cutoff rates $\le 2.1\%$.

Limitations and Future Work

  • Decodable $\neq$ causal in the wild: Steering proves the model can be controlled via this direction, not that the unperturbed model naturally consults it to decide when to stop. Proving natural usage requires activation patching or ablation, along with random-direction steering controls.
  • Token identity confounds: The retraction analysis only examined the word "Wait" in one cell (Qwen3-4B / GSM8K) without controlling for token identity—meaning the probe might just assign a high static weight to the token "Wait" itself rather than reading deeper planning states.
  • Task accuracy & filtering: Steering experiments tracked fluency (log-likelihood), not whether the math answers remained correct. Additionally, training only on naturally terminated sequences filtered out up to 37.5% of long generations on datasets like OpenThoughts-1k. Exploring base models and frontier-scale architectures remains open for future work.

Summary updated

Abstract

Large Language models generate tokens, without explicitly keeping track of the length of the generated text. This paper asks the question: can we estimate the number of tokens remaining in a generated response, using just a linear probe on the model's hidden states? Previous work on inference scheduling established that length is statistically predictable, using nonlinear methods. This paper contributes a linear representation method, using frozen hidden states of 7-8B instruction-tuned models, across seven datasets. We show that total completion length can be estimated, with performance stronger than statistical baselines, and stronger than the fair comparison to the prediction at the last token of the prompt. On the natural-language datasets, the probe's error lies between $0.57$ and $0.88$ of the statistical baseline's. Interestingly, when a retraction token occurs ("Wait''), the probe predicted length jumps upward by over $70$ tokens, on average, compared to the baseline, where it drops by $0.7$, on average. Moreover, the direction found can be used for length steering: adding to the probe direction increases completion length and vice-versa. These results indicate that LLMs have a linearly decodable internal representation of output length.
BibTeX
@inproceedings{merzouk2026how,
  author = {Mohamed Amine Merzouk and Dmitri Carpov and Mirko Bronzi and Damiano Fornasiere and Adam Oberman},
  title = {{How Much is Left? LLMs Linearly Encode Their Remaining Output Length}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=vPQUUDiAuf},
}
Figure