Documentation

LeanMlir.Proofs.Nets.EfficientNet.EfficientNetFullB0

The FULL EfficientNet-B0 — all 16 MBConv blocks, batched forward graph + faithfulness #

Scales EfficientNetStagesPC's representative (stem + 3 MBConv + head) to the real B0 [t,c,n,s,k] spec — 16 MBConv layers — at the batched index N·(c·h·w). Pure enumeration + chaining of the generic per-block machinery; the only genuinely-new piece is the 4th block shape (mbExp: expand + stride-1 + no residual, used by stage-5/stage-7 first blocks where ic ≠ oc).

B0 stage spec [t,c,n,s,k]: s1 (1,16,1,1,3) s2 (6,24,2,2,3) s3 (6,40,2,2,5) s4 (6,80,3,2,3) s5 (6,112,3,1,5) s6 (6,192,4,2,5) s7 (6,320,1,1,3); stem 3×3-s2 (3→32), head 1×1 (320→1280)→GAP→dense. Per-block (ic, mid=t·ic, oc, r=⌈ic/4⌉, k, spatial, kind): b1 32→16 mid32 r8 k3 @112 noExp b9 80→112 mid480 r20 k5 @14 exp(no-resid) b2 16→24 mid96 r4 k3 112→56 strided b10 112→112 mid672 r28 k5 @14 resid b3 24→24 mid144 r6 k3 @56 resid b11 112→112 mid672 r28 k5 @14 resid b4 24→40 mid144 r6 k5 56→28 strided b12 112→192 mid672 r28 k5 14→7 strided b5 40→40 mid240 r10 k5 @28 resid b13 192→192 mid1152 r48 k5 @7 resid b6 40→80 mid240 r10 k3 28→14 strided b14 192→192 mid1152 r48 k5 @7 resid b7 80→80 mid480 r20 k3 @14 resid b15 192→192 mid1152 r48 k5 @7 resid b8 80→80 mid480 r20 k3 @14 resid b16 192→320 mid1152 r48 k3 @7 exp(no-resid)

Padding: the 3×3/s2 stem AND the four strided depthwises (b2, b4, b6, b12) pad at the XLA-SAME phase — TF's SAME at every strided conv, so the spec is tf_efficientnet_b0's. (Until D3, 2026-10-12, the four depthwises padded symmetrically, a hybrid neither timm net computes; scripts/parity/enet_timm_parity.py --pad hybrid still measures that distance.)

Precision is a flag on the graph. The block builders (EfficientNetStagesPC, mbExpGraphB here) choose every conv and depthwise constructor through the renderers' switch (StableHLO.PrecisionSwitch), so one graph describes the f32 artifacts (bf16 := false) and the bf16 ones (bf16 := true, the kinds efficientnetin_emarmsdp64dropdowxeps0001bf16 emits); the squeeze-excite denses, BatchNorm, swish, GAP and the classifier carry no flag because no render switches them. efficientnetFwdGraphBFull_faithful holds at either value through Bf16Erasure (the bf16 kind at the identity rounding is its f32 peer); the rounding itself is not modelled, as it is not at f32: den is over ℝ at both values.

References #

structure Proofs.EnTail (mid oc rd : ℕ) :

The tail every MBConv block shares — depthwise BatchNorm → swish → squeeze-excite → 1×1 project → project BatchNorm. MBW and MBWNoExp both extend it, so the three block kinds share one tail chain through toEnTail.

