Skip to content
AI.info

Papers

Long-Context Generation Is a Sampling Problem (When You Turn Up the Heat)

Top-nsigma sampling preserves long agentic and reasoning generations at high temperature where top-p and top-k collapse, giving engineers a concrete replacement for a default inference setting.

The paper’s first page · arXiv:2611.22148
arXiv
2611.22148 · accepted · NEURIPS
Published
2026-11-17
Authors
Allen G. Roush, Minh Nhat Nguyen, Ravid Shwartz-Ziv, Judah Goldfeder, Sanjay Basu

In plain words

Open-weight language models are widely observed to get worse the longer they generate, and the usual remedy is more training or long-output fine-tuning. This paper argues for a cheaper fix that inference engines already expose: the sampler, i.e. the rule that picks the next token from the model's probability distribution.

Key results

  • Above temperature 1 the rules split sharply. Over all benchmarks, top-nσ keeps a median 100 percent of its temperature-1 score where top-p keeps 26 percent.
  • The pool size is the mechanism. In one Llama-3.1-8B story, going from temperature 1 to 2 grows top-p's pool from 4 tokens to 51,845 while top-nσ stays at 3.

AI summary

Overview

Research area: Inference-time decoding and sampling for large language models, with a focus on long-context, long-form and agentic generation.

Technical level: Intermediate. Readers should know roughly what a softmax, temperature and truncation samplers (top-p, top-k) do, but no advanced mathematics is required.

Scope: A large empirical study (29 open-weight models, 1B to 122B parameters, ten established benchmarks plus needle retrieval to one million tokens) arguing that long-context degradation at high temperature is primarily caused by how many tokens a sampler admits, not by a lack of training.

What This Paper Is About

Open-weight language models are widely observed to get worse the longer they generate, and the usual remedy is more training or long-output fine-tuning. This paper argues for a cheaper fix that inference engines already expose: the sampler, i.e. the rule that picks the next token from the model's probability distribution. The authors show that when temperature is raised, samplers whose candidate set (the pool of tokens a rule keeps at each step) grows large and lets in low-probability tokens collapse on long and agentic tasks, while samplers that keep that pool small and stable lose little or nothing.

Key Contributions

  1. A systematic sampler comparison at long context. The authors test 29 instruction-tuned open-weight models across Llama, Qwen, Mistral, Gemma, OLMo, Nemotron, GLM and gpt-oss families on ten established benchmarks plus multi-key needle retrieval in PG-19 text from 8K to one million tokens, all through a single vLLM logits processor that logs the candidate-set size at every decoding step.

  2. The candidate-set-size explanation. They show that the median number of tokens a sampler admits per step grows dramatically with temperature for most rules (top-p from 2 to roughly 90,000 in one ten-model measurement) but is invariant for top-nσ and top-k by construction, and that this pool size predicts judged quality with a Spearman correlation of −0.77 across 133 sampler-setting-by-temperature cells.

  3. Agentic coding evidence at temperature 2. On SWE-bench Verified with the mini-swe-agent harness, agents using top-p, top-k or Top-H resolve 0 of 100 issues at temperature 2, while top-nσ agents resolve 46 to 62 percent on three Qwen3.5 models, winning every issue on which the samplers disagree.

  4. A causal test by reordering temperature and truncation. Picking the candidate set at temperature 1 and only applying temperature afterwards rescues Top-H, min-p and P-less, which keep their temperature-1 quality up to temperature 3 (4.1–4.6) where the default order has them at 1.1–1.2.

