Provedalphabaguetteoptimizerclipping
Global-norm clipping on gradients pre-scaled by 1/N makes the same decision with the same coefficient
For all , and , if , then
What the notation means · or point at any symbol
- NNatural numbers
- The natural numbers 0, 1, 2, …. In Lean they start at 0. (
ℕ) - 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 k. Lean writes f x; papers write f(x). (
Fin k) - ⟹Implies
- If Fin(k), then ℝ. (Between types, A → B is the type of functions from A to B.) (
Fin k → ℝ) - x ∈ TVariables
- N, c range over real numbers: the statement must hold for every choice. (
(N c : ℝ)) - <Less than
- 0 is strictly smaller than N. (
0 < N) - ∧And
- Both hold: √(∑ i, (g(i)/N)^2) ≤ c/N ↔ √(∑ i, g(i)^2) ≤ c, and c/N/√(∑ i, (g(i)/N)^2) = c/√(∑ i, g(i)^2). (
(Real.sqrt (∑ i, (g i / N) ^ 2) ≤ c / N…) - √Square root
- The non-negative number whose square is ∑ i, (g(i)/N)^2. (
Real.sqrt (∑ i, (g i / N) ^ 2)) - ≤At most
- √(∑ i, (g(i)/N)^2) is less than or equal to c/N. (
Real.sqrt (∑ i, (g i / N) ^ 2) ≤ c / N) - ⟺If and only if
- √(∑ i, (g(i)/N)^2) ≤ c/N holds exactly when √(∑ i, g(i)^2) ≤ c holds. (
Real.sqrt (∑ i, (g i / N) ^ 2) ≤ c / N …) - RReal numbers
- The real numbers: every point on the number line. (
ℝ) - ∑Summation
- Add up (g(i)/N)^2 for every i. (
∑ i, (g i / N) ^ 2) - aᵇPower
- g(i)/N raised to the power 2. (
(g i / N) ^ 2) - a/bDivision
- g(i) divided by N. In Lean, dividing by 0 gives 0. (
g i / N) - =Equality
- c/N/√(∑ i, (g(i)/N)^2) and c/√(∑ i, g(i)^2) are the same. (
(c / N) / Real.sqrt (∑ i, (g i / N) ^ 2…)
theorem clip-prescale-invariant {k : ℕ} (g : Fin k → ℝ) (N c : ℝ) (hN : 0 < N) :
(Real.sqrt (∑ i, (g i / N) ^ 2) ≤ c / N ↔ Real.sqrt (∑ i, g i ^ 2) ≤ c) ∧ (c / N) / Real.sqrt (∑ i, (g i / N) ^ 2) = c / Real.sqrt (∑ i, g i ^ 2)To avoid overflow when squaring F32 gradients, Baguette scales every gradient by 1/N (N = parameter count) before the global-norm tree and compares against c/N (baguetteGradientNormScaleWord, baguetteGradientScaledClipLimitWord; Alpha commit e3330947, systems/baguette/src/Baguette/Learner.alpha). The comment claims this preserves "the unscaled L2 clipping decision". Over ℝ, for N > 0: ‖g/N‖ ≤ c/N ⇔ ‖g‖ ≤ c, and the clip coefficient (c/N)/‖g/N‖ = c/‖g‖ (with Lean's x/0 = 0 for a zero gradient).
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
- 18 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.