Documentation

LeanMlir.Proofs.Nets.EfficientNet.EfficientNetFold

PoC: the full-16 (262-param) EfficientNet-B0 train step, proof-tied (the §1 fold, den) #

The §1 fold for the batched 262-param EfficientNet-B0 train step efficientnetTrainStepFaithfulV (EfficientNetRender.lean). Every emitted param-SGD op denotes the certified loss-descent step — θ − lr·(certified Jacobian · cotangent).

The batched wrinkle vs mnv2. EfficientNet trains at the batched index N·(c·h·w) with the fused-batch param-SGD ops (convWeightSgdB/denseWeightSgdB/bn{Gamma,Beta}SgdB/…), whose den carries a batch sum Σ_n over the per-example gradients (the shared-weight batched gradient). So unlike mnv2 (per-example, one ∑_j pdiv·cot), each fold here is "the per-example bridge applied inside Σ_n" — the batch-sum bridge. For the linear families (conv/dense weight, bias) this is a Finset.sum_congr of the per-example .correct; for BN γ/β the den already folds N into the per-channel reduction count m = N·(h·w), so it is the cert's exact LHS (delegation).

Each fused op is θ − lr· its un-fused gradient node by rfl (StableHLO.lean's *SgdB_eq_grad), so every lemma here is the un-fused fold — ResNet34PoCB (conv, dense weight, BN) or EnetPoCG (the XLA-SAME stem, depthwise, the rectangular dense bias) — under that wrapper.

theorem Proofs.EnetPoC.convWB_den {N ic oc h w kH kW : } (xN wN lrStr cotN : String) (b : Vec oc) (x : Vec (N * (ic * h * w))) (W : Kernel4 oc ic kH kW) (cot : Vec (N * (oc * h * w))) (lr : ) (idx : Fin (oc * ic * kH * kW)) :
StableHLO.den (StableHLO.SHlo.convWeightSgdB xN wN lrStr b x W lr (StableHLO.SHlo.operand cotN cot)) idx = W.flatten idx - lr * 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 op denotes the certified Σ_n batched weight gradient. Each emitted convWeightSgdB (expand/project/head) denotes flatten W − lr·Σ_n (∂conv2d/∂W · cotₙ) at the per-example slice n, via Σ_n of conv_weight_grad_bridge. Generic in dims + cotangent.

theorem Proofs.EnetPoC.convStridedWB_den {N ic oc h w kH kW : } (xN wN lrStr 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))) (lr : ) (idx : Fin (oc * ic * kH * kW)) :
StableHLO.den (StableHLO.SHlo.convStridedXlaWeightSgdB xN wN lrStr b x W lr (StableHLO.SHlo.operand cotN cot)) idx = W.flatten idx - lr * 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 strided-stem 3×3 conv weight op denotes the certified Σ_n batched weight gradient. Σ_n of flatConvStride2Xla_weight_grad_has_vjp.correct. The op is the XLA-SAME convStridedXlaWeightSgdB the render emits at the stem (EfficientNetRender.lean), whose weight-grad correlation pad is shifted one position; its den is the odd-phase weight VJP, so the certified gradient here is the gradient of the net that ships.

theorem Proofs.EnetPoC.denseWB_den {N a c : } (xN wN lrStr cotN : String) (x : Vec (N * a)) (W : Mat a c) (b : Vec c) (cot : Vec (N * c)) (lr : ) (i : Fin a) (j : Fin c) :
StableHLO.den (StableHLO.SHlo.denseWeightSgdB xN wN lrStr x W lr (StableHLO.SHlo.operand cotN cot)) (finProdFinEquiv (i, j)) = W i j - lr * n : Fin N, k : Fin c, pdiv (fun (v : Vec (a * c)) => dense (Mat.unflatten v) b (StableHLO.batchSlice N a x n)) W.flatten (finProdFinEquiv (i, j)) k * StableHLO.batchSlice N c cot n k

Batched dense weight op denotes the certified Σ_n batched weight gradient. Σ_n of the dense outer-product .correct (dense_weight_grad_correct). Covers the SE squeeze/excite denses (W₁ : c→r, W₂ : r→c) and the head classifier. Generic in b (the grad is b-independent).

theorem Proofs.EnetPoC.denseBB_den {N c : } (bN lrStr cotN : String) (W : Mat c c) (x b : Vec c) (cot : Vec (N * c)) (lr : ) (j : Fin c) :
StableHLO.den (StableHLO.SHlo.denseBiasSgdB bN lrStr b lr (StableHLO.SHlo.operand cotN cot)) j = b j - lr * 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 op denotes the certified Σ_n batched bias gradient (Σ_{n} cotₙ per output) — Σ_n of dense_bias_grad_correct. Covers the SE b₁/b₂ and the head bias.

