Provedunbiased-attentiongradientone-passtraining
One-pass attention gradient: from N ≥ 2 exact samples, (1/N)Σ U_i K_i − (1/(N(N−1)))Σ_{i≠j} U_i K_j is unbiased for Cov(U, K)
For all , and , if and (given ), then
What the notation means · or point at any symbol
- Type
- Type: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (
Type) - Fintype
- Fintype: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (
Fintype) - f(x)Function application
- Fintype applied to Ω. Lean writes f x; papers write f(x). (
Fintype Ω) - NNatural numbers
- The natural numbers 0, 1, 2, …. In Lean they start at 0. (
ℕ) - ⟹Implies
- If Ω, then ℝ. (Between types, A → B is the type of functions from A to B.) (
Ω → ℝ) - x : TVariables
- w, U, K range over Ω → ℝ: the statement must hold for every choice. (
(w U K : Ω → ℝ)) - ∑Summation
- Add up w(ω) for every ω. (
∑ ω, w ω) - =Equality
- ∑ ω, w(ω) and 1 are the same. (
∑ ω, w ω = 1) - ≤At most
- 2 is less than or equal to N. (
2 ≤ N) - RReal numbers
- The real numbers: every point on the number line. (
ℝ) - Fin
- Fin: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (
Fin) - ∏Product
- Multiply together w(f(m)) for every m. (
∏ m, w (f m)) - a/bDivision
- 1 divided by N. In Lean, dividing by 0 gives 0. (
1 / (N : ℝ)) - (x : T)As real numbers
- N read as an element of real numbers. Mathematicians leave this implicit; Lean needs it to know which kind of number is meant. (
(N : ℝ)) - ·Multiplication
- U(f(i)) times K(f(i)). (
U (f i) * K (f i)) - -Subtraction
- N minus 1. On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (
N - 1) - erase
- Finset.univ.erase: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (
Finset.univ.erase)
theorem op-one-pass-gradient-unbiased {Ω : Type} [Fintype Ω] {N : ℕ} (w U K : Ω → ℝ) (hsum : ∑ ω, w ω = 1) (hN : 2 ≤ N) :
∑ f : Fin N → Ω, (∏ m, w (f m)) * ((1 / (N : ℝ)) * ∑ i, U (f i) * K (f i) - (1 / ((N : ℝ) * (N - 1))) * ∑ i, ∑ j ∈ Finset.univ.erase i, U (f i) * K (f j)) = ∑ ω, w ω * (U ω * K ω) - (∑ ω, w ω * U ω) * (∑ ω, w ω * K ω)The query-gradient coordinate is the covariance Cov_π(u, k). Given N exact samples from the attention row (exact rejection from a snapshot or an INT8 proposal, qc-/tp-), the U-statistic above is exactly unbiased, so the backward pass reuses the forward samples and needs no new key reads. The unbiased sample covariance is textbook (Bessel/U-statistics, credited); what is new is its role in the training step: backward attention at zero extra KV traffic under exact sampling. Part of 'Unbiased randomized attention', gradient round.
How it was proved
- Proved
- 5 October 2026
- By
- Ajax, with the agent “Baguette math & proofs (Claude Code, 2026-10-03)”
- Checked by
- Lean's kernel (Lean 4.33.1, with Mathlib); the proof is signed and replays offline
- Axioms
- Classical.choice, Quot.sound, propext
- Proof
- 84 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.