Documentation

LeanMlir.Proofs.Nets.EfficientNet.EfficientNetStepTie

EfficientNet-B0 train-step tie (fused SGD) — efficientnet_net_tied #

Every one of B0's 262 parameters' SGD ops, at the cotangent the rendered net's own backward chain hands it: the real forward (efficientnetForwardBFull) threaded through every parameter op, the loss cotangent composed back through all 16 MBConv blocks, the residual fan-in at each stride-1 skip and the squeeze-excite gate fan-in included. The batched, un-fused peer (tied at the *GradB nodes) is EnetTieG.efficientnet_net_tiedG in EfficientNetStepTieG.

What B0 adds over MobileNetV2's tie #

EfficientNetChainClose's whole-net backward is vjpComp of the per-block HasVJPs, so the tie builds explicit chain-cotangent constructors rather than reading them off.

Contents #

Not done: the dense head's total-loss fold (Wfc → ∂CE/∂Wfc, the batched Σ_n analogue of StableHLO.lossWeightGrad_eq_sum); the head dense ties at g directly.

Residual stride-1 MBConv block — all 16 params tied (expand → dw → SE → project + skip) #

The centerpiece: exercises the genuinely-new content vs mnv2 — swish masks (smooth), the SE gate fan-in (gateCotB → sigBackB → {zW₂,zb₂} → rowDenseBackFlat → swBackB → {zW₁,zb₁}), and true batch-norm backward (bnBackB), all at the batched index N·(c·h·w). Backward from dyOut (cot at project-BN out): project-BN-back → project-conv-back (cot at SE out) → SE backward (fused dx for the depthwise side; un-fused gate-cot for the SE params) → depthwise swish/BN/conv backs → expand swish/BN/conv backs. Residual (ic=oc=c): the block-input cotangent fan-in + dyOut lives in the whole-net thread, not here (the param ops are skip-agnostic — identical to the no-skip widenings).

def Proofs.EnetTie.ConvBBetaSgdTied (N h w : ℕ) {oc : ℕ} (bN lrStr cotN : String) (ε : ℝ) (b : Vec oc) (cot : Vec (N * (oc * h * w))) (lr : ℝ) :