theorem Proofs.EnetPoC.bnGammaB_den {N oc h w : } (gN vN epsStr lrStr cotN : String) (ε : ) (γ β : Vec oc) (v cot : Vec (N * (oc * (h * w)))) (lr : ) (idx : Fin oc) :
StableHLO.den (StableHLO.SHlo.bnGammaSgdB gN vN epsStr lrStr ε γ v lr (StableHLO.SHlo.operand cotN cot)) idx = γ idx - lr * j : Fin (oc * (N * (h * w))), pdiv (fun (γ' : Vec oc) => bnPerChannelFlat oc (N * (h * w)) ε γ' β (bnchwFwd N oc h w v)) γ idx j * bnchwFwd N oc h w cot j

Batched BN γ op denotes the certified per-channel γ gradient over the merged batch+spatial axis m = N·(h·w). True batch-norm's γ grad is per-channel BN's γ grad at m = N·h·w (γ enters affinely — no batch coupling in the param grad), so this is a direct delegation to the generic cifar_bn_render_gamma_certified at m = N·(h·w) (the den's exact reduction count, via the network→oc-major reindex bnchwFwd). Generic in the free β.

theorem Proofs.EnetPoC.bnBetaB_den {N oc h w : } (bN lrStr cotN : String) (ε : ) (γ β : Vec oc) (v : Vec (oc * (N * (h * w)))) (cot : Vec (N * (oc * (h * w)))) (lr : ) (idx : Fin oc) :
StableHLO.den (StableHLO.SHlo.bnBetaSgdB bN lrStr β lr (StableHLO.SHlo.operand cotN cot)) idx = β idx - lr * j : Fin (oc * (N * (h * w))), pdiv (fun (β' : Vec oc) => bnPerChannelFlat oc (N * (h * w)) ε γ β' v) β idx j * bnchwFwd N oc h w cot j

Batched BN β op denotes the certified per-channel β gradient Σ_{batch,spatial} cot at m = N·(h·w). Used for every BN β AND (as the channel-sum) every conv/depthwise bias. Direct delegation to cifar_bn_render_beta_certified. The pdiv form carries a free v/γ (β's grad is the channel-sum, independent of them).

def Proofs.EnetPoC.BnSgdPairTiedB (N oc h w : ) (gN vN epsStr bN lrStr cotN : String) (ε : ) (γ β : Vec oc) (v cot : Vec (N * (oc * (h * w)))) (lr : ) :

One batched BN layer's fused γ and β SGD nodes, tiedResNet34PoCB.BnPairTiedB under θ − lr·: the emitted bnGammaSgdB / bnBetaSgdB denote the certified per-channel γ and β steps at the layer's pre-BN activation v and output cotangent cot.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.EnetPoC.bnSgdPairTiedB_holds {N oc h w : } (gN vN epsStr bN lrStr cotN : String) (ε : ) (γ β : Vec oc) (v cot : Vec (N * (oc * (h * w)))) (lr : ) :
    BnSgdPairTiedB N oc h w gN vN epsStr bN lrStr cotN ε γ β v cot lr
    theorem Proofs.EnetPoC.depthwiseWB_den {N c h w kH kW : } (xN wN lrStr cotN : String) (b : Vec c) (x : Vec (N * (c * h * w))) (W : DepthwiseKernel c kH kW) (cot : Vec (N * (c * h * w))) (lr : ) (idx : Fin (c * kH * kW)) :
    StableHLO.den (StableHLO.SHlo.depthwiseWeightSgdB xN wN lrStr b x W lr (StableHLO.SHlo.operand cotN cot)) idx = Tensor3.flatten W idx - lr * 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 op denotes the certified Σ_n batched weight gradient. Σ_n of the flattened depthwise_weight_grad_has_vjp3.correct (the per-slice grad bridge from mnv2_render_depthwiseW_flat_certified). Generic in the kernel size (3×3 and 5×5).

    theorem Proofs.EnetPoC.depthwiseStridedWB_den {N c h w kH kW : } (xN wN lrStr cotN : String) (b : Vec c) (x : Vec (N * (c * (2 * h) * (2 * w)))) (W : DepthwiseKernel c kH kW) (cot : Vec (N * (c * h * w))) (lr : ) (idx : Fin (c * kH * kW)) :
    StableHLO.den (StableHLO.SHlo.depthwiseStridedWeightSgdB xN wN lrStr b x W lr (StableHLO.SHlo.operand cotN cot)) idx = Tensor3.flatten W idx - lr * 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 op denotes the certified Σ_n batched weight gradient. The strided VJP is already flat, so Σ_n of depthwiseStride2_weight_grad_has_vjp.correct.

    def Proofs.EnetPoC.ConvWSgdTiedB (N h w : ) {ic oc kH kW : } (xN wN lrStr cotN : String) (b : Vec oc) (x : Vec (N * (ic * h * w))) (W : Kernel4 oc ic kH kW) (cot : Vec (N * (oc * h * w))) (lr : ) :

    A stride-1 conv weight SGD node, tied (convWB_den).

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      def Proofs.EnetPoC.DepthwiseWSgdTiedB (N h w : ) {c kH kW : } (xN wN lrStr cotN : String) (b : Vec c) (x : Vec (N * (c * h * w))) (W : DepthwiseKernel c kH kW) (cot : Vec (N * (c * h * w))) (lr : ) :

      A stride-1 depthwise weight SGD node, tied (depthwiseWB_den).

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Proofs.EnetPoC.DenseWSgdTiedB (N : ) {a c : } (xN wN lrStr cotN : String) (x : Vec (N * a)) (W : Mat a c) (b : Vec c) (cot : Vec (N * c)) (lr : ) :

        A dense weight SGD node, tied (denseWB_den).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Proofs.EnetPoC.DenseBSgdTiedB (N : ) {a c : } (bN lrStr cotN : String) (W : Mat a c) (x : Vec a) (b : Vec c) (cot : Vec (N * c)) (lr : ) :

          A dense bias SGD node, tied — free in W and x, which b's gradient ignores.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For