proofs
Provedalphabaguettermsnormbackward

Alpha's RMSNorm input pullback r·(v − z·mean(v⊙z)) is the exact derivative of v·RMSNorm_ε

For all n∈N\htmlData{mx=1}{n \in \htmlData{mx=0}{\mathbb{N}}}, ε∈R\htmlData{mx=1}{\varepsilon \in \htmlData{mx=0}{\mathbb{R}}} and x,h,v:Fin⁡ n→R\htmlData{mx=5}{x, h, v : \htmlData{mx=2}{\htmlData{mx=0}{\operatorname{Fin}}\,\htmlData{mx=1}{n}} \mathrel{\htmlData{mx=4}{\to}} \htmlData{mx=3}{\mathbb{R}}}, if 0<n0 \mathrel{\htmlData{mx=1}{<}} \htmlData{mx=0}{n} and 0<ε0 \mathrel{\htmlData{mx=1}{<}} \htmlData{mx=0}{\varepsilon}, then

HasDerivAt⁡ t↦∑iv(i)⋅(x(i)+t⋅h(i)∑j(x(j)+t⋅h(j))2n+ε) ∑kh(k)⋅(1∑jx(j)2n+ε⋅(v(k)−x(k)∑jx(j)2n+ε⋅(∑iv(i)⋅(x(i)∑jx(j)2n+ε)n))) 0\htmlData{mx=91}{\htmlData{mx=0}{\operatorname{HasDerivAt}}\,\htmlData{mx=33}{t \mapsto \htmlData{mx=31}{\sum_{i} \htmlData{mx=30}{\htmlData{mx=3}{\htmlData{mx=1}{v}(\htmlData{mx=2}{i})} \cdot \left(\htmlData{mx=29}{\frac{\htmlData{mx=12}{\htmlData{mx=6}{\htmlData{mx=4}{x}(\htmlData{mx=5}{i})} + \htmlData{mx=11}{\htmlData{mx=7}{t} \cdot \htmlData{mx=10}{\htmlData{mx=8}{h}(\htmlData{mx=9}{i})}}}}{\htmlData{mx=28}{\sqrt{\htmlData{mx=27}{\htmlData{mx=25}{\frac{\htmlData{mx=23}{\sum_{j} \htmlData{mx=22}{(\htmlData{mx=21}{\htmlData{mx=15}{\htmlData{mx=13}{x}(\htmlData{mx=14}{j})} + \htmlData{mx=20}{\htmlData{mx=16}{t} \cdot \htmlData{mx=19}{\htmlData{mx=17}{h}(\htmlData{mx=18}{j})}}})^{2}}}}{\htmlData{mx=24}{n}}} + \htmlData{mx=26}{\varepsilon}}}}}}\right)}}}\,\htmlData{mx=90}{\sum_{k} \htmlData{mx=89}{\htmlData{mx=36}{\htmlData{mx=34}{h}(\htmlData{mx=35}{k})} \cdot \left(\htmlData{mx=88}{\htmlData{mx=47}{\frac{1}{\htmlData{mx=46}{\sqrt{\htmlData{mx=45}{\htmlData{mx=43}{\frac{\htmlData{mx=41}{\sum_{j} \htmlData{mx=40}{\htmlData{mx=39}{\htmlData{mx=37}{x}(\htmlData{mx=38}{j})}^{2}}}}{\htmlData{mx=42}{n}}} + \htmlData{mx=44}{\varepsilon}}}}}} \cdot \left(\htmlData{mx=87}{\htmlData{mx=50}{\htmlData{mx=48}{v}(\htmlData{mx=49}{k})} - \htmlData{mx=86}{\htmlData{mx=64}{\frac{\htmlData{mx=53}{\htmlData{mx=51}{x}(\htmlData{mx=52}{k})}}{\htmlData{mx=63}{\sqrt{\htmlData{mx=62}{\htmlData{mx=60}{\frac{\htmlData{mx=58}{\sum_{j} \htmlData{mx=57}{\htmlData{mx=56}{\htmlData{mx=54}{x}(\htmlData{mx=55}{j})}^{2}}}}{\htmlData{mx=59}{n}}} + \htmlData{mx=61}{\varepsilon}}}}}} \cdot \left(\htmlData{mx=85}{\frac{\htmlData{mx=83}{\sum_{i} \htmlData{mx=82}{\htmlData{mx=67}{\htmlData{mx=65}{v}(\htmlData{mx=66}{i})} \cdot \left(\htmlData{mx=81}{\frac{\htmlData{mx=70}{\htmlData{mx=68}{x}(\htmlData{mx=69}{i})}}{\htmlData{mx=80}{\sqrt{\htmlData{mx=79}{\htmlData{mx=77}{\frac{\htmlData{mx=75}{\sum_{j} \htmlData{mx=74}{\htmlData{mx=73}{\htmlData{mx=71}{x}(\htmlData{mx=72}{j})}^{2}}}}{\htmlData{mx=76}{n}}} + \htmlData{mx=78}{\varepsilon}}}}}}\right)}}}{\htmlData{mx=84}{n}}}\right)}}\right)}\right)}}\,0}
What the notation means · or point at any symbol
NNatural numbers
The natural numbers 0, 1, 2, …. In Lean they start at 0. (ℕ)
<Less than
0 is strictly smaller than n. (0 < 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)
f(x)Function application
Fin applied to n. Lean writes f x; papers write f(x). (Fin n)
⟹Implies
If Fin(n), then ℝ. (Between types, A → B is the type of functions from A to B.) (Fin n → ℝ)
x : TVariables
x, h, v range over Fin n → ℝ: the statement must hold for every choice. ((x h v : Fin n → ℝ))
HasDerivAt
HasDerivAt: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (HasDerivAt)
x ↦ f(x)Function (λ-abstraction)
The function sending t to ∑ i, v(i) · ((x(i) + t · h(i))/√((∑ j, (x(j) + t · h(j))^2…. Lean writes fun x => …; papers write x ↦ …. (fun t : ℝ => ∑ i, v i * ((x i + t * h i…)
+Addition
x(i) plus t · h(i). (x i + t * h i)
·Multiplication
t times h(i). (t * h i)
√Square root
The non-negative number whose square is (∑ j, (x(j) + t · h(j))^2)/n + ε. (Real.sqrt ((∑ j, (x j + t * h j) ^ 2) /…)
a/bDivision
∑ j, (x(j) + t · h(j))^2 divided by n. In Lean, dividing by 0 gives 0. ((∑ j, (x j + t * h j) ^ 2) / n)
∑Summation
Add up (x(j) + t · h(j))^2 for every j. (∑ j, (x j + t * h j) ^ 2)
aᵇPower
x(j) + t · h(j) raised to the power 2. ((x j + t * h j) ^ 2)
-Subtraction
v(k) minus x(k)/√((∑ j, x(j)^2)/n + ε) · ((∑ i, v(i) · (x(i)/√((∑ j, …. On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (v k - x k / Real.sqrt ((∑ j, x j ^ 2) /…)

Component.MeanSquareNormalization.propagateMeanSquareInputWith computes, for z = r·x, r = (Σx²/n + ε)^(-1/2) and v = dy ⊙ gain, the input cotangent dx = r·(v − z·mean(v⊙z)). Its comment says this is "the real analytic VJP". This theorem proves it over ℝ: along any direction h, the derivative at 0 of t ↦ ⟨v, RMSNorm_ε(x + t·h)⟩ equals ⟨h, dx⟩. ε stays in r, as the source requires; an ε-free shortcut would change the derivative.

How it was proved

Proved
3 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
66 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.

More proved statements