Main Findings

  • At temperature 1 the sampler barely matters. Across the ten-model core set, truncation rules open at 4.8–5.2 out of 10 on forced 16K-token generation and drift to about 2.5, and coding agents resolve 46–56 percent in the long-horizon setting with no statistically significant paired differences.

  • Above temperature 1 the rules split sharply. Over all benchmarks, top-nσ keeps a median 100 percent of its temperature-1 score where top-p keeps 26 percent.

  • Coding agents fail at the level of command format. At temperature 1.5, top-k agents average 15 malformed actions per episode and top-p agents 6.6, against 0.08 for top-nσ; at temperature 2 the tail-admitting agents are terminated after 3–9 steps, while tight rules submit a patch in 92–100 percent of episodes.

  • The win–loss records are lopsided. In the long-horizon setting (Qwen3.5-9B, 500 steps, 262K context, 50 issues) at temperature 1.5, min-p gets 48 percent (24–0 against top-p), P-less 58 percent (29–0) and top-nσ 52 percent (26–0), while top-p gets 0 percent.

  • The effect replicates out of sample. On 100 fresh SWE-bench Verified issues with no overlap, top-nσ resolves 46, 62 and 53 percent on Qwen3.5-9B, 27B and 35B-A3B while top-p and Top-H resolve none, for records of 46–0, 62–0 and 53–0. An independent rerun of the long-horizon grid gives top-nσ 56 percent at temperature 1.5 and 60 percent at 2, against 2 and 0 percent for top-p.

  • The pool size is the mechanism. In one Llama-3.1-8B story, going from temperature 1 to 2 grows top-p's pool from 4 tokens to 51,845 while top-nσ stays at 3. Median tokens kept per step from temperature 1 to 2: top-p 0.9 from 2 to about 90,000, Top-H 0.4 from 1 to 54, P-less from 1 to 21, min-p 0.1 from 1 to 14, top-nσ 1 stays at 1.

  • Long-form writing degrades in the same order. On Arena-Write, the share of healthy generations at temperature 2 is 0.93 for top-nσ, 0.74 for P-less, 0.69 for min-p, and only 0.10, 0.15 and 0.01 for Top-H, top-k and top-p; top-p scores 2.2 on WritingBench against 6.9 for top-nσ.

  • Rule-based and exact-match benchmarks agree. On LongProc at temperature 1.5, P-less and top-nσ keep the 31 and 29 percent they had at temperature 1 while top-p falls to 13 percent and loses 532–73 and 469–74 on disputed items. On LongBench v2, P-less and top-nσ hold 39.8 and 38.3 percent while top-p drops from 36.6 to 25.6 percent.

  • Retrieval degrades with context length. At one million tokens and temperature 1.5, top-nσ, P-less and min-p retrieve 75, 78 and 73 percent of the 16 needles, top-p 59 percent and pure sampling 48 percent. Under greedy decoding the entropy of the first answer token goes from 0.02 nats at 8K to 0.37 at one million tokens.

  • Long chain-of-thought reasoning holds up under tight rules. At temperature 1.3, top-nσ matches its temperature-1 accuracy on AIME and HMMT 2025–26 with six models (40.2 vs 39.6 percent) and on AIME plus MATH-500 level 5 with four models (57.9 vs 58.2 percent), while top-p 0.95 falls to 27.4 and 39.2 percent.

  • Hyperparameter tuning only moves the cliff. In a sweep of 22 settings over seven temperatures from 0.7 to 3.0 on eight models, top-nσ with n of 1 or less scores 4.2–4.7 throughout, every top-p setting is below 1.5 by temperature 1.6, and nothing stays usable above roughly 100 tokens admitted per step.

  • The sampler does not cure looping. Forced to 16K tokens at temperature 1, top-p, min-p, Top-H, P-less and top-nσ end in a terminal loop 95–100 percent of the time; no cell in the whole sweep is healthy more than 31 percent of the time. What the sampler controls is how a forced long generation responds to temperature.

  • An escape floor has mixed effects. Adding a floor that always keeps the top two tokens to top-nσ at temperature 2 nearly eliminates terminal loops (75 percent down to 2 percent) and keeps judged quality at 3.3, but it hurts coding agents, dropping top-nσ to 42 and 22 percent as format errors per episode rise from 0.04 to 1.4 at temperature 1.5.

  • Input context length is not the trigger. Continuing PG-19 novels from depths of 2K, 16K and 64K (and 128K on three models), the quality gap between tail-excluding and tail-admitting rules stays within 0.4 points at temperature 1 or below and sits at 1.2–1.6 points at 1.3 and 1.6 with no trend.

  • One model family is an exception. Gemma-4-31B shows no separation between rules at temperature 1.5 (49–55 percent for every rule, all p > 0.3), which the authors attribute to its soft-capped final logits without isolating the cap experimentally.

Methodology in Plain English

