- The paper introduces a deterministic gap-counting framework to unify disparate inverse-temperature scaling laws in self-attention.
- It details empirical validation using models like Qwen-7B-Chat and nanoGPT to identify optimal scaling exponents and softmax regimes.
- The study provides actionable diagnostics by relating attention score gap statistics to model stability and performance on long-context tasks.
A Unified Framework for Critical Scaling of Inverse Temperature in Self-Attention
Introduction and Motivation
Inverse-temperature rescaling of attention logits—essential for ensuring numerical stability and preventing capacity loss in long-context transformers—has been guided by disparate theoretical prescriptions, ranging from βn∝(logn)1/2, as motivated by Gaussian logit analyses, to βn∝logn and even βn∝(logn)2, as found in certain engineered context-extrapolating systems. The selection of the precise functional form for βn has thus far lacked a unifying, data-driven principle capable of reconciling the conflicting scaling laws and accommodating arbitrary attention score statistics.
This work introduces a deterministic, gap-counting theory for attention logits, viewing the scaling problem through the lens of the cumulative gap-counting function Nn(t), which measures the number of scores within t of the row-wise maximum. The exponential rate at which Nn(t) grows with t—the upper-tail accumulation scale Λn—determines the critical inverse-temperature separating softmax regimes: above this threshold, attention entropy collapses, while below it, dominant competitors are insufficiently separated.
Empirical Analysis: Inverse-Temperature Scaling Is Not Universal
Contrary to several widespread implementations and prior theoretical arguments, the log-context scaling ξβ=1 (i.e., βn∝logn0) is not empirically optimal across all settings. Experiments on Qwen-7B-Chat at extrapolated context lengths (with dynamic-NTK RoPE) and on GPT-124M trained with a learnable βn∝logn1 vector reveal significant variability in the optimal exponent βn∝logn2. Inference-time perplexity on PG-19 and Proof-Pile-2 identifies optima around βn∝logn3, notably higher than the classic logarithmic law. Conversely, fits to learned temperature vectors in nanoGPT models yield βn∝logn4, below the standard log scaling.



Figure 1: Perplexity on PG-19 as a function of the log-scaling exponent βn∝logn5, demonstrating that βn∝logn6 achieves lower perplexity at long context extrapolation.
These findings support the key claim: critical scaling of inverse temperature is governed by score-row statistics—not by context length alone. The demand for a data-driven calibration principle for βn∝logn7 leads directly to the gap-counting perspective.
Theoretical Framework: Gap-Counting and the Upper-Tail Accumulation Scale
A central object of the theory is the cumulative gap-counting function βn∝logn8, which encodes, for every βn∝logn9, the number of positions βn∝(logn)20 where the gap between the row-max score and βn∝(logn)21 does not exceed βn∝(logn)22. This function's large-βn∝(logn)23 expansion is dominated by the exponential envelope βn∝(logn)24, where the smallest such rate βn∝(logn)25 is defined as the upper-tail accumulation scale.
Figure 2: Illustration of βn∝(logn)26 and the exponential envelope βn∝(logn)27 for a two-level block-constant gram matrix. The tangent point (contact point) determines βn∝(logn)28 and the critical scaling.
A sequence βn∝(logn)29 is then:
- Subcritical if βn0: softmax does not sufficiently separate high competitors.
- Supercritical if βn1: entropy collapses, softmax becomes overly concentrated.
βn2 thus serves as the critical scale separating these regimes.
The contact formula relates βn3 to the gap-counting curve's geometry:
βn4
where βn5 is the (largest) contact gap at which βn6 achieves the exponential envelope, and βn7 quantifies the "mass" of competitors at this gap.
Logarithmic Scaling Exponents and Coordinate Decomposition
Scaling laws for βn8 can be characterized as:
βn9
The theory shows that any non-degenerate scaling yielding both non-collapsed softmax and non-trivial entropy must match these exponents: Nn(t)0.
A crucial result establishes a coordinate decomposition:
Nn(t)1
revealing that the observed scaling exponent depends on the growth rate of both competitor counts near the maximum and the typical gaps.



Figure 3: Qwen and nanoGPT cells mapped onto the Nn(t)2 plane relative to the Nn(t)3 boundary; operational regime (sublogarithmic vs. superlogarithmic scaling) is determined by the sign of Nn(t)4.
Empirical attention score statistics from trained transformers validate this decomposition, with the empirically optimally tuned Nn(t)5 closely matching the gap-counting prediction Nn(t)6 across all tested datasets and models.
The gap-counting abstraction encompasses classical attention configurations and structured extensions. In the equicorrelated ("simplex") case, Nn(t)7 jumps sharply at a unique gap, recapitulating Nn(t)8 (Nn(t)9). In hierarchical block-constant matrices, this framework interpolates between t0 and other exponents via block size and gap parameters, offering a unified lens on disparate theoretical models and their scaling phenomenology.
Empirical Validation: Critical Exponent Recovery from Attention Scores
Gap-counting diagnostics applied to both inference-time (Qwen-7B-Chat at t1) and training-time (nanoGPT with learned t2) settings demonstrate that the critical scaling exponent t3 is recoverable from the attention scores alone. The slope of t4 versus t5 (i.e., t6) aligns with optimization-sourced exponents t7 to within grid or measurement error.
Figure 4: Loss landscape for the bias-free post-hoc least-squares fit of the learned temperature vector t8 as a function of scaling exponent t9, demonstrating optimal fit at sublogarithmic scaling in the nanoGPT regime.
Calibration via Nn(t)0 demystifies why prior heuristics (Gaussian, equicorrelated, doubled-rescaling/YaRN) yield differing scaling exponents: these are not universal laws, but are driven by dataset/model-specific score gap statistics.
Figure 5: Two equivalent renderings of Nn(t)1. (Right) Gap-counting curve and exponential envelope; (Left) sorted competitor gaps and their log-jump form.
Implications and Future Directions
This framework has both immediate practical and theoretical consequences. Practically, it prescribes a direct diagnostic: sample attention scores at representative context lengths, obtain Nn(t)2, and fit Nn(t)3 to determine the critical Nn(t)4 scaling for model stability and optimal performance on long contexts. This unification obviates blind adherence to canonical scaling heuristics, which may be suboptimal or unstable, especially on extrapolation workloads.
Theoretically, the work raises the question of endogenizing the gap-counting statistics: can Nn(t)5 be predicted from training dynamics, architecture, positional encoding, or input distribution? A promising direction is to combine recent inference-time and training-time analyses of attention geometry—such as models of token clustering and low-dimensional structure, or those tracing hierarchical structure formation in embeddings—into the present gap-counting paradigm. Doing so would allow predictive control of critical rescaling schedules as a function of model depth, loop time, or data domain.
Conclusion
This study provides a gap-counting-based deterministic framework that unifies and extends prior scaling rules for self-attention inverse-temperature calibration. The critical scaling exponent can be directly diagnosed from empirical gap statistics in attention scores, and is neither universal nor solely a function of context length. This advances both principled model calibration and theoretical understanding of softmax regimes in long-context transformers, setting the stage for adaptive, data-driven scaling rules responsive to actual attention map statistics, and opening avenues for further integration with representation learning dynamics.