Prefix Sliding for efficient test-time scaling

Niklas Muennighoff, Zhengyang Wang, Zeyi Chen, Weijia Shi, Binyuan Hui, John Yang, Dapeng Jiang, Mika Senghaas, Fares Obeid, Johannes Hagemann, Sami Jaghouar, Ludwig Schmidt, Percy Liang, Jason Wei, Andrew Y. Ng, Luke Zettlemoyer, Yejin Choi, Mike Lewis

TL;DR

Large language models perform significantly better when given extra compute time to "think" through complex problems, but keeping massive reasoning chains in memory becomes prohibitively expensive. Prefix Sliding solves this bottleneck by discarding intermediate reasoning tokens while preserving crucial system instructions and the most recent context window. This simple architectural tweak caps memory costs to a constant rate, speeds up inference by up to 3x out-of-the-box, and unlocks reinforcement learning on reasoning traces over 100,000 tokens long.

What Problem Does This Paper Address?

Test-time scaling—allowing LLMs to generate long, sequential chains of thought before delivering a final answer—has driven massive performance leaps in complex reasoning tasks. However, standard models rely on full attention, meaning every newly generated token must attend to every single previous token in the sequence.

As a result, the computational and memory cost grows heavily as the reasoning trace lengthens. This linear-to-quadratic scaling makes long-horizon thinking incredibly expensive. Furthermore, massive context windows introduce secondary issues: models get distracted by old, irrelevant reasoning steps, suffer from context poisoning, or fall into repetitive loops. The authors target this fundamental memory and speed bottleneck to make long-horizon test-time scaling practical and efficient.

Methods

The authors introduce Prefix Sliding, a context-eviction mechanism that retains only two distinct parts of the key-value (KV) cache during generation:

  1. The Prefix: The system instructions, available tools, and the initial problem prompt.
  2. The Sliding Window: A fixed-size cache of the most recent tokens (e.g., the last 4,096 tokens) representing the model's current active train of thought.

As the model generates new tokens, the sliding window advances, and older intermediate reasoning tokens are permanently evicted from memory.

To deploy this without retraining existing models, the authors utilize Continue PE, a method that reuses cached key-value representations with position embeddings already applied, avoiding the need to recompute embeddings when tokens shift context. For training scenarios (such as Reinforcement Learning), they introduce Truncated Backpropagation and Chunked Backpropagation to calculate accurate gradients within the sliding window's receptive field without triggering out-of-memory errors. They also implement custom CUDA kernels for the Nvidia Hopper architecture to optimize the attention mechanism via intra-tile masking and inter-tile skipping.

Datasets

  • Evaluation Benchmarks: The method was tested across several rigorous reasoning and domain-specific datasets: GPQA Diamond (PhD-level science questions), MATH500 (high-school level mathematics), AIME25 (American Invitational Mathematics Examination), LiveCodeBench (coding problems), and HealthBench (medical QA).
  • Training Dataset: For reinforcement learning experiments, the authors curated a custom math dataset from public sources including SkyWork and s1 (which aggregates data from NuminaMATH, OlympicArena, OmniMath, and others). They filtered the problems based on guessability (removing items solved easily without reasoning), verifiability (ensuring answers can be objectively checked), and difficulty.

Key Insights and Ideas

  • Intermediate Tokens Quickly Lose Importance: By analyzing attention maps during full-attention reasoning, the authors discovered that once a sub-problem or mathematical step is completed, the model rarely looks back at how it solved it. It only cares about the final result of that step.
  • The Prefix Acts as an Attention Sink: System prompts and initial instructions consistently receive high attention throughout the entire generation. They serve as "attention sinks" where the model dumps excess probability weight and stores vital tool definitions needed much later.
Figure 2: The first and last few tokens receive most attention during reasoning with full attention. We plot post-softmax attention probabilities averaged across layers and attention heads in Qwen3-1.7B for an AIME25 reasoning trace. Probabilities are Gaussian smoothed.
  • Constant Cost in the Limit: By freezing the prefix and sliding window sizes, the computational cost of generating a new token becomes entirely constant. It costs the same to generate the 10,000th token as it does the 1,000th token.

Key Results

  • 3x Speedup Out-of-the-Box: Without any additional training, applying Prefix Sliding to a standard Qwen3 model yielded up to a 3x speedup in token generation while matching or exceeding full-attention accuracy on major math and science benchmarks.
Figure 1: Prefix Sliding without any training is more efficient than full attention. Prefix Sliding performs better as it can generate more tokens in the same thinking time than full attention, not because each token it generates is better. Both use the same Qwen3 model (section 3). Here, Prefix Sliding uses a window size of 4096; see Appendix B for other sizes, and Appendix C for the results in tabular form.
  • Outperforms Compression Alternatives: In direct comparisons, Prefix Sliding beat alternative methods like "Last $k$" (which suffers from volatile memory usage and duplicate token processing) and explicit "Summary" techniques (which introduce slow, extra generation steps).
  • Unlocks Ultra-Long RL Rollouts: When training models via reinforcement learning, Prefix Sliding successfully scaled to reasoning traces exceeding 100,000 tokens within reasonable memory budgets, leading to higher overall rewards.

Limitations and Future Work

  • Information Loss in Long-Form Tasks: On coding benchmarks like LiveCodeBench, performance dropped when the window size was too small. The model would frequently write a function stub, generate thousands of tokens of comments/reasoning, and evict the original code from its sliding window before it finished implementing the function.
  • No Benefit for Short Generations: For simpler tasks that require fewer tokens than the sliding window size (e.g., HealthBench), the model remains in a "warm-up phase" where it behaves identically to full attention, offering no speed advantages.
  • Agentic and Multi-Turn Vulnerabilities: In agentic workflows where a model reads massive external files or web pages, the incoming text can completely flood the sliding window, causing the model to lose track of the original user instructions. The authors suggest that future work should focus on teaching models to read content step-by-step or implementing automatic context guardrails.

Summary updated

BibTeX
@inproceedings{muennighoff2026prefix,
  author = {Niklas Muennighoff and Zhengyang Wang and Zeyi Chen and Weijia Shi and Binyuan Hui and John Yang and Dapeng Jiang and Mika Senghaas and Fares Obeid and Johannes Hagemann and Sami Jaghouar and Ludwig Schmidt and Percy Liang and Jason Wei and Andrew Y. Ng and Luke Zettlemoyer and Yejin Choi and Mike Lewis},
  title = {{Prefix Sliding for efficient test-time scaling}},
  booktitle = {Efficient Reasoning @ COLM},
  year = {2026},
  url = {https://openreview.net/forum?id=l5BRLIFY3o},
}
Figure