The authors take models whose weights are publicly released and swap out the normal token-picking step for a single custom component that implements six truncation rules side by side: top-k, top-p, min-p, top-nσ, Top-H and P-less, plus pure (untruncated) sampling. Crucially, this component records how many tokens each rule keeps at every step, so the abstract "candidate set" becomes a measurable number.

They then push temperature up on tasks that require long outputs. For coding, they run a real software-engineering agent against GitHub issues and only count an issue as resolved if the submitted patch passes the repository's tests, so no language model judge is involved. For writing and structured output they use benchmark scoring plus an LLM judge (gpt-oss-120b) that rates 1.5K-token windows on a 1–10 coherence scale; a generation counts as healthy only if it has no terminal loop (defined as at least 80 percent of remaining windows repeating 32-grams at least half the time) and every judged window scores at least 6. For reading they hide 16 key–value pairs in PG-19 novels and ask for each value.

The key experimental move is a controlled comparison: each sampler's score at high temperature is divided by that same sampler's score at temperature 1 on the same models and items, so the only thing varying is how the rule reacts to heat. They also run a causal intervention: compute the candidate set at temperature 1 and only then apply temperature inside it, which prevents the set from growing.

Why This Matters

Impact on research. The paper reframes long-context degradation as an inference-time sampling artifact rather than a training deficiency, and it offers a measurement (realized candidate-set size per step) that predicts quality across rules without knowing which rule produced it. It also shows that benchmarks run only at temperature 1 hide most of these differences, which has implications for how sampler comparisons and agent evaluations are reported.

Real-world applications:

  • Running coding agents at higher temperature to escape repetitive or stuck trajectories without the agent emitting unparsable shell commands.
  • Long-form drafting (fiction, reports, 2,000-word-plus prompts) where higher temperature is used to avoid loops but currently produces word salad under common defaults.
  • Long-context retrieval pipelines where the model must reproduce exact values from very long documents, and extra uncertainty at one million tokens gets turned into wrong digits.
  • Structured-output generation such as converting HTML pages into TSV tables or writing multi-step plans, where a single stray token breaks the format.

Industry relevance. The fix requires no retraining: top-nσ is already available in llama.cpp, and the paper notes that HuggingFace, vLLM and SGLang apply temperature before truncation while llama.cpp defaults to the opposite order. The authors' practical recommendation is to report the realized candidate-set size per step alongside the full sampler configuration and its ordering, since the same model at the same temperature goes from 62 percent of issues resolved to 0 percent on the sampler alone.

Future Directions

  • Isolate why Gemma-4 behaves differently. The authors suspect soft-capped final logits keep the distribution peaked under temperature, but state they did not isolate the cap experimentally; confirming this would sharpen the account of what makes a distribution vulnerable.
  • Close the gap between "no loops" and "good text." Top-nσ plus a top-2 escape floor nearly eliminates terminal loops at temperature 2 but still leaves judged quality at 3.3, and the authors attribute this to a low quality ceiling at 16K tokens under every sampler; whether training, not sampling, is required to raise that ceiling remains open.
  • Design an escape mechanism that does not break exact formats. The top-2 floor rescues fiction but pushes coding-agent resolve rates down to 42 and 22 percent by admitting a second token at every step; a mechanism that admits an escape token only when needed is an obvious next step.
  • Re-examine evaluation practice. Given that temperature-1-only benchmarks hide the sampler differences and that the same model and temperature can yield 62 percent or 0 percent depending on the rule, the paper's call for reporting realized candidate-set sizes and sampler ordering invites a broader audit of published agent and long-context results.

Target Audience

Practitioners deploying open-weight models for agents, long-form writing or long-context retrieval, who will find directly actionable sampler guidance; inference-engine and serving-stack developers who control the order of temperature and truncation; and evaluation researchers who need to know why reporting only a nominal temperature and top-p value is insufficient. Readers interested in decoding theory will also find the candidate-set-size framing useful, though the paper is empirical rather than theoretical.

Authors’ abstract

Open-weight language models are widely observed to get worse the longer they generate. Often, attempts to fix this involve more training. At high temperature, The sampler, i.e. the rule that picks the next token out of the model's probabilities, decides whether long and agentic generation survives and/or thrives. We test 29 open-weight models from 1B to 122B parameters on ten established benchmarks plus needle retrieval out to one million tokens, covering SWE-bench Verified…

The full abstract on arXiv
Read the original paper

Related papers