Documentation

LeanMlir.Proofs.Codegen.EfficientNetRenderPC

Item A — the BATCHED EfficientNet-B0 forward graph (true batch-norm, matches the render) #

The EfficientNet peer of MobileNetV2RenderPC.lean / ResNet34RenderPC.lean — but EfficientNet's operational render (tests/TestEfficientNetFwd.lean) emits true batch-norm (reduce μ/var over the batch+spatial axes [0,2,3] per channel — bnBatchTensor4), which couples the batch. MNV2/r34 get away with a batch-1 den because their per-channel BN reduces [2,3] (per-example, separable); EfficientNet's does not. So the forward graph here genuinely lives at the batched index N·(c·h·w) (StableHLO.batchOp/StableHLO.bnBatchF, StableHLO.lean):

We prove the FORWARD half — den (graph) = forward — for a representative EfficientNet-B0 that structurally exercises every element of B0: the stride-2 stem conv-bn-swish, an MBConv1 (t=1, no expand) SE block, an MBConv6 expand SE block with a stride-2 downsample (3×3 depthwise), an MBConv6 expand SE block with a 5×5 depthwise and an identity residual skip, the 1×1 conv-bn-swish head, GAP and the dense classifier — all with true batch-norm and the squeeze-excite gate (seBlockFull). Squeeze-excite is the genuinely-new structure; here it enters as BatchableOp.seBlock (= batchMap N seBlockFull).

Like ResNet34RenderPC, faithfulness is per-block (*GraphB_faithful: den (block graph) = block forward (den input)), then chained — so the kernel never reduces the whole net at once. 3-axiom clean. (The full 16-MBConv [t,c,n,s,k] enumeration is mechanical repetition of these block abbreviations; the structural + batched-infra content — the batched graph, true batch-norm, SE — is here. The structured render is Item B; the SE/BN cotangent chain is Item D.)

