A Context-Length Ceiling for Quantized Attention

Long-context language models must find a few relevant tokens among millions of irrelevant ones. Recent theory shows that this is possible only if the gap between the score of the relevant token and the scores of the distractors grows like the logarithm of the context length. The usual way to get that gap is to multiply attention scores by a factor proportional to $\log n$. At the same time, million-token inference is only affordable when the stored keys and values (the "KV cache") are compressed to 2–4 bits. Rounding the keys adds noise to every attention score, and that noise grows with the scores themselves. A radio designer would recognize this situation immediately. In a radio, distortion from imperfect hardware grows in proportion to transmit power, so turning up the power can never push signal quality past a fixed ceiling.

This note proposes that quantized attention has the same kind of ceiling, and that the ceiling sits on context length. Turning up the attention temperature plays the role of turning up transmit power. Under rounding noise it stops helping once the context exceeds roughly $\exp(\Delta^2/2\sigma^2)$, where $\Delta$ is the clean score gap and $\sigma$ is the spread of the score noise caused by quantization. The proposal is to derive this ceiling, measure $\Delta$ and $\sigma$ directly inside real models, and test whether the predicted breakdown length matches where long-context retrieval actually fails. A useful consequence follows if the law holds: the bits needed to support context length $n$ grow only like $\tfrac12\log_2\log n$. That would say how cheap long context can be made, and it would also identify the regime where it cannot.

Core Claim

The logarithmic-gap argument works as follows. A target with score $a$ competing against $n$ distractors with score $b$ keeps a non-vanishing share of attention only if $a-b$ grows like $\log n$ (Rachit Bansal et al., Arthur S. Bianchessi). Critical attention scaling in long-context transformers proves that multiplying scores by $\beta_n=\gamma\log n$ produces a sharp phase transition. Below a critical $\gamma$, token representations collapse to a single point. At the critical scaling, attention stays sparse and gradients stay stable.

That analysis assumes exact arithmetic. Now let each distractor score be $b+\epsilon_i$, where $\epsilon_i$ is rounding noise in the query–key dot product with spread $\sigma$, and let $\Delta=a-b$. After multiplying all scores by $\beta$, the softmax denominator behaves like $n\,e^{\beta b+\beta^2\sigma^2/2}$, by the same averaging used in the Random Energy Model analysis of Two failure modes of deep transformers and how to avoid them. The target therefore keeps a non-vanishing attention weight only when

$$\beta\Delta \;\ge\; \log n + \tfrac12\beta^2\sigma^2 .$$

The left side grows linearly in $\beta$, while the noise penalty grows quadratically. Maximizing over $\beta$ gives the best temperature $\beta^\star=\Delta/\sigma^2$. It also gives a ceiling that no choice of temperature can exceed:

$$n^\star = \exp\!\left(\frac{\Delta^2}{2\sigma^2}\right).$$

The "frozen" large-$\beta$ regime of the Random Energy Model, in which the largest noisy distractor dominates, yields the same condition $\Delta\ge\sigma\sqrt{2\log n}$.

The quantity $\Delta^2/\sigma^2$ is a score-level signal-to-distortion ratio. The hardware analogy carries real content at this step. Per-channel quantizers set their step size from the range of the keys, so the noise spread $\sigma$ scales with key magnitude. Learning larger query and key norms, which is how a trained model implements logarithmic scaling, then raises $\Delta$ and $\sigma$ together and leaves $n^\star$ unchanged. This is the attention version of $\lim_{P\to\infty}\mathrm{SNDR}=1/\kappa$ in A New Look at Dual-Hop Relaying, where $P$ is transmit power and $\kappa$ measures hardware quality.

Each extra bit roughly halves $\sigma$, which multiplies $\log n^\star$ by four. The theory therefore predicts a sharp cliff. A cache precision that supports $10^4$ tokens at one bit-width should support effectively unlimited context at one more bit.

The model makes three further, more specific predictions, all testable:

  1. Non-monotone temperature. With quantization noise, retrieval accuracy as a function of $\gamma$ should peak and then fall. In the exact-arithmetic theory it only saturates.
  2. Only per-token noise matters. The part of $\epsilon_i$ shared across all tokens cancels inside the softmax. Only the token-to-token variation of the score error counts. This mirrors the finding in Massive MIMO Systems with Non-Ideal Hardware that distortion common to all base-station antennas averages out, while distortion on the single user path does not.
  3. The query sets the relevant error. The relevant $\sigma^2$ is the key-error covariance seen through the query, $q^\top\Sigma_e q$, and not the raw mean-squared quantization error. This is the "colored noise" lesson of MIMO Transmission with Residual Transmit-RF Impairments.

Research Program

The first stage is theory. It extends the inequality above beyond Gaussian noise. Uniform rounding error summed over $d$ channels is approximately Gaussian in the bulk, but its tails are bounded. Because $n^\star$ is controlled by extreme values, bounded tails should push the ceiling outward. Heavy-tailed or gapped error should pull it in. Heavy-tailed error arises from outlier channels, and gapped error resembles the transfer-function gaps that The Impact of SAR-ADC Mismatch on Quantized Massive MU-MIMO Systems analyzes with Bussgang's decomposition. Bussgang's decomposition writes a nonlinear quantizer as a linear gain plus uncorrelated distortion.

The theory stage borrows two tools from the radio literature: that decomposition, and the paper's habit of designing to a low quantile of effective resolution rather than its mean. The theory stage resolves a tension in the file. Chen et al. reject Gaussian score models and derive $\log n$ scaling, while Giorlandino and Goldt use Gaussian disorder and derive $\sqrt{\log T}$ scaling. In our setting the clean geometry supplies $\Delta$ and the hardware supplies the Gaussian-like $\sigma$, and the two combine in the expression for $n^\star$.