Instances For
    structure Proofs.MBW (ic mid oc r kh kw : ℕ) extends Proofs.EnTail mid oc r :

    Weights of one MBConv6 block (expand ic→mid, depthwise k×k, SE mid→r→mid, project mid→oc): the expand conv + BN and the depthwise kernel, then the shared tail.

    Instances For
      structure Proofs.MBWNoExp (ic oc r kh kw : ℕ) extends Proofs.EnTail ic oc r :

      Weights of the MBConv1 block (t=1, no expand; depthwise on ic, SE ic→r→ic, project ic→oc): the depthwise kernel, then the shared tail.

      Instances For
        structure Proofs.B0Weights (nCls : ℕ) :

        All 262 EfficientNet-B0 parameters: stem (3×3-s2 3→32) + 16 MBConv blocks (the real [t,c,n,s,k] spec) + head (1×1 320→1280) + dense (1280→nCls).

        • sW : Kernel4 32 3 3 3
        • sb : Vec 32
        • sε : ℝ
        • sγ : Vec 32
        • sβ : Vec 32
        • b1 : MBWNoExp 32 16 8 3 3
        • b2 : MBW 16 96 24 4 3 3
        • b3 : MBW 24 144 24 6 3 3
        • b4 : MBW 24 144 40 6 5 5
        • b5 : MBW 40 240 40 10 5 5
        • b6 : MBW 40 240 80 10 3 3
        • b7 : MBW 80 480 80 20 3 3
        • b8 : MBW 80 480 80 20 3 3
        • b9 : MBW 80 480 112 20 5 5
        • b10 : MBW 112 672 112 28 5 5
        • b11 : MBW 112 672 112 28 5 5
        • b12 : MBW 112 672 192 28 5 5
        • b13 : MBW 192 1152 192 48 5 5
        • b14 : MBW 192 1152 192 48 5 5
        • b15 : MBW 192 1152 192 48 5 5
        • b16 : MBW 192 1152 320 48 3 3
        • hW : Kernel4 1280 320 1 1
        • hb : Vec 1280
        • hε : ℝ
        • hγ : Vec 1280
        • hβ : Vec 1280
        • fcW : Mat 1280 nCls
        • fcb : Vec nCls
        Instances For
          structure Proofs.MBW.EpsPos {ic mid oc r kh kw : ℕ} (b : MBW ic mid oc r kh kw) :

          The three BatchNorm εs of an MBConv6 block are positive.

          Instances For
            structure Proofs.MBWNoExp.EpsPos {ic oc r kh kw : ℕ} (b : MBWNoExp ic oc r kh kw) :

            The two BatchNorm εs of the MBConv1 block are positive.

            Instances For
              structure Proofs.B0Weights.EpsPos {nCls : ℕ} (w : B0Weights nCls) :

              All 49 BatchNorm εs of EfficientNet-B0 are positive: stem, the 16 blocks, head.

              Instances For
                def Proofs.StableHLO.mbExpGraphB (p epsStr : String) {N ic mid oc h w kHd kWd r : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (γd βd : Vec mid) (Wz₁ : Mat mid r) (bz₁ : Vec r) (Wz₂ : Mat r mid) (bz₂ : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (γp βp : Vec oc) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                SHlo (N * (oc * h * w))

                MBConv6 expand + stride-1 + no-residual graph (the mbResidGraphB body without the addV skip).

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem Proofs.StableHLO.mbExpGraphB_faithful (p epsStr : String) {N ic mid oc h w kHd kWd r : ℕ} (We : Kernel4 mid ic 1 1) (be : Vec mid) (εe : ℝ) (γe βe : Vec mid) (Wd : DepthwiseKernel mid kHd kWd) (bd : Vec mid) (εd : ℝ) (γd βd : Vec mid) (Wz₁ : Mat mid r) (bz₁ : Vec r) (Wz₂ : Mat r mid) (bz₂ : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (γp βp : Vec oc) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                  den (mbExpGraphB p epsStr We be εe γe βe Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp bf16 e) = mbExpFwdB N We be εe γe βe Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp (den e)
                  noncomputable def Proofs.mbNoExpW (N h w : ℕ) {ic oc kh kw r : ℕ} (p : MBWNoExp ic oc r kh kw) :
                  Vec (N * (ic * h * w)) → Vec (N * (oc * h * w))
                  Equations
                  Instances For
                    noncomputable def Proofs.mbStridedW (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) :
                    Vec (N * (ic * (2 * h) * (2 * w))) → Vec (N * (oc * h * w))
                    Equations
                    Instances For
                      noncomputable def Proofs.mbResidW (N h w : ℕ) {c mid kh kw r : ℕ} (p : MBW c mid c r kh kw) :
                      Vec (N * (c * h * w)) → Vec (N * (c * h * w))
                      Equations
                      Instances For
                        noncomputable def Proofs.mbExpW (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) :
                        Vec (N * (ic * h * w)) → Vec (N * (oc * h * w))
                        Equations
                        Instances For
                          theorem Proofs.mbNoExpW_differentiable (N h w : ℕ) {ic oc kh kw r : ℕ} (p : MBWNoExp ic oc r kh kw) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                          noncomputable def Proofs.mbNoExpWHasVJP (N h w : ℕ) {ic oc kh kw r : ℕ} (p : MBWNoExp ic oc r kh kw) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                          HasVJP (mbNoExpW N h w p)
                          Equations
                          Instances For
                            theorem Proofs.mbStridedW_differentiable (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                            noncomputable def Proofs.mbStridedWHasVJP (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                            HasVJP (mbStridedW N h w p)
                            Equations
                            Instances For
                              theorem Proofs.mbResidW_differentiable (N h w : ℕ) {c mid kh kw r : ℕ} (p : MBW c mid c r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                              noncomputable def Proofs.mbResidWHasVJP (N h w : ℕ) {c mid kh kw r : ℕ} (p : MBW c mid c r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                              HasVJP (mbResidW N h w p)
                              Equations
                              Instances For
                                theorem Proofs.mbExpW_differentiable (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                                noncomputable def Proofs.mbExpWHasVJP (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (he : 0 < p.eε) (hd : 0 < p.dε) (hp : 0 < p.pε) :
                                HasVJP (mbExpW N h w p)
                                Equations
                                Instances For
                                  noncomputable def Proofs.efficientnetForwardBFull (N : ℕ) {nCls : ℕ} (w : B0Weights nCls) (x : Vec (N * (3 * 224 * 224))) :
                                  Vec (N * nCls)

                                  The B0 forward every B0 capstone is stated against: the stem 3×3/s2 at the XLA-SAME phase, the sixteen MBConv blocks with their four strided depthwises at that phase too (TF SAME), SE width ic/4, batch BatchNorm, then the head. No drop-path or dropout; the drop-carrying forward is EfficientNetFullB0Drop's.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    def Proofs.StableHLO.mbNoExpGraphW (pfx epsStr : String) (N h w : ℕ) {ic oc kh kw r : ℕ} (p : MBWNoExp ic oc r kh kw) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                                    SHlo (N * (oc * h * w))
                                    Equations
                                    Instances For
                                      theorem Proofs.StableHLO.mbNoExpGraphW_faithful (pfx epsStr : String) (N h w : ℕ) {ic oc kh kw r : ℕ} (p : MBWNoExp ic oc r kh kw) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                                      den (mbNoExpGraphW pfx epsStr N h w p bf16 e) = mbNoExpW N h w p (den e)
                                      def Proofs.StableHLO.mbStridedGraphW (pfx epsStr : String) (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (bf16 : Bool) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                                      SHlo (N * (oc * h * w))
                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem Proofs.StableHLO.mbStridedGraphW_faithful (pfx epsStr : String) (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (bf16 : Bool) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                                        den (mbStridedGraphW pfx epsStr N h w p bf16 e) = mbStridedW N h w p (den e)
                                        def Proofs.StableHLO.mbResidGraphW (pfx epsStr : String) (N h w : ℕ) {c mid kh kw r : ℕ} (p : MBW c mid c r kh kw) (bf16 : Bool) (e : SHlo (N * (c * h * w))) :
                                        SHlo (N * (c * h * w))
                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          theorem Proofs.StableHLO.mbResidGraphW_faithful (pfx epsStr : String) (N h w : ℕ) {c mid kh kw r : ℕ} (p : MBW c mid c r kh kw) (bf16 : Bool) (e : SHlo (N * (c * h * w))) :
                                          den (mbResidGraphW pfx epsStr N h w p bf16 e) = mbResidW N h w p (den e)
                                          def Proofs.StableHLO.mbExpGraphW (pfx epsStr : String) (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                                          SHlo (N * (oc * h * w))
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            theorem Proofs.StableHLO.mbExpGraphW_faithful (pfx epsStr : String) (N h w : ℕ) {ic mid oc kh kw r : ℕ} (p : MBW ic mid oc r kh kw) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                                            den (mbExpGraphW pfx epsStr N h w p bf16 e) = mbExpW N h w p (den e)
                                            def Proofs.StableHLO.efficientnetFwdGraphBFull (N : ℕ) (epsStr : String) {nCls : ℕ} (w : B0Weights nCls) (bf16 : Bool) (x : Vec (N * (3 * 224 * 224))) :
                                            SHlo (N * nCls)

                                            The full batched EfficientNet-B0 forward graph at the batched index N·(c·h·w): stem → 16 MBConv blocks (the real [t,c,n,s,k] spec, 3×3 and 5×5 depthwise, true batch-norm, squeeze-excite, 4 stride-2 downsamples, identity residuals where s=1 ∧ ic=oc) → head → GAP → dense. bf16 selects the conv and depthwise kinds at every site (.convAt / .convStridedXlaAt / .depthwiseAt / .depthwiseStridedXlaAt, StableHLO.PrecisionSwitch): false is the f32 artifacts' graph, true the bf16 ones'; the squeeze-excite and the dense stay f32 in both.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For
                                              theorem Proofs.StableHLO.efficientnetFwdGraphBFull_faithful (N : ℕ) (epsStr : String) {nCls : ℕ} (w : B0Weights nCls) (bf16 : Bool) (x : Vec (N * (3 * 224 * 224))) :

                                              Full batched EfficientNet-B0 forward faithfulness. The full 16-MBConv batched graph (true batch-norm + SE) denotes efficientnetForwardBFull. Chained from the per-block *GraphW_faithful lemmas (one rw per block, outermost→innermost), then a structural rfl (the forward is nested-application form, blocks opaque).

                                              noncomputable def Proofs.efficientnetForwardBFullHasVJP (N : ℕ) {nCls : ℕ} (w : B0Weights nCls) (hεw : w.EpsPos) :
                                              HasVJP (headFwdB N w.hW w.hb w.hε w.hγ w.hβ w.fcW w.fcb ∘ mbExpW N 7 7 w.b16 ∘ mbResidW N 7 7 w.b15 ∘ mbResidW N 7 7 w.b14 ∘ mbResidW N 7 7 w.b13 ∘ mbStridedW N 7 7 w.b12 ∘ mbResidW N 14 14 w.b11 ∘ mbResidW N 14 14 w.b10 ∘ mbExpW N 14 14 w.b9 ∘ mbResidW N 14 14 w.b8 ∘ mbResidW N 14 14 w.b7 ∘ mbStridedW N 14 14 w.b6 ∘ mbResidW N 28 28 w.b5 ∘ mbStridedW N 28 28 w.b4 ∘ mbResidW N 56 56 w.b3 ∘ mbStridedW N 56 56 w.b2 ∘ mbNoExpW N 112 112 w.b1 ∘ stemB N w.sW w.sb w.sε w.sγ w.sβ)

                                              The full EfficientNet-B0 has a (correct) VJP. Chained from the per-block gradients (stem → 16 MBConv blocks → head) via vjpComp. Stated on the ∘-composition of the blocks (= the full forward by construction; keeps the blocks opaque so the chain closes structurally). The full-depth, batched, true-batch-norm + SE analogue of efficientnetHasVJP.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For
                                                theorem Proofs.efficientnetForwardBFull_eq_chain (N : ℕ) {nCls : ℕ} (w : B0Weights nCls) (x : Vec (N * (3 * 224 * 224))) :
                                                efficientnetForwardBFull N w x = (headFwdB N w.hW w.hb w.hε w.hγ w.hβ w.fcW w.fcb ∘ mbExpW N 7 7 w.b16 ∘ mbResidW N 7 7 w.b15 ∘ mbResidW N 7 7 w.b14 ∘ mbResidW N 7 7 w.b13 ∘ mbStridedW N 7 7 w.b12 ∘ mbResidW N 14 14 w.b11 ∘ mbResidW N 14 14 w.b10 ∘ mbExpW N 14 14 w.b9 ∘ mbResidW N 14 14 w.b8 ∘ mbResidW N 14 14 w.b7 ∘ mbStridedW N 14 14 w.b6 ∘ mbResidW N 28 28 w.b5 ∘ mbStridedW N 28 28 w.b4 ∘ mbResidW N 56 56 w.b3 ∘ mbStridedW N 56 56 w.b2 ∘ mbNoExpW N 112 112 w.b1 ∘ stemB N w.sW w.sb w.sε w.sγ w.sβ) x

                                                efficientnetForwardBFull = the ∘-chain of the VJP's statement — the kernel-checked bridge between the nested-application and composition forms, closing the form-gap this file shipped with. PROOF-SHAPE MATTERS (the ConvNeXt-T convNextForwardTCh_eq_chain lesson): equation-lemma rw + 17 comp_apply rewrites close syntactically; a simp/rfl proof of the same statement makes the kernel reduce the block bodies (no reducibility, no defeq cache) and deterministically time out.

                                                theorem Proofs.efficientnetForwardBFullHasVJP_correct (N : ℕ) {nCls : ℕ} (w : B0Weights nCls) (hεw : w.EpsPos) (x : Vec (N * (3 * 224 * 224))) (dy : Vec (N * nCls)) (i : Fin (N * (3 * 224 * 224))) :
                                                (efficientnetForwardBFullHasVJP N w hεw).backward x dy i = ∑ j : Fin (N * nCls), pdiv (efficientnetForwardBFull N w) x i j * dy j

                                                The .correct field of efficientnetForwardBFullHasVJP, restated at the nested forward efficientnetForwardBFull through efficientnetForwardBFull_eq_chain: its backward is the pdiv-contracted Jacobian at every input. The tie of the hand-written input-gradient chain to this backward is efficientnetInputGradBFull_eq_efficientnetForwardB_full_vjp.