Manuscript Offprint
arXiv:2609.06685RoPE attention is an exact forward-pass gradient step with softmax intact
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
We derive an exact gradient-step representation of the RoPE-softmax forward pass. For every deterministic RoPE-softmax attention head with arbitrary affine projection weights, we construct a query-dependent effective matrix satisfying , where is the uniform mean of the attended values and is the augmented query input. The construction applies the classical exponential divided difference to retain softmax exactly. Its positive coefficients give a unit gradient-step representation on a query-conditioned quadratic objective. The same function connects the RoPE generator to exact positional finite differences. We derive a tokenwise formula for the error of reusing one query's matrix and prove that a nonconstant finite-cache head cannot admit a globally exact affine query readout. Reconstruction checks and frozen-reuse calibration on one pretrained Qwen2.5-0.5B layer verify the representation and quantify the correction required when one query's matrix is reused.
1 Contribution and relation to existing constructions
We apply the exponential divided difference to express full RoPE-softmax attention in the original projection-weight coordinates, including biases. This yields an exact query-conditioned matrix, its per-token decomposition, and the corresponding quadratic gradient-step representation. A boundedness proposition characterises the obstruction to a globally shared affine readout; a matrix-function identity connects the same construction to positional derivatives and finite differences.
The construction uses the classical function from exponential integrators [1] to factorise the softmax readout. Softmax attention is a Nadaraya-Watson-type normalised kernel average [2, 3]: with , its output is . RoPE enters through the relative rotation inside the exponential.
Von Oswald et al. [4] construct a least-squares gradient step using linear self-attention. Schlag et al. [5] develop the fast-weight view of linear attention, and Dai et al. [6] use a linearised attention expression to obtain an implicit weight update. Here the coefficients retain the exponential and its normalisation for arbitrary projection weights. Modern Hopfield networks give an exact softmax-attention correspondence [7]; the object derived here is a query-conditioned effective matrix in input coordinates, together with its score-shift family and exact reuse residual.
2.1 RoPE, affine projections, and the attended bank
Let be a column input, with query/key width and value width . Use row-vector projections
where , , and biases are rows. For standard RoPE with fixed frequencies [8], set and
The rotated rows are and . Augment the query input and projection by
Then the raw score is exactly . In the bias-free case this is . Let be a finite nonempty set of permitted keys; causal masking selects this set. For deterministic attention, define
Here is the uniform arithmetic mean of the permitted values.
2.2 The exponential divided difference
The entire function
is the first divided difference of the exponential at 0 and s, with its continuous value at coincident arguments. It is the standard of exponential integration [1]; for real s and .
Theorem 1 (Exact effective-weight representation). For the head in (1)–(4), define
The last equality holds exactly for every query and all finite projection weights and inputs.
Proof. The centred values sum to zero. Therefore
In particular, without projection biases the effective matrix in the original weights is
At a fixed bank and query position, write and . Then , where . The cache supplies the outer-product directions; the query selects their positive coefficients. This gives in this representation.
Corollary 2 (A query-conditioned unit gradient step). For each fixed query, define and
Proof. With the query, features, centred values, and coefficients held fixed, ; evaluation at gives the result.
A unit step from zero on gives the effective matrix and its exact readout . Every coefficient is computed directly from the query and its attended bank through (6). As all scores approach zero, ; the first-order readout is . This is the centred outer-product form underlying linear-attention gradient constructions. The corresponding regression step is specified by the feature/label encoding, projection choices, and step scale of von Oswald et al. [4].
3 The same function links RoPE derivatives and finite differences
For fixed content , let be a rotated column feature. The generator in (2) gives
The matrix extension of (5) is defined by the convergent power series . Consequently
The power-series definition also covers zero-frequency blocks. These identities expose RoPE as a bank of position-response operators on frozen features: gives the infinitesimal response and gives the exact finite-difference quotient. The same entire function converts the scalar softmax increment into and the matrix rotary increment into . In (7), rotary position structure enters through and its scores, while retains their full exponential response. The derivatives in (9) are with respect to position at fixed content.
4 Residual coordinates, gauge, and exact reuse error
4.1 Residual write and score-shift family
In the bias-free case, if the head input is also the residual input and , then
For a pre-normalised head, use and the exact residual ; projected head writes are summed for multi-head attention. Equation (6) is a secant representation of the readout. At a fixed bank and position, its differential is ; the second term contains the query derivatives of the coefficients.
Effective matrices depend on a score-shift convention. For any fixed , put . Softmax is unchanged by subtracting from every attended score. Applying Theorem 1 to the shifted features gives
Key shifts give the subfamily , of dimension at most at a fixed position. We call (6) the original-score gauge; all matrix-transfer results below use this gauge. The displayed transformations give a family of exact matrices for the same output map.
4.2 Global affine representability
Proposition 3 (Boundedness obstruction to a global affine readout). Fix a finite nonempty key/value bank and query position, and let be its softmax head output as the query coordinate ranges over all of . If is nonconstant, no fixed and satisfy for every .
Proof. Every output is a convex combination of the fixed values, so for all . If , choose with ; then as . Hence , which makes constant, a contradiction.
Matrix transfer on a finite query set is quantified by the following exact residual.
4.3 The exact term omitted by freezing
Fix the bank and query position so that and are shared, and select an anchor query . Define . Then
Thus , and is the exact projected correction. Each summand resolves this correction by cached token. In bias-free coordinates, freezing anchor 0 omits exactly , with
The fixed-position condition makes the features shared; changing the position also changes , and changing the bank can change both features and mean.
5 Pretrained reconstruction and frozen-reuse calibration
5.1 Protocol and reconstruction precision
We evaluate Qwen2.5-0.5B [9], layer 23 (zero-indexed), on article prefixes of 511 tokens, all 14 query heads, and alternative one-token continuations at position 511. Continuation 0 is the observed next token; the other 31 are the model's highest-ranked distinct nonspecial alternatives. Each continuation reads the same prefix bank. Projection biases and the model's pre-normalised head inputs are included. Reconstruction is checked both for the prefix-only readout and for the full causal readout including the continuation's own key/value.
For the latter, if the self token receives mass , the exact relation is . The full-bank version of (6) uses its own scores and uniform mean. The 240 reconstruction rows comprise 224 individual head/context pairs and 16 combined projected writes. All pass the reported checks. Combined prefix and full reconstruction MSEs in float64 are approximately and . Against the native FP32 combined write, the MSE is and the maximum absolute difference is . The float64 figures measure agreement between algebraically equivalent evaluations; the native comparison measures agreement at the model's execution precision.
5.2 Frozen reuse as calibration of the omitted term
The calibration evaluates the residual in (13) on alternative queries from one position. Let be the exact combined projected prefix write and let denote a predictor formed using anchor . Define
where . All-anchor evaluation uses and . Squared errors are pooled with equal context weights, with ratios taken after pooling. The combined write sums projected heads before its error is measured.
In addition to constant-anchor and frozen-matrix predictors, the per-head controls are
The second is the first-order softmax expansion at zero logits. Every control undergoes the same output projection and aggregation as its corresponding exact head.
Table 1: Frozen-reuse calibration: pooled MSE of the combined projected prefix write. Anchor 0 is the observed next token. All anchors averages the 32 possible anchors within each of the 16 contexts. Matrices use the original-score gauge.
| Predictor | Anchor 0 | All anchors |
|---|---|---|
| Constant anchor output | 0.047787 | 0.045672 |
| Cache mean () | 0.124573 | 0.124513 |
| Frozen anchor matrix | 0.324970 | 0.356763 |
| Linearised softmax | 0.161842 | 0.162068 |
The target RMS is 0.670545 for anchor 0 and 0.670824 across all anchors. Frozen rRMSE against the constant-anchor output is 2.608 for anchor 0 and 2.795 across all anchors. The anchor-0 RMSE ratio against the cache mean is 1.615. At the individual-head level, the all-anchor rRMSE is 0.728–0.933 for 13 of the 14 heads, and 8.516 for head 5. Each per-head ratio uses that head’s constant-anchor output as its baseline.
The frozen-matrix row measures the MSE of the omitted correction in (13). Adding that tokenwise correction to the reused matrix’s readout recovers the exact attention output for each query.
Code and archive. GitHub repository: https://github.com/leochlon/secant/tree/main.
Zenodo record: https://zenodo.org/records/22543637.
References
[1] Marlis Hochbruck and Alexander Ostermann. Exponential integrators. Acta Numerica, 19:209–286, 2010. doi: 10.1017/S0962492910000048.
[2] E. A. Nadaraya. On estimating regression. Theory of Probability and Its Applications, 9(1):141–142, 1964. doi: 10.1137/1109020.
[3] Geoffrey S. Watson. Smooth regression analysis. Sankhya: The Indian Journal of Statistics, Series A, 26(4): 359–372, 1964. URL https://www.jstor.org/stable/25049340.
[4] Johannes von Oswald, Eyvind Niklasson, Ettore Randazzo, Joao Sacramento, Alexander Mordvintsev, Andrey Zhmoginov, and Max Vladymyrov. Transformers learn in-context by gradient descent. In Proceedings of the 40th International Conference on Machine Learning, volume 202 of Proceedings of Machine Learning Research, pages 35151–35174. PMLR, 2023. URL https://proceedings.mlr.press/v202/von-oswald23a.html.
[5] Imanol Schlag, Kazuki Irie, and Jürgen Schmidhuber. Linear transformers are secretly fast weight programmers. In Proceedings of the 38th International Conference on Machine Learning, volume 139 of Proceedings of Machine Learning Research, pages 9355–9366. PMLR, 2021. URL https://proceedings.mlr.press/v139/schlag21a.html.
[6] Damai Dai, Yutao Sun, Li Dong, Yaru Hao, Shuming Ma, Zhifang Sui, and Furu Wei. Why can GPT learn in-context? language models secretly perform gradient descent as meta-optimizers. In Findings of the Association for Computational Linguistics: ACL 2023, pages 4005–4019. Association for Computational Linguistics, 2023. doi: 10.18653/v1/2023.findings-acl.247. URL https://aclanthology.org/2023.findings-acl.247/.
[7] Hubert Ramsauer, Bernhard Schäfl, Johannes Lehner, Philipp Seidl, Michael Widrich, Thomas Adler, Lukas Gruber, Markus Holzleitner, Milena Pavlović, Geir Kjetil Sandve, Victor Greiff, David Kreil, Michael Kopp, Günter Klambauer, Johannes Brandstetter, and Sepp Hochreiter. Hopfield networks is all you need. In International Conference on Learning Representations, 2021. URL https://arxiv.org/abs/2008.02217.
[8] Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen, and Yunfeng Liu. RoFormer: Enhanced transformer with rotary position embedding, 2021. URL https://arxiv.org/abs/2104.09864. arXiv:2104.09864.
[9] Qwen Team. Qwen2.5-0.5B: Model card, 2024. URL https://huggingface.co/Qwen/Qwen2.5-0.5B.