The second stage is measurement. In a pretrained long-context model, we identify the heads that perform retrieval on passkey tasks. In those heads we record the clean score gap $\Delta$ between the needle token and the distractors. We also record the per-token component of the score error under each quantizer: uniform INT2–4, and KVQuant-style per-channel, pre-RoPE, non-uniform, dense-and-sparse quantization (RoPE is the rotary position encoding applied to keys). From these quantities we compute a predicted $n^\star$ per head and per quantizer before running any long-context evaluation.

The third stage tests one design consequence. If prediction 2 holds, the quantizer should spend its error budget on the per-token component as seen through typical queries. Concretely, this means removing the shared per-channel key mean before quantization and allocating precision by query-weighted error. We treat this as a check on the theory, not as the main contribution.

Baselines

The naive reference point is uniform low-bit KV quantization with the model's default attention temperature. The file reports that uniform 3-bit methods push LLaMA-7B perplexity from about 5.6 to over 10 (KVQuant). Our theory should predict that this collapse appears as early retrieval failure at short lengths.

The strongest existing method is KVQuant itself, which reports under 0.1 perplexity degradation at 3 bits on LLaMA-7B on Wikitext-2 and C4. However, the file contains no reported passkey accuracy for it at long lengths: no reported result found on Lacuna for KVQuant's passkey accuracy as a function of length. We run it with the same model, the same calibration data and the same bit budget as every other arm. The proposal "beats" KVQuant only in a specific sense. It must predict KVQuant's retrieval breakdown length to within a factor of two in $\log n$. Under an equal bit budget, the query-weighted, mean-removed variant must also extend that breakdown length. Matching perplexity is not enough.

The second competitor is the logarithmic-scaling recipe from Critical attention scaling in long-context transformers and the related dynamic logit-scaling methods (Peter Cholak et al., Yelin Chen et al., Muquan Yu et al.). These methods multiply scores by a length-dependent factor and are designed for exact arithmetic. We sweep $\gamma$ over the same grid, at the same lengths, for every quantizer. Our claim is beaten if some $\gamma$ restores retrieval beyond the predicted $n^\star$.

As a structural reference, retrieval-based attention (DRT with grouped cross-attention) reports near-perfect passkey accuracy at 16M tokens after training at 16K. We include it with quantized landmark scores, because retrieval shrinks the effective number of distractors, and the law should account for that.

Finally, an ablation isolates the key ingredient. We compare predicting breakdown from raw quantization mean-squared error against predicting it from the query-weighted, per-token score noise $\sigma$. If raw error predicts equally well, the hardware-floor framing adds nothing.

Why not just…?

Why not just use more bits, since KVQuant already loses almost nothing at 3 bits? This is the most serious threat. The predicted cliff means that one extra bit may move $n^\star$ far beyond any practical length. Perplexity is, however, dominated by nearby tokens, so the reported <0.1 degradation says little about retrieval at depth. The experiments settle the question directly by measuring breakdown length at 2, 3 and 4 bits. If even 2-bit KVQuant retrieves perfectly at a million tokens, we will report that the ceiling is practically irrelevant for digital caches. The theory then still gives the rule "bits needed $\approx \tfrac12\log_2\log n$". It would also redirect the work toward noisier analog or in-memory attention hardware, where $\sigma$ is set by physics rather than by bit count.

Why not just retune the attention temperature for the quantized model? The derivation says that tuning helps only up to $\beta^\star=\Delta/\sigma^2$, and that overshooting hurts. That is the transmit-power plateau of Björnson et al. in attention form. The $\gamma$ sweep tests this directly. A monotone accuracy curve in $\gamma$, or retrieval succeeding beyond $n^\star$, would refute the claim.

Why not just switch to retrieval or recurrent memory and avoid dense attention? Retrieval lowers the effective $n$, so it lives inside the same law rather than escaping it. Off-the-shelf retrieval also does poorly on reasoning: BABILong reports about 60% on single-fact tasks and failure on multi-hop. Recurrent memory, meanwhile, hits its own capacity limits (Stuffed Mamba). We include the retrieval-based DRT arm to check whether its quantized landmark scores obey $n^\star$ computed with chunk count in place of token count.

Proposed Experiments

The synthetic stage reuses two setups. The first is the sparse-token classification setup of Barnfield, Cui and Lu, in which attention needs only $\log L$ signal strength in exact arithmetic. The second is the simplex geometry of Chen et al. In both, we inject quantized keys at controlled bit-widths and noise tails (Gaussian, bounded uniform, and SAR-style gapped). We then check that measured failure lengths follow $\exp(\Delta^2/2\sigma^2)$ and that accuracy is non-monotone in $\gamma$.

We next train small models on TinyStories and PG19 with $\beta_n=\gamma\log n$, following the trainability setup in Giorlandino and Goldt, and evaluate them with quantized caches at lengths well beyond training.

The main test uses a pretrained long-context model of the size evaluated in KVQuant. We run passkey retrieval and needle-in-a-haystack across depths and lengths up to the largest length our memory allows. We add BABILong single- and multi-hop tasks; its reference point is that GPT-4 effectively uses only about 10% of its 128K window. We also run LongBench-E length splits as a check that general long-context performance follows the same ordering.

The decisive checks are as follows:

  1. Prediction. Breakdown lengths predicted from measured head statistics, before any long-context run, must match observed breakdowns across quantizers and bit-widths.
  2. Bit cliff. Raising precision by one bit should multiply $\log n^\star$ by roughly four.
  3. Shared noise is harmless. Adding error that is shared across tokens should leave retrieval unchanged, while adding the same amount of per-token error should degrade it.

Failure of the first check would mean that real attention is not limited by score noise in the way the radio analogy suggests. That negative result would still be worth reporting.