@[reducible]
noncomputable def Proofs.cbsB (N : ) {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (ε : ) (γ β : Vec oc) :
Vec (N * (ic * h * w))Vec (N * (oc * h * w))

Batched conv → bn → swish (1×1 expand / generic stride-1 conv).

Equations
Instances For
    noncomputable def Proofs.stemB (N : ) {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (ε : ) (γ β : Vec oc) :
    Vec (N * (ic * (2 * h) * (2 * w)))Vec (N * (oc * h * w))

    Batched strided (3×3 s2) stem conv → bn → swish (halves spatial). ⚠ At the XLA-SAME phase (flatConvStride2Xla = decimateOddFlat ∘ flatConv): the TF-origin B0 pads its stem (0,1), and the shipped render has emitted convStridedXla there since 2026-08-08. The symmetric flatConvStride2 has the same type and output shape; nothing structural would notice the wrong one (re-spelled 2026-09-05, planning/archive/xla_same_respell_and_blueprint_audit.md).

    Equations
    Instances For
      @[reducible]
      noncomputable def Proofs.dwbsB (N : ) {c h w kH kW : } (W : DepthwiseKernel c kH kW) (b : Vec c) (ε : ) (γ β : Vec c) :
      Vec (N * (c * h * w))Vec (N * (c * h * w))

      Batched depthwise (stride-1, k×k) → bn → swish.

      Equations
      Instances For
        @[reducible]
        noncomputable def Proofs.dwbsSB (N : ) {c h w kH kW : } (W : DepthwiseKernel c kH kW) (b : Vec c) (ε : ) (γ β : Vec c) :
        Vec (N * (c * (2 * h) * (2 * w)))Vec (N * (c * h * w))

        Batched depthwise (stride-2 downsample, k×k) → bn → swish.

        Equations
        Instances For
          @[reducible]
          noncomputable def Proofs.seB (N : ) {c h w r : } (W₁ : Mat c r) (b₁ : Vec r) (W₂ : Mat r c) (b₂ : Vec c) :
          Vec (N * (c * h * w))Vec (N * (c * h * w))

          Batched squeeze-excite block x ⊙ gate(x) (the proven seBlockFull, per example).

          Equations
          Instances For
            @[reducible]
            noncomputable def Proofs.projB (N : ) {ic oc h w kH kW : } (W : Kernel4 oc ic kH kW) (b : Vec oc) (ε : ) (γ β : Vec oc) :
            Vec (N * (ic * h * w))Vec (N * (oc * h * w))

            Batched project: 1×1 conv → bn (no swish — the linear bottleneck).

            Equations
            Instances For
              noncomputable def Proofs.mbNoExpFwdB (N : ) {ic oc h w kHd kWd r : } (Wd : DepthwiseKernel ic kHd kWd) (bd : Vec ic) (εd : ) (γd βd : Vec ic) (Wz₁ : Mat ic r) (bz₁ : Vec r) (Wz₂ : Mat r ic) (bz₂ : Vec ic) (Wp : Kernel4 oc ic 1 1) (bp : Vec oc) (εp : ) (γp βp : Vec oc) :
              Vec (N * (ic * h * w))Vec (N * (oc * h * w))

              MBConv1 (t=1, no expand): depthwise-bn-swish → SE → project-bn. No residual (ic ≠ oc).

              Equations
              Instances For
                noncomputable def Proofs.mbStridedFwdB (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) :
                Vec (N * (ic * (2 * h) * (2 * w)))Vec (N * (oc * h * w))

                MBConv6 with a stride-2 downsample: expand-bn-swish (at 2h×2w) → strided depthwise-bn-swish → SE → project-bn. No residual (spatial changes).

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  noncomputable def Proofs.mbResidFwdB (N : ) {c mid h w kHd kWd r : } (We : Kernel4 mid c 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 c mid 1 1) (bp : Vec c) (εp : ) (γp βp : Vec c) :
                  Vec (N * (c * h * w))Vec (N * (c * h * w))

                  MBConv6 with an identity residual skip (s=1 ∧ ic=oc=c): x + (project ∘ SE ∘ depthwise ∘ expand)(x).

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    noncomputable def Proofs.headFwdB (N : ) {c oc h w nC : } (Wh : Kernel4 oc c 1 1) (bh : Vec oc) (εh : ) (γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) :
                    Vec (N * (c * h * w))Vec (N * nC)

                    Head: 1×1 conv-bn-swish → global-avg-pool → dense classifier, all batched.

                    Equations
                    Instances For
                      noncomputable def Proofs.efficientnetForwardB (N : ) (Ws : Kernel4 32 3 3 3) (bs : Vec 32) (εs : ) (γs βs : Vec 32) (Wd1 : DepthwiseKernel 32 3 3) (bd1 : Vec 32) (εd1 : ) (γd1 βd1 : Vec 32) (Wz1a : Mat 32 8) (bz1a : Vec 8) (Wz1b : Mat 8 32) (bz1b : Vec 32) (Wp1 : Kernel4 16 32 1 1) (bp1 : Vec 16) (εp1 : ) (γp1 βp1 : Vec 16) (We2 : Kernel4 96 16 1 1) (be2 : Vec 96) (εe2 : ) (γe2 βe2 : Vec 96) (Wd2 : DepthwiseKernel 96 3 3) (bd2 : Vec 96) (εd2 : ) (γd2 βd2 : Vec 96) (Wz2a : Mat 96 4) (bz2a : Vec 4) (Wz2b : Mat 4 96) (bz2b : Vec 96) (Wp2 : Kernel4 24 96 1 1) (bp2 : Vec 24) (εp2 : ) (γp2 βp2 : Vec 24) (We3 : Kernel4 144 24 1 1) (be3 : Vec 144) (εe3 : ) (γe3 βe3 : Vec 144) (Wd3 : DepthwiseKernel 144 5 5) (bd3 : Vec 144) (εd3 : ) (γd3 βd3 : Vec 144) (Wz3a : Mat 144 6) (bz3a : Vec 6) (Wz3b : Mat 6 144) (bz3b : Vec 144) (Wp3 : Kernel4 24 144 1 1) (bp3 : Vec 24) (εp3 : ) (γp3 βp3 : Vec 24) (Wh : Kernel4 1280 24 1 1) (bh : Vec 1280) (εh : ) (γh βh : Vec 1280) (Wfc : Mat 1280 10) (bfc : Vec 10) (x : Vec (N * (3 * 224 * 224))) :
                      Vec (N * 10)
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        def Proofs.StableHLO.stemGraphB (epsStr : String) {N ic oc h w : } (Ws : Kernel4 oc ic 3 3) (bs : Vec oc) (εs : ) (γs βs : Vec oc) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                        SHlo (N * (oc * h * w))

                        Stem 3×3-s2 conv → bn → swish, batched.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem Proofs.StableHLO.stemGraphB_faithful (epsStr : String) {N ic oc h w : } (Ws : Kernel4 oc ic 3 3) (bs : Vec oc) (εs : ) (γs βs : Vec oc) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                          den (stemGraphB epsStr Ws bs εs γs βs e) = stemB N Ws bs εs γs βs (den e)
                          def Proofs.StableHLO.mbNoExpGraphB (p epsStr : String) {N ic oc h w kHd kWd r : } (Wd : DepthwiseKernel ic kHd kWd) (bd : Vec ic) (εd : ) (γd βd : Vec ic) (Wz₁ : Mat ic r) (bz₁ : Vec r) (Wz₂ : Mat r ic) (bz₂ : Vec ic) (Wp : Kernel4 oc ic 1 1) (bp : Vec oc) (εp : ) (γp βp : Vec oc) (e : SHlo (N * (ic * h * w))) :
                          SHlo (N * (oc * h * w))

                          MBConv1 (no expand): dw-bn-swish → SE → project-bn, batched.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem Proofs.StableHLO.mbNoExpGraphB_faithful (p epsStr : String) {N ic oc h w kHd kWd r : } (Wd : DepthwiseKernel ic kHd kWd) (bd : Vec ic) (εd : ) (γd βd : Vec ic) (Wz₁ : Mat ic r) (bz₁ : Vec r) (Wz₂ : Mat r ic) (bz₂ : Vec ic) (Wp : Kernel4 oc ic 1 1) (bp : Vec oc) (εp : ) (γp βp : Vec oc) (e : SHlo (N * (ic * h * w))) :
                            den (mbNoExpGraphB p epsStr Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp e) = mbNoExpFwdB N Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp (den e)
                            def Proofs.StableHLO.mbStridedGraphB (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) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                            SHlo (N * (oc * h * w))

                            MBConv6 strided: expand-bn-swish (at 2h×2w) → strided dw-bn-swish → SE → project-bn, batched.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              theorem Proofs.StableHLO.mbStridedGraphB_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) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                              den (mbStridedGraphB p epsStr We be εe γe βe Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp e) = mbStridedFwdB N We be εe γe βe Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp (den e)
                              def Proofs.StableHLO.mbResidGraphB (p epsStr : String) {N c mid h w kHd kWd r : } (We : Kernel4 mid c 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 c mid 1 1) (bp : Vec c) (εp : ) (γp βp : Vec c) (e : SHlo (N * (c * h * w))) :
                              SHlo (N * (c * h * w))

                              MBConv6 with identity residual: addV body skip, body = project ∘ SE ∘ dw ∘ expand, batched.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                theorem Proofs.StableHLO.mbResidGraphB_faithful (p epsStr : String) {N c mid h w kHd kWd r : } (We : Kernel4 mid c 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 c mid 1 1) (bp : Vec c) (εp : ) (γp βp : Vec c) (e : SHlo (N * (c * h * w))) :
                                den (mbResidGraphB p epsStr We be εe γe βe Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp e) = mbResidFwdB N We be εe γe βe Wd bd εd γd βd Wz₁ bz₁ Wz₂ bz₂ Wp bp εp γp βp (den e)
                                def Proofs.StableHLO.headGraphB (epsStr : String) {N c oc h w nC : } (Wh : Kernel4 oc c 1 1) (bh : Vec oc) (εh : ) (γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (e : SHlo (N * (c * h * w))) :
                                SHlo (N * nC)

                                Head: 1×1 conv-bn-swish → GAP → dense, batched.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  theorem Proofs.StableHLO.headGraphB_faithful (epsStr : String) {N c oc h w nC : } (Wh : Kernel4 oc c 1 1) (bh : Vec oc) (εh : ) (γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (e : SHlo (N * (c * h * w))) :
                                  den (headGraphB epsStr Wh bh εh γh βh Wfc bfc e) = headFwdB N Wh bh εh γh βh Wfc bfc (den e)
                                  def Proofs.StableHLO.efficientnetFwdGraphB (N : ) (epsStr : String) (Ws : Kernel4 32 3 3 3) (bs : Vec 32) (εs : ) (γs βs : Vec 32) (Wd1 : DepthwiseKernel 32 3 3) (bd1 : Vec 32) (εd1 : ) (γd1 βd1 : Vec 32) (Wz1a : Mat 32 8) (bz1a : Vec 8) (Wz1b : Mat 8 32) (bz1b : Vec 32) (Wp1 : Kernel4 16 32 1 1) (bp1 : Vec 16) (εp1 : ) (γp1 βp1 : Vec 16) (We2 : Kernel4 96 16 1 1) (be2 : Vec 96) (εe2 : ) (γe2 βe2 : Vec 96) (Wd2 : DepthwiseKernel 96 3 3) (bd2 : Vec 96) (εd2 : ) (γd2 βd2 : Vec 96) (Wz2a : Mat 96 4) (bz2a : Vec 4) (Wz2b : Mat 4 96) (bz2b : Vec 96) (Wp2 : Kernel4 24 96 1 1) (bp2 : Vec 24) (εp2 : ) (γp2 βp2 : Vec 24) (We3 : Kernel4 144 24 1 1) (be3 : Vec 144) (εe3 : ) (γe3 βe3 : Vec 144) (Wd3 : DepthwiseKernel 144 5 5) (bd3 : Vec 144) (εd3 : ) (γd3 βd3 : Vec 144) (Wz3a : Mat 144 6) (bz3a : Vec 6) (Wz3b : Mat 6 144) (bz3b : Vec 144) (Wp3 : Kernel4 24 144 1 1) (bp3 : Vec 24) (εp3 : ) (γp3 βp3 : Vec 24) (Wh : Kernel4 1280 24 1 1) (bh : Vec 1280) (εh : ) (γh βh : Vec 1280) (Wfc : Mat 1280 10) (bfc : Vec 10) (x : Vec (N * (3 * 224 * 224))) :
                                  SHlo (N * 10)

                                  The representative batched EfficientNet-B0 forward graph at the batched index N·(c·h·w): stem → MBConv1(no-exp) → MBConv6(strided 3×3) → MBConv6(5×5, residual) → head. Every spatial op is batchOp; true batch-norm is bnBatchF; pointwise swish is swishF; the residual is addV. Built by composing the per-block graphs; denotes efficientnetForwardB.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    theorem Proofs.StableHLO.efficientnetFwdGraphB_faithful (N : ) (epsStr : String) (Ws : Kernel4 32 3 3 3) (bs : Vec 32) (εs : ) (γs βs : Vec 32) (Wd1 : DepthwiseKernel 32 3 3) (bd1 : Vec 32) (εd1 : ) (γd1 βd1 : Vec 32) (Wz1a : Mat 32 8) (bz1a : Vec 8) (Wz1b : Mat 8 32) (bz1b : Vec 32) (Wp1 : Kernel4 16 32 1 1) (bp1 : Vec 16) (εp1 : ) (γp1 βp1 : Vec 16) (We2 : Kernel4 96 16 1 1) (be2 : Vec 96) (εe2 : ) (γe2 βe2 : Vec 96) (Wd2 : DepthwiseKernel 96 3 3) (bd2 : Vec 96) (εd2 : ) (γd2 βd2 : Vec 96) (Wz2a : Mat 96 4) (bz2a : Vec 4) (Wz2b : Mat 4 96) (bz2b : Vec 96) (Wp2 : Kernel4 24 96 1 1) (bp2 : Vec 24) (εp2 : ) (γp2 βp2 : Vec 24) (We3 : Kernel4 144 24 1 1) (be3 : Vec 144) (εe3 : ) (γe3 βe3 : Vec 144) (Wd3 : DepthwiseKernel 144 5 5) (bd3 : Vec 144) (εd3 : ) (γd3 βd3 : Vec 144) (Wz3a : Mat 144 6) (bz3a : Vec 6) (Wz3b : Mat 6 144) (bz3b : Vec 144) (Wp3 : Kernel4 24 144 1 1) (bp3 : Vec 24) (εp3 : ) (γp3 βp3 : Vec 24) (Wh : Kernel4 1280 24 1 1) (bh : Vec 1280) (εh : ) (γh βh : Vec 1280) (Wfc : Mat 1280 10) (bfc : Vec 10) (x : Vec (N * (3 * 224 * 224))) :
                                    den (efficientnetFwdGraphB N epsStr Ws bs εs γs βs Wd1 bd1 εd1 γd1 βd1 Wz1a bz1a Wz1b bz1b Wp1 bp1 εp1 γp1 βp1 We2 be2 εe2 γe2 βe2 Wd2 bd2 εd2 γd2 βd2 Wz2a bz2a Wz2b bz2b Wp2 bp2 εp2 γp2 βp2 We3 be3 εe3 γe3 βe3 Wd3 bd3 εd3 γd3 βd3 Wz3a bz3a Wz3b bz3b Wp3 bp3 εp3 γp3 βp3 Wh bh εh γh βh Wfc bfc x) = efficientnetForwardB N Ws bs εs γs βs Wd1 bd1 εd1 γd1 βd1 Wz1a bz1a Wz1b bz1b Wp1 bp1 εp1 γp1 βp1 We2 be2 εe2 γe2 βe2 Wd2 bd2 εd2 γd2 βd2 Wz2a bz2a Wz2b bz2b Wp2 bp2 εp2 γp2 βp2 We3 be3 εe3 γe3 βe3 Wd3 bd3 εd3 γd3 βd3 Wz3a bz3a Wz3b bz3b Wp3 bp3 εp3 γp3 βp3 Wh bh εh γh βh Wfc bfc x

                                    Batched EfficientNet-B0 forward faithfulness. The batched render graph (true batch-norm + SE, at index N·(c·h·w)) denotes efficientnetForwardB. Chained from the per-block *GraphB_faithful lemmas (each fires as a simp rewrite, so the kernel never reduces the whole net at once) — the ResNet34RenderPC recipe lifted to the batched index. The "text = render of a proven forward graph" half for EfficientNet at the render's genuine (batch-coupled) BN flavor.