ClockRoPE: Random Fourier RotationsResearch Paper
Motivation
Transformer sequence models modulate attention scores by a function of the relative position between a query and a key: the attention logit between token and token is scaled by a fixed profile . Realizing this modulation the naive way means evaluating once per pair and materializing an adjustment over the whole sequence — quadratic in the sequence length . Rotary Position Embedding (RoPE) Su et al. 2021 avoids this entirely: it rotates the query at position and the key at position independently, each by an angle depending only on its own position, so that the pairwise quantity falls out of the dot product of the two separately rotated vectors — is never evaluated pairwise, and no matrix is ever built. This is what lets RoPE stay a linear, per-token preprocessing step compatible with efficient (sub-quadratic) attention implementations, rather than an modulation. The catch is that RoPE's specific log-linear frequency schedule bakes in one particular profile: a monotone, decaying . That schedule is a poor fit whenever the correlation structure of the data is not monotonically decaying with distance — the leading example being periodicity: in sequential recommendation, interactions separated by exactly one day or one week are more correlated than interactions separated by, say, half a day, and a decaying profile cannot express that "attention comes back" at the period.
Chen, Ainslie, Choromanski et al., ClockRoPE: Random Fourier Rotations for Temporal Routine Modeling (arXiv:2607.26369), ask a more general question first: which attention-modulation profiles can be realized at all by this same per-token, pairwise-iteration-free rotation trick — rotate each token once, on its own, and let the pairwise profile emerge from the dot product — and by what rotation-frequency schedule? Their answer is a random-features construction — sample the rotation frequencies from the kernel's own Fourier transform, rather than fixing them log-linearly — that realizes any continuous, normalized, positive-definite profile in expectation, with a quantified concentration rate, all while keeping the exact same per-token rotate-then-dot-product computation RoPE already uses. ClockRoPE is the periodic instance of this general theory, later deployed in a production-scale generative-retrieval system.
Setting
Fix an embedding dimension and group a vector into consecutive feature pairs for . For an angle , let
be the (Givens) rotation matrix. A real kernel is positive definite if for every finite family of points and complex coefficients , has nonnegative real part; it is normalized if . When is also continuous and Lebesgue-integrable, its Fourier transform
is (by Bochner's theorem) a genuine probability density on : this is the distribution the mission's rotation frequencies are sampled from.
Given a query at position , a key at position , and i.i.d. frequencies , the Random Fourier Rotation (RFR) estimator is
is exactly the modulated attention logit computed by rotating query/key feature pairs with per-pair, sampled RoPE frequencies — the same operation standard RoPE performs, but with drawn from instead of fixed by a log-linear schedule.
Formalization targets
Goal — convergence of the RFR estimator (Proposition 3.2)
for every . This is the mission's central target: it upgrades the mean identity below into a quantitative, non-asymptotic guarantee that the sampled estimator is close to the target profile with high probability, at a rate that is exponential in the embedding dimension .
Milestone — unbiasedness of the RFR estimator (Proposition 3.1)
The expectation identity that the concentration bound above sharpens; it is the feasibility half of the claim ("this construction is correct on average") that the convergence half needs as its starting point.
Milestone — periodic case via Herglotz's theorem (Corollary 3.3)
For a continuous, positive-definite, -periodic with and Fourier coefficients ,
The periodic specialization needed to apply the goal and first milestone with a discrete frequency distribution over harmonics — the regime ClockRoPE actually deploys, since daily/weekly routines are periodic rather than merely decaying.
Significance
The result gives a general recipe — sample, don't hand-design — for turning any admissible attention-modulation profile into a RoPE-compatible rotation schedule, with a concentration guarantee that says how many feature pairs are needed before the sampled schedule reliably approximates the target profile. Crucially, the recipe changes only which frequencies the per-token rotation uses — it never touches the computational shape of RoPE itself: each query and key is still rotated once, independently, by an angle depending only on its own position, and the target pairwise profile is still recovered purely from the dot product of the two rotated vectors. So realizing an arbitrary positive-definite this way costs exactly what realizing RoPE's own log-linear profile costs — linear in the sequence length, with no pairwise evaluation of and no matrix ever materialized — rather than the quadratic cost a direct, per-pair implementation of an arbitrary modulation function would require. This subsumes standard RoPE's log-linear schedule as one instance and explains, via the periodic corollary, why a schedule built from the kernel's own spectrum (rather than an arbitrary log-linear one) is the right way to encode periodicity: nothing about the construction, or its efficiency, is specific to decay. The paper reports this translated into measured gains in a production-scale generative-retrieval system, which is unusual weight of practical evidence behind a Bochner/Herglotz-style spectral argument.
At the time of writing, none of these three results have a machine-checked proof; this mission asks for the first formalization of all three, together with the shared scaffolding (feature-pair extraction, the rotation estimator, and the notion of a positive-definite kernel) they are stated over.
Difficulty
The natural first attempt at the concentration bound is a direct union bound or a naive variance argument, but the estimator is a sum of terms that are each bounded (each rotated pair lies on a fixed-radius circle) rather than governed by a variance bound that shrinks with under a fixed frequency; the source proof instead applies McDiarmid's bounded-differences inequality, treating each sampled frequency as one coordinate of the input and bounding the one-coordinate change in by via the maximal distance between two points on the unit circle — not by directly bounding a variance term. Establishing Proposition 3.1 itself already requires care: it requires justifying that , defined purely as an integral transform of , is in fact a legitimate probability density (Bochner's theorem), and then a real/complex bookkeeping argument identifying the real inner product of rotated pairs with the real part of a product of complex exponentials.
Formalization scope
The mission works over the reals and represents feature pairs as functions
Fin (2 * n) → ℝ sliced into Fin n-indexed pairs, matching the " feature pairs,
dimension " convention used throughout; rotations are ordinary
Matrix (Fin 2) (Fin 2) ℝ values built with Matrix.mulVec/Matrix.dotProduct, and
expectation over i.i.d. -distributed frequencies is formalized as integration
against the product measure MeasureTheory.Measure.pi of n independent copies of
the measure with density (MeasureTheory.Measure.withDensity) — this is
mathematically equivalent to, and more directly usable in Lean than, introducing an
abstract probability space with named i.i.d. random variables.
Since a general continuous positive-definite kernel need not have an
integrable Fourier transform (the periodic case in Corollary 3.3 is exactly the
counterexample: its "Fourier transform" is a discrete measure, not a density) — the
goal and first milestone add Integrable f as an explicit hypothesis beyond what the
paper states in prose, so that is genuinely a density rather than a junk value.
This is not a strengthening of the target profiles the paper cares about in practice
(Gaussian, Laplace, and the cosine/Gaussian priors used by ClockRoPE itself are all
integrable) and mirrors the paper's own split between the density case (Propositions
3.1–3.2) and the discrete, purely-periodic case (Corollary 3.3). A formalization that
dropped this hypothesis and instead let the Fourier integral silently evaluate to
Lean's junk value (0 for non-integrable integrands) would make the goal statement
possible to "prove" vacuously and must be avoided.
Definitions needed: a positive-definite-kernel predicate, the real-valued Fourier transform of a kernel, feature-pair extraction, the rotation matrix, and the RFR estimator itself — all reusable by any future mission formalizing RoPE-family positional encodings (e.g. STRING, nD-RoPE) or other random-Fourier-feature results. McDiarmid's inequality, if not already in Mathlib in the needed form, is itself a independently reusable contribution.
Selected references
- Yiwen Chen, Joshua Ainslie, Krzysztof Choromanski, Xiang Gao, Su-Lin Wu, Yiping Yuan, Qian Sun, ClockRoPE: Random Fourier Rotations for Temporal Routine Modeling, 2026. arXiv:2607.26369
- Jianlin Su, Yu Lu, Shengfeng Pan, Ahmed Murtadha, Bo Wen, Yunfeng Liu, RoFormer: Enhanced Transformer with Rotary Position Embedding, arXiv, 2021. arXiv:2104.09864
- Ali Rahimi, Benjamin Recht, Random Features for Large-Scale Kernel Machines, NeurIPS, 2007.
- Salomon Bochner, Monotone Funktionen, Stieltjessche Integrale und harmonische Analyse, Springer, 1933.
- Gustav Herglotz, Über Potenzreihen mit positivem, reellem Teil im Einheitskreis, Berichte über die Verhandlungen der Königlich Sächsischen Gesellschaft der Wissenschaften zu Leipzig, 1911.