Documentation

LeanMlir.Proofs.Nets.EfficientNet.EfficientNetFoldG

T3 §1 fold for EfficientNet-B0 at the UN-FUSED gradient — the Adam artifact's op set #

EfficientNetFold.lean makes every parameter output of the SGD-inline efficientnet_train_step.mlir den-faithful: each *SgdB op denotes θ − lr·(certified Jacobian · cotangent). Every OTHER train step this net renders — efficientnet_adam_train_step, the _rms_/_emarms_/_do_/_drop_/_dp_/bf16 families, and the ImageNet efficientnetin_emarmsdp64dropdo_train_step whose accuracy the book quotes — takes EfficientNetRender's adam := true branch, which emits the RAW gradient (*GradB) and hands it to an optimizer tail. This file is the fold at those nodes. ⚠ The bf16 family's conv and depthwise weight nodes are *GradBBf16, their own kind, folded in Foundation/Bf16GradNodes.lean.

One lemma per op kind certifies every optimizer variant at once, because RMSProp, AdamW, plain SGD, EMA and the data-parallel peers all consume the same gradient node. The fusion itself is rfl (StableHLO.lean's *SgdB_eq_grad family), so nothing here is new mathematics, and EfficientNetFold.lean's fused lemmas are these (and ResNet34FoldB.lean's) through that family.

⭐ Five of the eight op kinds were ALREADY proven, in r34's file #

ResNet34FoldB.lean states its eight folds at op kinds, not at r34 — and five of them are the same constructors this net emits, at the same generality: convWeightGradB (every 1×1 expand / project / head conv), bnGammaGradB / bnBetaGradB (all 49 BatchNorm sites, and every conv bias, which the render folds onto the following BN's β), and denseWeightGradB (the SE squeeze/excite denses and the classifier). So B0's package is three genuinely new lemmas, not eight; the five below are one-line delegations that say so out loud, so this file is still the complete op table for the artifact. (denseBiasGradB is restated rather than delegated only to widen r34's square Mat c c witness to the SE's rectangular Mat a c — the gradient is W-free either way.)

The three that are new, and why #

Honest residual #

theorem Proofs.EnetPoCG.convWGradB_den {N ic oc h w kH kW : } (xN cotN : String) (b : Vec oc) (x : Vec (N * (ic * h * w))) (W : Kernel4 oc ic kH kW) (cot : Vec (N * (oc * h * w))) (idx : Fin (oc * ic * kH * kW)) :
StableHLO.den (StableHLO.SHlo.convWeightGradB xN b x W (StableHLO.SHlo.operand cotN cot)) idx = n : Fin N, j : Fin (oc * h * w), pdiv (fun (v' : Vec (oc * ic * kH * kW)) => (conv2d (Kernel4.unflatten v') b (Tensor3.unflatten (StableHLO.batchSlice N (ic * h * w) x n))).flatten) W.flatten idx j * StableHLO.batchSlice N (oc * h * w) cot n j

Batched 1×1-conv weight GRADIENT denotes the certified Σ_n weight gradient. Every expand, project and head conv. Identical to r34's block convs as an op: ResNet34PoCB.convWGradB_den.

theorem Proofs.EnetPoCG.bnBetaGradB_den {N oc h w : } (cotN : String) (ε : ) (γ β : Vec oc) (v : Vec (oc * (N * (h * w)))) (cot : Vec (N * (oc * (h * w)))) (c : Fin oc) :
StableHLO.den (StableHLO.SHlo.operand cotN cot).bnBetaGradB c = j : Fin (oc * (N * (h * w))), pdiv (fun (β' : Vec oc) => bnPerChannelFlat oc (N * (h * w)) ε γ β' v) β c j * bnchwFwd N oc h w cot j

Batched BN β GRADIENT denotes the certified per-channel β gradient Σ_{batch,spatial} cot. Used at all 49 BN βs AND at every conv bias, which the render folds onto the following BN. ResNet34PoCB.bnBetaGradB_den.

theorem Proofs.EnetPoCG.denseWGradB_den {N a c : } (xN cotN : String) (x : Vec (N * a)) (W : Mat a c) (b : Vec c) (cot : Vec (N * c)) (i : Fin a) (j : Fin c) :

Batched dense weight GRADIENT denotes the certified Σ_n outer product. The SE squeeze (c → r) and excite (r → c) denses and the classifier head. ResNet34PoCB.denseWGradB_den.

theorem Proofs.EnetPoCG.denseBGradB_den {N a c : } (cotN : String) (W : Mat a c) (x : Vec a) (b : Vec c) (cot : Vec (N * c)) (j : Fin c) :
StableHLO.den (StableHLO.SHlo.operand cotN cot).denseBiasGradB j = n : Fin N, k : Fin c, pdiv (fun (b' : Vec c) => dense W b' x) b j k * StableHLO.batchSlice N c cot n k

Batched dense bias GRADIENT denotes the certified Σ_n cotangent sum. r34's peer at a RECTANGULAR witness Mat a c, which the SE's c → r squeeze needs; the gradient is the channel sum and depends on neither W nor x, so the widening is free.

theorem Proofs.EnetPoCG.convStridedXlaWGradB_den {N ic oc h w kH kW : } (xN cotN : String) (b : Vec oc) (x : Vec (N * (ic * (2 * h) * (2 * w)))) (W : Kernel4 oc ic kH kW) (cot : Vec (N * (oc * h * w))) (idx : Fin (oc * ic * kH * kW)) :
StableHLO.den (StableHLO.SHlo.convStridedXlaWeightGradB xN b x W (StableHLO.SHlo.operand cotN cot)) idx = n : Fin N, j : Fin (oc * h * w), pdiv (fun (v' : Vec (oc * ic * kH * kW)) => flatConvStride2Xla (Kernel4.unflatten v') b (StableHLO.batchSlice N (ic * (2 * h) * (2 * w)) x n)) W.flatten idx j * StableHLO.batchSlice N (oc * h * w) cot n j

Batched XLA-SAME strided conv weight GRADIENT denotes the certified Σ_n weight gradient. B0's 3×3/s2 stem, the net's one XLA-phase site. Σ_n of flatConvStride2Xla_weight_grad_has_vjp.correct — the odd-phase weight VJP, so the certified gradient is the gradient of the net that ships.

theorem Proofs.EnetPoCG.depthwiseWGradB_den {N c h w kH kW : } (xN cotN : String) (b : Vec c) (x : Vec (N * (c * h * w))) (W : DepthwiseKernel c kH kW) (cot : Vec (N * (c * h * w))) (idx : Fin (c * kH * kW)) :
StableHLO.den (StableHLO.SHlo.depthwiseWeightGradB xN b x W (StableHLO.SHlo.operand cotN cot)) idx = n : Fin N, j : Fin (c * h * w), pdiv (fun (v' : Vec (c * kH * kW)) => (depthwiseConv2d (Tensor3.unflatten v') b (Tensor3.unflatten (StableHLO.batchSlice N (c * h * w) x n))).flatten) (Tensor3.flatten W) idx j * StableHLO.batchSlice N (c * h * w) cot n j

Batched stride-1 depthwise weight GRADIENT denotes the certified Σ_n weight gradient. Σ_n of the flattened depthwise_weight_grad_has_vjp3.correct. Generic in the kernel size, so the one lemma covers every 3×3 and every 5×5 depthwise.

theorem Proofs.EnetPoCG.depthwiseStridedWGradB_den {N c h w kH kW : } (xN cotN : String) (b : Vec c) (x : Vec (N * (c * (2 * h) * (2 * w)))) (W : DepthwiseKernel c kH kW) (cot : Vec (N * (c * h * w))) (idx : Fin (c * kH * kW)) :
StableHLO.den (StableHLO.SHlo.depthwiseStridedWeightGradB xN b x W (StableHLO.SHlo.operand cotN cot)) idx = n : Fin N, j : Fin (c * h * w), pdiv (fun (v' : Vec (c * kH * kW)) => depthwiseStride2Flat (Tensor3.unflatten v') b (StableHLO.batchSlice N (c * (2 * h) * (2 * w)) x n)) (Tensor3.flatten W) idx j * StableHLO.batchSlice N (c * h * w) cot n j

Batched strided depthwise weight GRADIENT denotes the certified Σ_n weight gradient. The strided VJP is already flat, so this is Σ_n of depthwiseStride2_weight_grad_has_vjp.correct.