Documentation

LeanMlir.Proofs.Nets.ConvNeXt.ConvNeXtClose

Closing the ConvNeXt render — the parameter-gradient close (two small new families) #

planning/archive/convnext_close.md Item C, applied to the representative 2-block ConvNeXt (tests/TestConvNeXtTrain.lean; convNextForward, the proven whole-net VJP convnext_has_vjp). The close is generic in the cotangent dy the backward chain delivers at each layer's output (pinning that cotangent to the actual block chain is the optional Item D), batch-1 — LayerNorm is per-example separable, so no batched apparatus (the EfficientNet contrast).

family (render SSA)forward fncertified by
stem/expand/project 1×1 conv W/bconv2d (stride 1)cnn_render_conv{W,b}_certified (M3, reuse)
depthwise 7×7 W/bdepthwiseConv2dcnx_render_dw7{W,b}_certified (kernel-general — pinned below)
dense head Wd/bdmatmul / +biasM2 weight/bias_grad_bridge (reuse)
layer-scale γ (layerScaleF)γ ⊙ xcnx_render_lsgamma_certified (new): ∂(γⱼxⱼ)/∂γᵢ = xᵢδᵢⱼdγ = x ⊙ dy
scalar-LN γ/β (the bnF sites)layerNormForwardcnx_render_ln{gamma,beta}_certified (new): the Vec 1 embedding
geluno parameters

Two genuinely-new bridge families:

The 7×7 depthwise is the only kernel size to pin (prior nets used 3×3/5×5; the generic mnv2_render_depthwise{W,b}_certified is kernel-general — stride-1 only, ConvNeXt blocks don't downsample). The 1×1 convs (stem/expand/project) and the dense head are verbatim M3/M2 reuse at the ConvNeXt shapes. 3-axiom clean by inheritance.

theorem Proofs.cnx_render_dw7W_certified {c h w : } (b : Vec c) (x : Tensor3 c h w) (W : DepthwiseKernel c 7 7) (dy : Tensor3 c h w) (lr : ) (ci : Fin c) (hi wi : Fin 7) :
W ci hi wi - lr * (depthwise_weight_grad_has_vjp3 b x).backward W dy ci hi wi = W ci hi wi - lr * co : Fin c, ho : Fin h, wo : Fin w, pdiv3 (fun (W' : DepthwiseKernel c 7 7) => depthwiseConv2d W' b x) W ci hi wi co ho wo * dy co ho wo

7×7 depthwise weight output, certified. The generic depthwise weight bridge at kH=kW=7; covers every ConvNeXt block's depthwise (stride-1 — ConvNeXt blocks keep resolution).

theorem Proofs.cnx_render_dw7b_certified {c h w : } (W : DepthwiseKernel c 7 7) (x : Tensor3 c h w) (b : Vec c) (dy : Vec (c * h * w)) (lr : ) (cc : Fin c) :
b cc - lr * (depthwise_bias_grad_has_vjp W x).backward b dy cc = b cc - lr * j : Fin (c * h * w), pdiv (fun (b' : Vec c) => (depthwiseConv2d W b' x).flatten) b cc j * dy j

7×7 depthwise bias output, certified.

theorem Proofs.pdiv_layerScale_gamma {n : } (x γ : Vec n) (i j : Fin n) :
pdiv (fun (γ' : Vec n) => layerScale γ' x) γ i j = if i = j then x i else 0

Jacobian of layerScale w.r.t. γ∂(γ_j x_j)/∂γ_i = x_i δ_{ij}. The parameter mirror of pdiv_layerScale.

noncomputable def Proofs.layerScale_grad_gamma {n : } (x dy : Vec n) :
Vec n

The rendered layer-scale γ gradient: dγ_i = x_i · dy_i (elementwise multiply of the saved layer input with the cotangent — the layerScaleF-shaped backward).

Equations
Instances For
    theorem Proofs.layerScale_gamma_grad_bridge {n : } (x γ dy : Vec n) (i : Fin n) :
    layerScale_grad_gamma x dy i = j : Fin n, pdiv (fun (γ' : Vec n) => layerScale γ' x) γ i j * dy j

    Layer-scale γ-gradient bridge. The rendered dγ = x ⊙ dy equals the certified Jacobian of layerScale (as a function of γ) contracted with the cotangent dy.

    theorem Proofs.cnx_render_lsgamma_certified {n : } (x γ dy : Vec n) (lr : ) (i : Fin n) :
    γ i - lr * layerScale_grad_gamma x dy i = γ i - lr * j : Fin n, pdiv (fun (γ' : Vec n) => layerScale γ' x) γ i j * dy j

    Layer-scale γ output, certified. γⁿ = γ − lr·(x ⊙ dy) denotes γ − lr·(certified ∂(layerScale)/∂γ · cotangent). The multiplicative-bias peer of cnn_render_convb_certified.

    theorem Proofs.cnx_lnGamma_grad_bridge (n : ) (ε β : ) (γ : Vec 1) (x dy : Vec n) :
    bn_grad_gamma n ε x dy = j : Fin n, pdiv (fun (γ' : Vec 1) => layerNormForward n ε (γ' 0) β x) γ 0 j * dy j

    Scalar-LN γ-gradient bridge. The rendered whole-n reduce dγ = Σ_j dy_j·x̂_j (bn_grad_gamma) equals the certified Jacobian of scalar-LN (as a function of γ, embedded Vec 1) contracted with the cotangent dy. Closes the gap BatchNorm.lean documented — bn_grad_gamma is now bridged, not just defined.

    theorem Proofs.cnx_lnBeta_grad_bridge (n : ) (ε γ : ) (β : Vec 1) (x dy : Vec n) :
    bn_grad_beta n dy = j : Fin n, pdiv (fun (β' : Vec 1) => layerNormForward n ε γ (β' 0) x) β 0 j * dy j

    Scalar-LN β-gradient bridge. Likewise the rendered dβ = Σ_j dy_j (bn_grad_beta) is the certified scalar-LN ∂/∂β contraction.

    theorem Proofs.cnx_render_lngamma_certified (n : ) (ε β : ) (γ : Vec 1) (x dy : Vec n) (lr : ) :
    γ 0 - lr * bn_grad_gamma n ε x dy = γ 0 - lr * j : Fin n, pdiv (fun (γ' : Vec 1) => layerNormForward n ε (γ' 0) β x) γ 0 j * dy j

    Scalar-LN γ output, certified. γⁿ = γ − lr·(Σ dy·x̂) denotes γ − lr·(certified ∂(layerNormForward)/∂γ · cotangent). Covers the stem-LN, both block-LNs, and the head-LN of the representative ConvNeXt (each at its own n).

    theorem Proofs.cnx_render_lnbeta_certified (n : ) (ε γ : ) (β : Vec 1) (x dy : Vec n) (lr : ) :
    β 0 - lr * bn_grad_beta n dy = β 0 - lr * j : Fin n, pdiv (fun (β' : Vec 1) => layerNormForward n ε γ (β' 0) x) β 0 j * dy j

    Scalar-LN β output, certified. βⁿ = β − lr·(Σ dy) denotes the certified scalar-LN ∂/∂β contraction.