Documentation

LeanMlir.Proofs.Nets.MobileNet.MobileNetV2FullB

MobileNetV2 at batch BatchNorm — the whole net's forward and graph #

The MobileNetV2 peer of ResNet34FullB.lean. mobilenetv2ForwardBFull is the seventeen-bottleneck net at batch BatchNorm (bnBatchLA, the proven bnBatchTensor4 at the network's left-assoc index; reduce [0,2,3]: one mean/variance per channel across the batch, the one op that couples examples), which is the forward MobileNetV2RenderB emits for mobilenetv2_fwd, mobilenetv2in_fwd and the f32 train steps. mobilenetv2FwdGraphBFull is its typed graph and mobilenetv2FwdGraphBFull_faithful ties the two.

What this file adds #

The batched relu6 stages (cbrB, dwbrB, dwbrBstrided in Batched.StageLayers, projB in Batched.Stages), their _at VJPs and their backward-graph faithfulness are one level down, all at bnBatchLA; MobileNetV2BackB0.lean composes them into block bodies. This file adds the net-level ℝ forward, the net-level forward graph, and the faithfulness tying them.

The block weight records IVW / IVWNoExp come from MobileNetV2FullPaper.lean; only the top-level bundle MNV2BWeights is declared here, generic in the class count.

Padding is XLA-SAME at all five stride-2 sites — the stem 3x3/s2 conv and the four stride-2 depthwises (b2, b4, b7, b14). These are flatConvStride2Xla / depthwiseStride2FlatXla, not r34's symmetric flatConvStride2 peers; the two families have identical types and identical emitted shapes, so only the certificate distinguishes them, and MobileNetV2 is the TF-origin net. scripts/gates/convention_audit.py checks this at the artifact level.

There is no max-pool. MobileNetV2's stem is conv-BN-relu6 and downsamples once; r34's stem is conv-BN-relu, then a 3x3/s2 pool. That is why this net needs no batchMapHasVJPAt.

Precision is a flag on the graph. Every conv and depthwise site is .convAt bf16 id … / .convStridedXlaAt … / .depthwiseAt … / .depthwiseStridedXlaAt … (StableHLO.PrecisionSwitch, the renderers' own switch), so one builder describes the f32 artifacts (bf16 := false) and the bf16 ones (bf16 := true, the kinds mobilenetv2in_rmsdp64wxdols0eps0001bf16 emits); BatchNorm, relu6, GAP and the dense carry no flag because no render switches them. The faithfulness theorems hold at either value through Bf16Erasure (Bf16Fold.denOp_convAt_id, …: the bf16 kind at the identity rounding is its f32 peer), so the typed graph denotes mobilenetv2ForwardBFull whichever precision the text declares. The rounding itself is not modelled here, as it is not at f32: den is over ℝ at both values.

Conventions this net runs at #

depth17 bottlenecks, the paper [t,c,n,s] table, stem 32 to head 1280
BatchNormbatch (bnBatchLA, reduce [0,2,3], width N*h*w), 52 sites
activationrelu6 (TWO kinks, at 0 and at 6); 35 sites, none after a project
stride-2 paddingXLA-SAME at all five sites
stem3x3/s2 conv-bn-relu6, 3 to 32, 224 to 112 (NO pool)
head1x1 conv-bn-relu6 320 to 1280, then GAP and dense, generic in the class count
artifactsmobilenetv2_fwd, mobilenetv2in_fwd and the train steps at either precision (bf16 selects the conv / depthwise kinds); the classifier-dropout variants mobilenetv2in_rmsdp64wxdols0* are mobilenetv2FwdGraphBFullDo below (a %do operand; at the all-ones mask this net's forward, mobilenetv2ForwardBFullDo_ones). Not this graph: the frozen-statistics evals (mobilenetv2{,in}_fwd_eval*, stated in MobileNetV2FullPaperEval)

The head is generic in nCls, so one statement covers the 10-class Imagenette artifacts and the 1000-class mobilenetv2in ones.

N stays a variable throughout. On the data-parallel artifacts the render's N is the per-replica batch and BatchNorm is synchronised across replicas; MobileNetV2SyncB.lean is this file's twin for them: replica r's forward graph denotes shard r of mobilenetv2ForwardBFull (R * N), this file's forward at the global batch.

The bias operand names are the render's default convBias := false ones — %zb{c}, the shared zero constant each conv, depthwise and project bias is bound to once its real bias has been folded into the BatchNorm that follows it. That is what makes the shipped parameter census 158 and not 210. Every graph below is ∀-quantified over the bias VALUE, so it covers the convBias := true render too; only the name would differ there.

References #

structure Proofs.MNV2BWeights (nCls : ℕ) :

Every paper-spec MobileNetV2 parameter: stem (3x3/s2, 3 to 32) + the 17 bottlenecks of the [t,c,n,s] table + the 1x1 head (320 to 1280) + the dense classifier. Generic in nCls, so one record covers the 10-class (mobilenetv2_*) and 1000-class (mobilenetv2in_*) artifacts.

Instances For
    @[reducible]
    noncomputable def Proofs.mnv2StemB (N h w : ℕ) {ic oc kH kW : ℕ} (Ws : Kernel4 oc ic kH kW) (bs : Vec oc) (εs : ℝ) (γs βs : Vec oc) :
    Vec (N * (ic * (2 * h) * (2 * w))) → Vec (N * (oc * h * w))

    Batched stem: 3x3/s2 XLA-SAME conv -> batch BN -> relu6. MobileNetV2 has no stem pool.

    Equations
    Instances For
      @[reducible]
      noncomputable def Proofs.mnv2NoExpB (N h w : ℕ) {ic oc : ℕ} (p : IVWNoExp ic oc) :
      Vec (N * (ic * h * w)) → Vec (N * (oc * h * w))

      Batched t = 1 first bottleneck (b1): depthwise-bn-relu6 then the linear-bottleneck project. No expand conv, no skip. The one block shape with no mnv2*BodyB lemma to delegate to.

      Equations
      Instances For
        @[reducible]
        noncomputable def Proofs.mnv2ExpOnlyB (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) :
        Vec (N * (ic * h * w)) → Vec (N * (oc * h * w))

        Batched stride-1 inverted-residual BODY, no skip (ic ≠ oc; b11, b17): projB ∘ dwbrB ∘ cbrB.

        Equations
        Instances For
          @[reducible]
          noncomputable def Proofs.mnv2ResidB (N h w : ℕ) {c mid : ℕ} (p : IVW c mid c) :
          Vec (N * (c * h * w)) → Vec (N * (c * h * w))

          Batched stride-1 inverted residual WITH the identity skip (s = 1 ∧ ic = oc). The residual add is the block output — unlike ResNet, there is no relu after it, which is why a MobileNetV2 block carries two kink clauses and not three.

          Equations
          Instances For
            @[reducible]
            noncomputable def Proofs.mnv2StridedB (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) :
            Vec (N * (ic * (2 * h) * (2 * w))) → Vec (N * (oc * h * w))

            Batched stride-2 downsampling bottleneck (no skip): expand at 2h x 2w, the XLA-SAME strided depthwise halving spatial, then project at h x w.

            Equations
            Instances For
              @[reducible]
              noncomputable def Proofs.mnv2HeadB (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) :
              Vec (N * (ic * h * w)) → Vec (N * nCls)

              Batched head: 1x1 conv-bn-relu6 (ic to oc), global average pool, dense classifier.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                noncomputable def Proofs.mobilenetv2ForwardBFull (N : ℕ) {nCls : ℕ} (w : MNV2BWeights nCls) (x : Vec (N * (3 * (2 * 112) * (2 * 112)))) :
                Vec (N * nCls)

                The full batch-BN MobileNetV2 forward, N*(3*224*224) -> N*nCls, in nested-application form, as resnet34ForwardBFull and efficientnetForwardBFull both are, so the whole-net tie (MobileNetV2WholeBackCertifiedTieB) can peel it one block at a time.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  noncomputable def Proofs.mnv2HeadBDo (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (m : Vec (N * oc)) :
                  Vec (N * (ic * h * w)) → Vec (N * nCls)

                  Batched head with classifier dropout at the mask m: mnv2HeadB with dropout m on the dense's input.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Proofs.mnv2HeadBDo_ones (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) :
                    (mnv2HeadBDo N h w Wh bh εh γh βh Wd bd fun (x : Fin (N * oc)) => 1) = mnv2HeadB N h w Wh bh εh γh βh Wd bd
                    noncomputable def Proofs.mobilenetv2ForwardBFullDo (N : ℕ) {nCls : ℕ} (w : MNV2BWeights nCls) (m : Vec (N * 1280)) (x : Vec (N * (3 * (2 * 112) * (2 * 112)))) :
                    Vec (N * nCls)

                    The MobileNetV2 forward with classifier dropout at the per-element mask m (the driver's inverted mask, %do).

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem Proofs.mobilenetv2ForwardBFullDo_ones (N : ℕ) {nCls : ℕ} (w : MNV2BWeights nCls) (x : Vec (N * (3 * (2 * 112) * (2 * 112)))) :
                      mobilenetv2ForwardBFullDo N w (fun (x : Fin (N * 1280)) => 1) x = mobilenetv2ForwardBFull N w x

                      At the all-ones mask the dropout forward is the certified forward.

                      def Proofs.StableHLO.mnv2StemGraphB (epsStr : String) (N h w : ℕ) {ic oc kH kW : ℕ} (Ws : Kernel4 oc ic kH kW) (bs : Vec oc) (εs : ℝ) (γs βs : Vec oc) (bf16 : Bool) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                      SHlo (N * (oc * h * w))

                      Stem graph: 3x3/s2 XLA-SAME conv -> batch BN -> relu6.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        theorem Proofs.StableHLO.mnv2StemGraphB_faithful (epsStr : String) (N h w : ℕ) {ic oc kH kW : ℕ} (Ws : Kernel4 oc ic kH kW) (bs : Vec oc) (εs : ℝ) (γs βs : Vec oc) (bf16 : Bool) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                        den (mnv2StemGraphB epsStr N h w Ws bs εs γs βs bf16 e) = mnv2StemB N h w Ws bs εs γs βs (den e)
                        def Proofs.StableHLO.mnv2NoExpGraphB (pfx epsStr : String) (N h w : ℕ) {ic oc : ℕ} (p : IVWNoExp ic oc) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                        SHlo (N * (oc * h * w))

                        t = 1 bottleneck graph (b1): depthwise -> BN -> relu6 -> project 1x1 -> BN.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem Proofs.StableHLO.mnv2NoExpGraphB_faithful (pfx epsStr : String) (N h w : ℕ) {ic oc : ℕ} (p : IVWNoExp ic oc) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                          den (mnv2NoExpGraphB pfx epsStr N h w p bf16 e) = mnv2NoExpB N h w p (den e)
                          def Proofs.StableHLO.mnv2ExpOnlyGraphB (pfx epsStr : String) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                          SHlo (N * (oc * h * w))

                          Stride-1 no-skip bottleneck graph (b11, b17): expand -> depthwise -> project, batch BN after each, relu6 after the first two.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem Proofs.StableHLO.mnv2ExpOnlyGraphB_faithful (pfx epsStr : String) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                            den (mnv2ExpOnlyGraphB pfx epsStr N h w p bf16 e) = mnv2ExpOnlyB N h w p (den e)
                            def Proofs.StableHLO.mnv2ResidGraphB (pfx epsStr : String) (N h w : ℕ) {c mid : ℕ} (p : IVW c mid c) (bf16 : Bool) (e : SHlo (N * (c * h * w))) :
                            SHlo (N * (c * h * w))

                            Stride-1 skip bottleneck graph: the body plus the addVB identity skip, the block-input subtree e shared between both arms as the render emits it.

                            Equations
                            Instances For
                              theorem Proofs.StableHLO.mnv2ResidGraphB_faithful (pfx epsStr : String) (N h w : ℕ) {c mid : ℕ} (p : IVW c mid c) (bf16 : Bool) (e : SHlo (N * (c * h * w))) :
                              den (mnv2ResidGraphB pfx epsStr N h w p bf16 e) = mnv2ResidB N h w p (den e)
                              def Proofs.StableHLO.mnv2StridedGraphB (pfx epsStr : String) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (bf16 : Bool) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                              SHlo (N * (oc * h * w))

                              Stride-2 downsampling bottleneck graph: expand at 2h x 2w, XLA-SAME strided depthwise, project at h x w.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                theorem Proofs.StableHLO.mnv2StridedGraphB_faithful (pfx epsStr : String) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (bf16 : Bool) (e : SHlo (N * (ic * (2 * h) * (2 * w)))) :
                                den (mnv2StridedGraphB pfx epsStr N h w p bf16 e) = mnv2StridedB N h w p (den e)
                                def Proofs.StableHLO.mnv2HeadGraphB (epsStr : String) (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                                SHlo (N * nCls)

                                Head graph: 1x1 conv -> batch BN -> relu6 -> GAP -> dense.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  theorem Proofs.StableHLO.mnv2HeadGraphB_faithful (epsStr : String) (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (e : SHlo (N * (ic * h * w))) :
                                  den (mnv2HeadGraphB epsStr N h w Wh bh εh γh βh Wd bd bf16 e) = mnv2HeadB N h w Wh bh εh γh βh Wd bd (den e)
                                  def Proofs.StableHLO.mobilenetv2FwdGraphBFull (N : ℕ) (epsStr : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (e : SHlo (N * (3 * (2 * 112) * (2 * 112)))) :
                                  SHlo (N * nCls)

                                  The full batch-BN MobileNetV2 forward graph. Block prefixes are the render's (b1 … b17, each parameter %b{k}{e,d,p}{W,g,bt}), so the typed graph diffs against mobilenetv2_adam_train_step's forward half name for name. bf16 selects the conv and depthwise kinds at every site (.convAt / .convStridedXlaAt / .depthwiseAt / .depthwiseStridedXlaAt).

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    theorem Proofs.StableHLO.mobilenetv2FwdGraphBFull_faithful (N : ℕ) (epsStr : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (e : SHlo (N * (3 * (2 * 112) * (2 * 112)))) :

                                    The MobileNetV2 forward graph at batch BN denotes the whole-net forward. One rw per block over the six per-kind faithfulness lemmas.

                                    def Proofs.StableHLO.mnv2HeadGraphBDo (epsStr mName : String) (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (m : Vec (N * oc)) (e : SHlo (N * (ic * h * w))) :
                                    SHlo (N * nCls)

                                    Head graph with classifier dropout: mnv2HeadGraphB with a dropoutB on the dense's input, its mask the input mName (the render's is doName).

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      theorem Proofs.StableHLO.mnv2HeadGraphBDo_faithful (epsStr mName : String) (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (m : Vec (N * oc)) (e : SHlo (N * (ic * h * w))) :
                                      den (mnv2HeadGraphBDo epsStr mName N h w Wh bh εh γh βh Wd bd bf16 m e) = mnv2HeadBDo N h w Wh bh εh γh βh Wd bd m (den e)
                                      def Proofs.StableHLO.mobilenetv2FwdGraphBFullDo (N : ℕ) (epsStr mName : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (m : Vec (N * 1280)) (e : SHlo (N * (3 * (2 * 112) * (2 * 112)))) :
                                      SHlo (N * nCls)

                                      The %do forward graph: mobilenetv2FwdGraphBFull with the dropout head.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem Proofs.StableHLO.mobilenetv2FwdGraphBFullDo_faithful (N : ℕ) (epsStr mName : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (m : Vec (N * 1280)) (e : SHlo (N * (3 * (2 * 112) * (2 * 112)))) :
                                        den (mobilenetv2FwdGraphBFullDo N epsStr mName w bf16 m e) = mobilenetv2ForwardBFullDo N w m (den e)

                                        The %do forward graph denotes the dropout forward, at every mask — the trunk by the same per-block rewrites as mobilenetv2FwdGraphBFull_faithful.