A conv or depthwise bias, tied, fused SGD form. The emitted bnBetaSgdB node takes the bias step on the channel sum of the conv-output cotangent cot (network layout); the right side states that gradient as a per-channel BatchNorm's β-Jacobian at the γ and activation (both zero here) that β's gradient ignores.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.EnetTie.convBBetaSgdTied_holds {N h w oc : ℕ} {bN lrStr cotN : String} {ε : ℝ} {b : Vec oc} {cot : Vec (N * (oc * h * w))} {lr : ℝ} :
    ConvBBetaSgdTied N h w bN lrStr cotN ε b cot lr
    def Proofs.EnetTie.enetExpTied {N ic mid oc h w r kHd kWd : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εe : ℝ) (hεe : 0 < εe) (εd : ℝ) (hεd : 0 < εd) (εp : ℝ) (hεp : 0 < εp) (We : Kernel4 mid ic 1 1) (be γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd γd βd : Vec mid) (Wz1 : Mat mid r) (bz1 : Vec r) (Wz2 : Mat r mid) (bz2 : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp γp βp : Vec oc) (xin : Vec (N * (ic * h * w))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :

    Residual stride-1 MBConv block, tied. All 16 params (expand/project 1×1 conv W+b, depthwise W+b, SE reduce/excite dense W₁/b₁/W₂/b₂, three true-BN γ/β) denote the certified batched Σ_n loss-descent step at the real block forward activations + the chain cotangents driven by dyOut.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.EnetTie.enet_exp_tied {N ic mid oc h w r kHd kWd : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εe : ℝ) (hεe : 0 < εe) (εd : ℝ) (hεd : 0 < εd) (εp : ℝ) (hεp : 0 < εp) (We : Kernel4 mid ic 1 1) (be γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd γd βd : Vec mid) (Wz1 : Mat mid r) (bz1 : Vec r) (Wz2 : Mat r mid) (bz2 : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp γp βp : Vec oc) (xin : Vec (N * (ic * h * w))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :
      enetExpTied xN wN bN gN vN epsStr lrStr cotN εe hεe εd hεd εp hεp We be γe βe Wd bd γd βd Wz1 bz1 Wz2 bz2 Wp bp γp βp xin dyOut lr

      Strided downsampling MBConv block — all 16 params tied (b2/b4/b6/b12) #

      Same as the expand block EXCEPT the expand stage lives at the block-input grid 2h×2w and the depthwise is strided (depthwiseStridedXlaWeightSgdB, the expand-side cotangent cotEr upsamples h→2h via dStridedXlaInB). No skip (spatial+channels change).

      def Proofs.EnetTie.enetStridedTied {N ic mid oc h w r kHd kWd : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εe : ℝ) (hεe : 0 < εe) (εd : ℝ) (hεd : 0 < εd) (εp : ℝ) (hεp : 0 < εp) (We : Kernel4 mid ic 1 1) (be γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd γd βd : Vec mid) (Wz1 : Mat mid r) (bz1 : Vec r) (Wz2 : Mat r mid) (bz2 : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp γp βp : Vec oc) (xin : Vec (N * (ic * (2 * h) * (2 * w)))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :

      Strided downsampling MBConv block, tied. All 16 params at the real forward (expand at 2h×2w, strided depthwise 2h→h) + the chain cotangents driven by dyOut.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Proofs.EnetTie.enet_strided_tied {N ic mid oc h w r kHd kWd : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εe : ℝ) (hεe : 0 < εe) (εd : ℝ) (hεd : 0 < εd) (εp : ℝ) (hεp : 0 < εp) (We : Kernel4 mid ic 1 1) (be γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd γd βd : Vec mid) (Wz1 : Mat mid r) (bz1 : Vec r) (Wz2 : Mat r mid) (bz2 : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp γp βp : Vec oc) (xin : Vec (N * (ic * (2 * h) * (2 * w)))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :
        enetStridedTied xN wN bN gN vN epsStr lrStr cotN εe hεe εd hεd εp hεp We be γe βe Wd bd γd βd Wz1 bz1 Wz2 bz2 Wp bp γp βp xin dyOut lr

        No-expand MBConv block (b1, t=1) — all 12 params tied (depthwise on ic → SE → project) #

        NO expand conv: the depthwise runs directly on the block input (ic channels). 12 params (4 depthwise+BN, 4 SE, 4 project). The SE squeeze/excite is on ic channels (ic → r → ic).

        def Proofs.EnetTie.enetNoExpTied {N ic oc h w r kHd kWd : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εd : ℝ) (hεd : 0 < εd) (εp : ℝ) (hεp : 0 < εp) (Wd : DepthwiseKernel ic kHd kWd) (bd γd βd : Vec ic) (Wz1 : Mat ic r) (bz1 : Vec r) (Wz2 : Mat r ic) (bz2 : Vec ic) (Wp : Kernel4 oc ic 1 1) (bp γp βp : Vec oc) (xin : Vec (N * (ic * h * w))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :

        No-expand MBConv block, tied. All 12 params at the real forward + chain cotangents.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Proofs.EnetTie.enet_noexp_tied {N ic oc h w r kHd kWd : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εd : ℝ) (hεd : 0 < εd) (εp : ℝ) (hεp : 0 < εp) (Wd : DepthwiseKernel ic kHd kWd) (bd γd βd : Vec ic) (Wz1 : Mat ic r) (bz1 : Vec r) (Wz2 : Mat r ic) (bz2 : Vec ic) (Wp : Kernel4 oc ic 1 1) (bp γp βp : Vec oc) (xin : Vec (N * (ic * h * w))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :
          enetNoExpTied xN wN bN gN vN epsStr lrStr cotN εd hεd εp hεp Wd bd γd βd Wz1 bz1 Wz2 bz2 Wp bp γp βp xin dyOut lr

          Stem — the 3×3/s2 conv-bn-swish (4 params), feeding block 1 #

          swish(bn(convStride2Xla Ws bs x)), 3→32 at 224→112, at the XLA-SAME phase the shipped stem uses. The cotangent block 1 delivers at the stem swish output (dyStem) lifts through swish-back

          def Proofs.EnetTie.enetStemTied {N ic oc h w kHs kWs : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εs : ℝ) (hεs : 0 < εs) (Ws : Kernel4 oc ic kHs kWs) (bs γs βs : Vec oc) (x : Vec (N * (ic * (2 * h) * (2 * w)))) (dyStem : Vec (N * (oc * h * w))) (lr : ℝ) :

          Stem, tied. The 3×3/s2 conv (Ws/bs) + its true-BN (γs/βs) at the real stem forward + the cotangent through the stem swish (no maxpool, no conv-back).

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Proofs.EnetTie.enet_stem_tied {N ic oc h w kHs kWs : ℕ} (xN wN bN gN vN epsStr lrStr cotN : String) (εs : ℝ) (hεs : 0 < εs) (Ws : Kernel4 oc ic kHs kWs) (bs γs βs : Vec oc) (x : Vec (N * (ic * (2 * h) * (2 * w)))) (dyStem : Vec (N * (oc * h * w))) (lr : ℝ) :
            enetStemTied xN wN bN gN vN epsStr lrStr cotN εs hεs Ws bs γs βs x dyStem lr

            Head — the 1×1 conv-bn-swish (4 params) → GAP → dense (Wfc/bfc), + the loss cotangent #

            dense(GAP(swish(bn(conv Wh bh))))) (320→1280 conv, GAP, 1280→nClasses dense), then the batched per-row softmax-CE gradient g = rowSoftmax(logits) − onehot. The head conv params tie at the chain cotangent (loss → dense-back → GAP-back → swish/BN-back); the dense Wfc/bfc tie at the loss cotangent g directly.

            def Proofs.EnetTie.enetHeadTied {N c oc h w nC : ℕ} (xN wN bN gN vN epsStr lrStr cotN dN : String) (εh : ℝ) (hεh : 0 < εh) (Wh : Kernel4 oc c 1 1) (bh γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (xhead : Vec (N * (c * h * w))) (onehot : Vec (N * nC)) (lr : ℝ) :

            Head, tied. The 4 head conv-bn params + the 2 dense params (Wfc/bfc) denote the certified step at the real head forward + the loss-driven cotangent g = rowSoftmax(logits) − onehot.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem Proofs.EnetTie.enet_head_tied {N c oc h w nC : ℕ} (xN wN bN gN vN epsStr lrStr cotN dN : String) (εh : ℝ) (hεh : 0 < εh) (Wh : Kernel4 oc c 1 1) (bh γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (xhead : Vec (N * (c * h * w))) (onehot : Vec (N * nC)) (lr : ℝ) :
              enetHeadTied xN wN bN gN vN epsStr lrStr cotN dN εh hεh Wh bh γh βh Wfc bfc xhead onehot lr

              Bundle-taking *TiedAt wrappers — one per block type, for the whole-net thread #

              Each takes the B0Weights block bundle (MBW/MBWNoExp) + its ε-positivity + the block input + the downstream cotangent dyOut, and delegates to the per-block-type tie.

              def Proofs.EnetTie.enetExpTiedAt (xN wN bN gN vN epsStr lrStr cotN : String) {N ic mid oc r kh kw : ℕ} (h w : ℕ) (p : MBW ic mid oc r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) (xin : Vec (N * (ic * h * w))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def Proofs.EnetTie.enetStridedTiedAt (xN wN bN gN vN epsStr lrStr cotN : String) {N ic mid oc r kh kw : ℕ} (h w : ℕ) (p : MBW ic mid oc r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) (xin : Vec (N * (ic * (2 * h) * (2 * w)))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def Proofs.EnetTie.enetNoExpTiedAt (xN wN bN gN vN epsStr lrStr cotN : String) {N ic oc r kh kw : ℕ} (h w : ℕ) (p : MBWNoExp ic oc r kh kw) (hd : 0 < p.dε) (hp : 0 < p.pε) (xin : Vec (N * (ic * h * w))) (dyOut : Vec (N * (oc * h * w))) (lr : ℝ) :
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    The whole-net thread — all 262 params tied through the REAL efficientnetForwardBFull #

                    The capstone: efficientnetForwardBFull's prefixes are the block inputs (a0..a16 = stem, then the 16 MBConv blocks), and the per-block output cotangents (dy0..dy16) are composed TOP-DOWN by the proven block VJPs (headFwdBHasVJP, mb{Exp,Resid,Strided,NoExp}WHasVJP) from the loss cotangent g = rowSoftmax(logits) − onehot. Each block's tie then holds at its real input + threaded dyOut. The whole-net tie: the WHOLE 16-MBConv (262-param) EfficientNet-B0 train step is den-composed forward→loss→backward, no free activations, no symbolic cotangent. The residual fan-in at the 9 identity skips is folded into mbResidW's own VJP (it includes the + x), so it is automatic.

                    theorem Proofs.EnetTie.efficientnet_net_tied (xN wN bN gN vN epsStr lrStr cotN dN : String) (N : ℕ) {nCls : ℕ} (w : B0Weights nCls) (hεw : w.EpsPos) (x : Vec (N * (3 * 224 * 224))) (onehot : Vec (N * nCls)) (lr : ℝ) :
                    have a0 := stemB N w.sW w.sb w.sε w.sγ w.sβ x; have a1 := mbNoExpW N 112 112 w.b1 a0; have a2 := mbStridedW N 56 56 w.b2 a1; have a3 := mbResidW N 56 56 w.b3 a2; have a4 := mbStridedW N 28 28 w.b4 a3; have a5 := mbResidW N 28 28 w.b5 a4; have a6 := mbStridedW N 14 14 w.b6 a5; have a7 := mbResidW N 14 14 w.b7 a6; have a8 := mbResidW N 14 14 w.b8 a7; have a9 := mbExpW N 14 14 w.b9 a8; have a10 := mbResidW N 14 14 w.b10 a9; have a11 := mbResidW N 14 14 w.b11 a10; have a12 := mbStridedW N 7 7 w.b12 a11; have a13 := mbResidW N 7 7 w.b13 a12; have a14 := mbResidW N 7 7 w.b14 a13; have a15 := mbResidW N 7 7 w.b15 a14; have a16 := mbExpW N 7 7 w.b16 a15; have g := fun (idx : Fin (N * nCls)) => StableHLO.rowSoftmaxFlat N nCls (headFwdB N w.hW w.hb w.hε w.hγ w.hβ w.fcW w.fcb a16) idx - onehot idx; have dy16 := (headFwdBHasVJP N w.hW w.hb w.hε ⋯ w.hγ w.hβ w.fcW w.fcb).backward a16 g; have dy15 := (mbExpWHasVJP N 7 7 w.b16 ⋯ ⋯ ⋯).backward a15 dy16; have dy14 := (mbResidWHasVJP N 7 7 w.b15 ⋯ ⋯ ⋯).backward a14 dy15; have dy13 := (mbResidWHasVJP N 7 7 w.b14 ⋯ ⋯ ⋯).backward a13 dy14; have dy12 := (mbResidWHasVJP N 7 7 w.b13 ⋯ ⋯ ⋯).backward a12 dy13; have dy11 := (mbStridedWHasVJP N 7 7 w.b12 ⋯ ⋯ ⋯).backward a11 dy12; have dy10 := (mbResidWHasVJP N 14 14 w.b11 ⋯ ⋯ ⋯).backward a10 dy11; have dy9 := (mbResidWHasVJP N 14 14 w.b10 ⋯ ⋯ ⋯).backward a9 dy10; have dy8 := (mbExpWHasVJP N 14 14 w.b9 ⋯ ⋯ ⋯).backward a8 dy9; have dy7 := (mbResidWHasVJP N 14 14 w.b8 ⋯ ⋯ ⋯).backward a7 dy8; have dy6 := (mbResidWHasVJP N 14 14 w.b7 ⋯ ⋯ ⋯).backward a6 dy7; have dy5 := (mbStridedWHasVJP N 14 14 w.b6 ⋯ ⋯ ⋯).backward a5 dy6; have dy4 := (mbResidWHasVJP N 28 28 w.b5 ⋯ ⋯ ⋯).backward a4 dy5; have dy3 := (mbStridedWHasVJP N 28 28 w.b4 ⋯ ⋯ ⋯).backward a3 dy4; have dy2 := (mbResidWHasVJP N 56 56 w.b3 ⋯ ⋯ ⋯).backward a2 dy3; have dy1 := (mbStridedWHasVJP N 56 56 w.b2 ⋯ ⋯ ⋯).backward a1 dy2; have dy0 := (mbNoExpWHasVJP N 112 112 w.b1 ⋯ ⋯).backward a0 dy1; enetStemTied xN wN bN gN vN epsStr lrStr cotN w.sε ⋯ w.sW w.sb w.sγ w.sβ x dy0 lr ∧ enetNoExpTiedAt xN wN bN gN vN epsStr lrStr cotN 112 112 w.b1 ⋯ ⋯ a0 dy1 lr ∧ enetStridedTiedAt xN wN bN gN vN epsStr lrStr cotN 56 56 w.b2 ⋯ ⋯ ⋯ a1 dy2 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 56 56 w.b3 ⋯ ⋯ ⋯ a2 dy3 lr ∧ enetStridedTiedAt xN wN bN gN vN epsStr lrStr cotN 28 28 w.b4 ⋯ ⋯ ⋯ a3 dy4 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 28 28 w.b5 ⋯ ⋯ ⋯ a4 dy5 lr ∧ enetStridedTiedAt xN wN bN gN vN epsStr lrStr cotN 14 14 w.b6 ⋯ ⋯ ⋯ a5 dy6 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 14 14 w.b7 ⋯ ⋯ ⋯ a6 dy7 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 14 14 w.b8 ⋯ ⋯ ⋯ a7 dy8 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 14 14 w.b9 ⋯ ⋯ ⋯ a8 dy9 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 14 14 w.b10 ⋯ ⋯ ⋯ a9 dy10 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 14 14 w.b11 ⋯ ⋯ ⋯ a10 dy11 lr ∧ enetStridedTiedAt xN wN bN gN vN epsStr lrStr cotN 7 7 w.b12 ⋯ ⋯ ⋯ a11 dy12 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 7 7 w.b13 ⋯ ⋯ ⋯ a12 dy13 lr ∧ enetExpTiedAt xN wN bN gN vN epsStr lrStr cotN 7 7 w.b14 ⋯ ⋯ ⋯ a13 dy14 lr ∧ ⋯ ∧ ⋯

                    The whole 16-MBConv EfficientNet-B0 train step, tied. Threading the real batched (true-BN + SE) forward efficientnetForwardBFull and the loss-driven backward cotangent chain (swish masks, SE gate fan-in, true-BN backs, the residual fan-in folded into the block VJPs), the stem, all 16 MBConv blocks, the conv-bn-swish head, and the dense head all denote the certified batched Σ_n loss-descent step.