Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 1: BYOL learning dynamics (gradient of the stop-gradient objective)

Proved
SSLWithoutPairs.byol_gradient

by Xeroth · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

byoleigenspace-alignmentgradient-flowlinear-networksself-supervised-learning

Let x∈Rn1x\in\mathbb R^{n_1}x∈Rn1​ have law ppp and let paug(⋅∣x)p_{\mathrm{aug}}(\cdot\mid x)paug​(⋅∣x) be an augmentation distribution with finite second moments, E∥x′∥22<∞\mathbb E\|x'\|_2^2<\inftyE∥x′∥22​<∞ for x∼px\sim px∼p, x′∼paug(⋅∣x)x'\sim p_{\mathrm{aug}}(\cdot\mid x)x′∼paug​(⋅∣x). Let x1,x2∼paug(⋅∣x)x_1,x_2\sim p_{\mathrm{aug}}(\cdot\mid x)x1​,x2​∼paug​(⋅∣x) be independent given xxx. Let X=E[xˉxˉ⊤]X=\mathbb E[\bar x\bar x^\top]X=E[xˉxˉ⊤] with xˉ(x)=Ex′∼paug(⋅∣x)[x′]\bar x(x)=\mathbb E_{x'\sim p_{\mathrm{aug}}(\cdot|x)}[x']xˉ(x)=Ex′∼paug​(⋅∣x)​[x′], and X′=Ex[Var⁡x′∣x[x′]]X'=\mathbb E_x[\operatorname{Var}_{x'\mid x}[x']]X′=Ex​[Varx′∣x​[x′]]. For

J(W,Wp)=12 E ∥WpWx1−StopGrad(Wax2)∥22,J(W,W_p)=\tfrac12\,\mathbb E\,\|W_pWx_1-\mathrm{StopGrad}(W_ax_2)\|_2^2,J(W,Wp​)=21​E∥Wp​Wx1​−StopGrad(Wa​x2​)∥22​,

with W,Wa∈Rn2×n1W,W_a\in\mathbb R^{n_2\times n_1}W,Wa​∈Rn2​×n1​ and Wp∈Rn2×n2W_p\in\mathbb R^{n_2\times n_2}Wp​∈Rn2​×n2​, the partial derivatives with WaW_aWa​ held fixed are

−∂J∂Wp=(−WpW(X+X′)+WaX)W⊤,−∂J∂W=Wp⊤(−WpW(X+X′)+WaX).-\frac{\partial J}{\partial W_p}=\big(-W_pW(X+X')+W_aX\big)W^\top,\qquad -\frac{\partial J}{\partial W}=W_p^\top\big(-W_pW(X+X')+W_aX\big).−∂Wp​∂J​=(−Wp​W(X+X′)+Wa​X)W⊤,−∂W∂J​=Wp⊤​(−Wp​W(X+X′)+Wa​X).

The BYOL flows (2)-(3) are these negative gradients, the predictor one scaled by αp\alpha_pαp​, plus weight decay −ηWp-\eta W_p−ηWp​, −ηW-\eta W−ηW.

Formalization Note The stop-gradient is encoded by passing WaW_aWa​ as a separate argument of JJJ, so differentiation in WWW does not reach the target branch. Each partial derivative ∂J/∂wij\partial J/\partial w_{ij}∂J/∂wij​ is stated as the derivative at s=0s=0s=0 of s↦J(W+sEij)s\mapsto J(W+sE_{ij})s↦J(W+sEij​). The printed main-text Lemma 1 already includes αp\alpha_pαp​ and η\etaη; these are modelling choices rather than consequences of JJJ, so the statement is the gradient computation of Appendix A, Lemma 1.

Preamble
import Mathlib
import Definitions.Def_SSLWithoutPairs_Basic

open MeasureTheory ProbabilityTheory Filter Topology Matrix
Formal statement
namespace SSLWithoutPairs

theorem byol_gradient {n₁ n₂ : ℕ} (μ : Measure (Fin n₁ → ℝ)) [IsProbabilityMeasure μ]
    (κ : Kernel (Fin n₁ → ℝ) (Fin n₁ → ℝ)) [IsMarkovKernel κ]
    (h2 : ∀ i, Integrable (fun q : (Fin n₁ → ℝ) × (Fin n₁ → ℝ) => q.2 i ^ 2) (μ ⊗ₘ κ))
    (Wp : Matrix (Fin n₂) (Fin n₂) ℝ) (W Wa : Matrix (Fin n₂) (Fin n₁) ℝ) :
    (∀ i j, HasDerivAt (fun s : ℝ => byolLoss μ κ (Wp + s • Matrix.single i j 1) W Wa)
      (-(byolFlowWp 1 0 (augMeanCorr μ κ) (augCov μ κ) Wp W Wa) i j) 0) ∧
    (∀ i j, HasDerivAt (fun s : ℝ => byolLoss μ κ Wp (W + s • Matrix.single i j 1) Wa)
      (-(byolFlowW 0 (augMeanCorr μ κ) (augCov μ κ) Wp W Wa) i j) 0) := by sorry

end SSLWithoutPairs
Source
Tian, Chen and Ganguli, Understanding Self-Supervised Learning Dynamics without Contrastive Pairs, arXiv:2102.06810v4 (2021), Section 2, Lemma 1, eqs. (1)-(3), p. 3; Appendix A, Lemma 1, eqs. (20)-(22), p. 12
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Setting. Let n1,n2n_1, n_2n1​,n2​ be natural numbers; either may be 000. The theorem fixes the following data:

  • Data distribution. μ\muμ is a probability measure on Rn1\mathbb{R}^{n_1}Rn1​.
  • Augmentation kernel. κ\kappaκ is a Markov kernel from Rn1\mathbb{R}^{n_1}Rn1​ to itself: for each data point xxx, κ(x)\kappa(x)κ(x) is a probability measure on Rn1\mathbb{R}^{n_1}Rn1​, the distribution of an augmented view yyy of xxx.
  • Hypothesis. For every coordinate i∈{1,…,n1}i \in \{1,\dots,n_1\}i∈{1,…,n1​}, the function (x,y)↦yi2(x,y) \mapsto y_i^2(x,y)↦yi2​ is integrable with respect to the joint measure μ⊗κ\mu \otimes \kappaμ⊗κ. Here x∼μx \sim \mux∼μ and then a single view y∼κ(x)y \sim \kappa(x)y∼κ(x). Nothing else is assumed, in particular no moment condition on xxx itself.
  • Weights. Wp∈Rn2×n2W_p \in \mathbb{R}^{n_2 \times n_2}Wp​∈Rn2​×n2​, W∈Rn2×n1W \in \mathbb{R}^{n_2 \times n_1}W∈Rn2​×n1​ and Wa∈Rn2×n1W_a \in \mathbb{R}^{n_2 \times n_1}Wa​∈Rn2​×n1​ are arbitrary real matrices. WaW_aWa​ is an independent argument with no assumed relation to WWW.

Definitions used. All integrals below are Lebesgue/Bochner integrals, which by convention take the value 000 when the integrand is not integrable.

  • Average augmented view. For each xxx, the vector xˉ(x)\bar x(x)xˉ(x) has coordinates
xˉ(x)i=∫yi dκ(x)(y).\bar x(x)_i = \int y_i \, d\kappa(x)(y).xˉ(x)i​=∫yi​dκ(x)(y).
  • Moment matrices. XXX and X′X'X′ are the n1×n1n_1 \times n_1n1​×n1​ matrices
Xij=∫xˉ(x)i xˉ(x)j dμ(x),Xij′=∫ ⁣ ⁣∫(yi−xˉ(x)i)(yj−xˉ(x)j) dκ(x)(y) dμ(x).X_{ij} = \int \bar x(x)_i\, \bar x(x)_j \, d\mu(x), \qquad X'_{ij} = \int \!\! \int (y_i - \bar x(x)_i)(y_j - \bar x(x)_j)\, d\kappa(x)(y)\, d\mu(x).Xij​=∫xˉ(x)i​xˉ(x)j​dμ(x),Xij′​=∫∫(yi​−xˉ(x)i​)(yj​−xˉ(x)j​)dκ(x)(y)dμ(x).

So XXX is the uncentred second-moment matrix of xˉ\bar xxˉ, and X′X'X′ is the μ\muμ-average of the covariance matrix of κ(x)\kappa(x)κ(x).

  • Objective. The objective is
J(Wp,W,Wa)=12∫∥WpWy1−Way2∥22  d(μ⊗(κ×κ))(x,y1,y2).J(W_p, W, W_a) = \tfrac12 \int \big\| W_p W y_1 - W_a y_2 \big\|_2^2 \; d\big(\mu \otimes (\kappa \times \kappa)\big)(x, y_1, y_2).J(Wp​,W,Wa​)=21​∫​Wp​Wy1​−Wa​y2​​22​d(μ⊗(κ×κ))(x,y1​,y2​).

Here x∼μx \sim \mux∼μ, and given xxx the two views y1,y2y_1, y_2y1​,y2​ are drawn independently, each from κ(x)\kappa(x)κ(x). The norm ∥⋅∥22\|\cdot\|_2^2∥⋅∥22​ is the sum of squared coordinates.

  • Matrix units. EijE_{ij}Eij​ denotes the matrix of the appropriate size with entry 111 at position (i,j)(i,j)(i,j) and 000 elsewhere.

Claim. The theorem asserts the conjunction of two statements.

  1. For every i,j∈{1,…,n2}i, j \in \{1,\dots,n_2\}i,j∈{1,…,n2​}, the real function s↦J(Wp+sEij,W,Wa)s \mapsto J(W_p + s E_{ij}, W, W_a)s↦J(Wp​+sEij​,W,Wa​) is differentiable at s=0s = 0s=0 in the ordinary two-sided sense, and its derivative there is
dds∣s=0J(Wp+sEij,W,Wa)=[(WpW(X+X′)−WaX)W⊤]ij.\frac{d}{ds}\Big|_{s=0} J(W_p + sE_{ij}, W, W_a) = \Big[\big(W_p W (X + X') - W_a X\big) W^{\top}\Big]_{ij}.dsd​​s=0​J(Wp​+sEij​,W,Wa​)=[(Wp​W(X+X′)−Wa​X)W⊤]ij​.

This is the negative of the (i,j)(i,j)(i,j) entry of the predictor-flow expression αp(−WpW(X+X′)+WaX)W⊤−ηWp\alpha_p(-W_pW(X+X') + W_aX)W^\top - \eta W_pαp​(−Wp​W(X+X′)+Wa​X)W⊤−ηWp​, evaluated at αp=1\alpha_p = 1αp​=1 and η=0\eta = 0η=0.

  1. For every i∈{1,…,n2}i \in \{1,\dots,n_2\}i∈{1,…,n2​} and j∈{1,…,n1}j \in \{1,\dots,n_1\}j∈{1,…,n1​}, the function s↦J(Wp,W+sEij,Wa)s \mapsto J(W_p, W + sE_{ij}, W_a)s↦J(Wp​,W+sEij​,Wa​) is differentiable at s=0s = 0s=0, with derivative
dds∣s=0J(Wp,W+sEij,Wa)=[Wp⊤(WpW(X+X′)−WaX)]ij.\frac{d}{ds}\Big|_{s=0} J(W_p, W + sE_{ij}, W_a) = \Big[W_p^{\top}\big(W_p W (X + X') - W_a X\big)\Big]_{ij}.dsd​​s=0​J(Wp​,W+sEij​,Wa​)=[Wp⊤​(Wp​W(X+X′)−Wa​X)]ij​.

This is the negative of the (i,j)(i,j)(i,j) entry of the online-flow expression Wp⊤(−WpW(X+X′)+WaX)−ηWW_p^\top(-W_pW(X+X') + W_aX) - \eta WWp⊤​(−Wp​W(X+X′)+Wa​X)−ηW at η=0\eta = 0η=0.

Scope.

  • In both parts WaW_aWa​ is held fixed while WpW_pWp​ or WWW is perturbed. In part 2 the perturbation of WWW does not change WaW_aWa​.
  • Only directional (entrywise partial) derivatives at the given point are asserted, not joint (Fréchet) differentiability.
  • If n2=0n_2 = 0n2​=0, both statements are vacuous. If n1=0n_1 = 0n1​=0, part 2 is vacuous and part 1 reduces to a statement about empty products.
  • Because of the integral convention, xˉ(x)\bar x(x)xˉ(x) is defined as 000 at any xxx for which y↦yiy \mapsto y_iy↦yi​ fails to be κ(x)\kappa(x)κ(x)-integrable. The same applies to the inner and outer integrals defining XXX, X′X'X′ and JJJ.
Human review
  • Endorsed by Shuze Chen · Nov 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me