Documentation

LeanMlir.Proofs.Nets.MobileNet.MobileNetV4SyncB

MobileNetV4-Conv-M's data-parallel forward at synchronised BatchNorm — replica r is shard r #

MobileNetV4FullB.lean says the typed batch-BN graph denotes mobilenetv4ForwardBFull N w on one device. MobileNetV4RenderB's data-parallel step normalises with the GLOBAL batch's statistics at replicas > 1: every one of the 77 BatchNorm sites is the sync-BN composition — this replica's mean all-reduced, then Chan's σ²_r + (μ_r − μ)² all-reduced, packed, then bnSyncF. This file is the data-parallel twin of mnv4FwdGraphBFull_faithful: that forward graph, stated as a family over the R replicas, denotes on replica r exactly batchShard r of the single-device forward at the global batch R·N.

den (mnv4FwdGraphSyncFull R hR N epsStr w bf16 e r)
  = batchShard R N nCls (mobilenetv4ForwardBFull (R * N) w X) r

given that each replica's input is its shard of one global batch X. The spec does not move: the right-hand side is the committed mobilenetv4ForwardBFull, at N := R·N.

How it is proved #

As ResNet34SyncB.lean and MobileNetV2SyncB.lean prove theirs: one block at a time, with the shard hypothesis ∀ r, den (e r) = batchShard R N _ X r carried from block to block.

Same shape as MobileNetV4FullB, and for its reasons. The block lemmas are generic in the row (s : UibSpec), so every width is a projection of a variable and nothing evaluates; each one closes on the row-typed mnv4BodyOfRow (R * N) s p / mnv4StridedBodyOfRow by the dispatch hypotheses MobileNetV4FullB uses (s.preDWk ≠ 0, s.postDWk = 0, …), discharged by decide at the concrete rows. The skip is one generic combinator (mnv4SkipGraphSync, the peer of mnv4SkipGraphB), which keeps the whole-net term linear in the depth. The five resolution groups are proved against mnv4Res*Layer (R * N) w through MobileNetV4FullB's _fwd_apply peels, and the whole net is a have-chain of eight stage lemmas over mobilenetv4ForwardBFull's own prefixes — no CertLayer.comp is ever peeled at a literal width.

The index seam #

The conv/relu chain runs at the left-assoc index N·(c·h·w); bnSyncF and its statistics nodes at N·(c·(h·w)). As in ResNet-34's and MobileNetV2's twins the site is ResNet34SyncB's bnSyncSiteLA, which carries the mul_assoc relabelling as castIdx on the AST value (the emitted text does not change: skel never sees an index), and den_bnSyncSiteLA reads P1 back at the network index through batchShard_castIdx. Nothing about the seam is MobileNetV4's own.

Names #

Parameter names are MobileNetV4FullB's, read off the row (%u{p}{q,e,d,p}{W,g,bt}, %f0cW, %sW, %h1W, %hW, …), and every bias operand is the shared zero %zb{c}. A BatchNorm site with γ %u{p}qg gathers its statistics as %arsum / %armean of u{p}qgmu and u{p}qgvar, each over a [c] vector — the γ name without %, then mu / var, the tag bnFwdSite is handed.

What is not claimed here #

The backward and the parameter collectives are MobileNetV4SyncStepTieB.lean's. Every conv here is bias-free by construction: MobileNetV4RenderB has no convBias flag and binds each bias slot to the zero %zb{c}, so no bias is trained and no bias gradient is emitted (the statement is ∀ w, and zero biases are one instance). bf16 selects the conv and depthwise kinds at every site, as the single-device graph does (StableHLO.PrecisionSwitch): true is the *bf16 DP renders' graph — mnv4in_emaaccdp8x128wxdowd005bf16's trunk among them — read over ℝ through Bf16Erasure, each conv's shard step erasing the switch before the f32 proof proceeds. That the R replicas' inputs are the shards of one batch is the driver's, as in DataParallel.Sync. The lowerer's all_reduce is trusted as every other op's lowering is.

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

Stem at sync-BN, over the replica family: 3×3/s2 symmetric conv → sync-BN → relu.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.StableHLO.mnv4StemGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc kH kW : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (Ws : Kernel4 oc ic kH kW) (bs : Vec oc) (εs : ℝ) (γs βs : Vec oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * h) * (2 * w)))) (X : Vec (R * N * (ic * (2 * h) * (2 * w)))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (ic * (2 * h) * (2 * w)) X r) (r : Fin R) :
    den (mnv4StemGraphSync epsStr R hR N h w Ws bs εs γs βs bf16 e r) = batchShard R N (oc * h * w) (mnv4StemB (R * N) h w Ws bs εs γs βs X) r
    def Proofs.StableHLO.mnv4FusedGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc kH kW : ℕ} (Wc : Kernel4 mid ic kH kW) (bc : Vec mid) (εc : ℝ) (γc βc : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (γp βp : Vec oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * h) * (2 * w)))) :
    Fin R → SHlo (N * (oc * h * w))

    Fused stage at sync-BN, over the replica family: 3×3/s2 symmetric conv → sync-BN → relu → 1×1 project → sync-BN. Two sync sites, no skip.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.StableHLO.mnv4FusedGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc kH kW : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (Wc : Kernel4 mid ic kH kW) (bc : Vec mid) (εc : ℝ) (hεc : 0 < εc) (γc βc : Vec mid) (Wp : Kernel4 oc mid 1 1) (bp : Vec oc) (εp : ℝ) (hεp : 0 < εp) (γp βp : Vec oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * h) * (2 * w)))) (X : Vec (R * N * (ic * (2 * h) * (2 * w)))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (ic * (2 * h) * (2 * w)) X r) (r : Fin R) :
      den (mnv4FusedGraphSync epsStr R hR N h w Wc bc εc γc βc Wp bp εp γp βp bf16 e r) = batchShard R N (oc * h * w) ((mnv4FusedStage (R * N) (cbReluStridedLayer (R * N) Wc bc εc hεc γc βc) (projLayer (R * N) Wp bp εp hεp γp βp)).fwd X) r
      def Proofs.StableHLO.mnv4ExtraDWBodyGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (s : UibSpec) (p : UibParams s) (bf16 : Bool) (e : Fin R → SHlo (N * (s.ic * s.h * s.h))) :
      Fin R → SHlo (N * (s.oc * s.h * s.h))

      ExtraDW body at sync-BN, over the replica family — both depthwises present: pre-DW → sync-BN → expand → sync-BN → relu → post-DW → sync-BN → relu → project → sync-BN. Four sync sites. The body only; the identity skip is mnv4SkipGraphSync.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Proofs.StableHLO.mnv4ExtraDWBodyGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (s : UibSpec) (hh : 0 < s.h) (p : UibParams s) (bf16 : Bool) (hq : s.preDWk ≠ 0) (hd : s.postDWk ≠ 0) (e : Fin R → SHlo (N * (s.ic * s.h * s.h))) (X : Vec (R * N * (s.ic * s.h * s.h))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (s.ic * s.h * s.h) X r) (r : Fin R) :
        den (mnv4ExtraDWBodyGraphSync epsStr R hR N s p bf16 e r) = batchShard R N (s.oc * s.h * s.h) ((mnv4BodyOfRow (R * N) s p).fwd X) r

        The ExtraDW body at sync-BN is shard r of the row-typed body at R·N — generic in the row, the dispatch hypotheses mnv4ExtraDWBodyGraphB_faithful takes.

        def Proofs.StableHLO.mnv4ConvNeXtBodyGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (s : UibSpec) (p : UibParams s) (bf16 : Bool) (e : Fin R → SHlo (N * (s.ic * s.h * s.h))) :
        Fin R → SHlo (N * (s.oc * s.h * s.h))

        ConvNeXt-like body at sync-BN — pre-DW only (postDWk = 0): the absent depthwise emits no tokens, exactly as in MobileNetV4FullB. Three sync sites.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Proofs.StableHLO.mnv4ConvNeXtBodyGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (s : UibSpec) (hh : 0 < s.h) (p : UibParams s) (bf16 : Bool) (hq : s.preDWk ≠ 0) (hd : s.postDWk = 0) (e : Fin R → SHlo (N * (s.ic * s.h * s.h))) (X : Vec (R * N * (s.ic * s.h * s.h))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (s.ic * s.h * s.h) X r) (r : Fin R) :
          den (mnv4ConvNeXtBodyGraphSync epsStr R hR N s p bf16 e r) = batchShard R N (s.oc * s.h * s.h) ((mnv4BodyOfRow (R * N) s p).fwd X) r
          def Proofs.StableHLO.mnv4FfnBodyGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (s : UibSpec) (p : UibParams s) (bf16 : Bool) (e : Fin R → SHlo (N * (s.ic * s.h * s.h))) :
          Fin R → SHlo (N * (s.oc * s.h * s.h))

          FFN body at sync-BN — neither depthwise: expand → sync-BN → relu → project → sync-BN.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Proofs.StableHLO.mnv4FfnBodyGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (s : UibSpec) (hh : 0 < s.h) (p : UibParams s) (bf16 : Bool) (hq : s.preDWk = 0) (hd : s.postDWk = 0) (e : Fin R → SHlo (N * (s.ic * s.h * s.h))) (X : Vec (R * N * (s.ic * s.h * s.h))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (s.ic * s.h * s.h) X r) (r : Fin R) :
            den (mnv4FfnBodyGraphSync epsStr R hR N s p bf16 e r) = batchShard R N (s.oc * s.h * s.h) ((mnv4BodyOfRow (R * N) s p).fwd X) r
            def Proofs.StableHLO.mnv4StridedGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (s : UibSpec) (p : UibParams s) (bf16 : Bool) (e : Fin R → SHlo (N * (s.ic * (2 * s.h) * (2 * s.h)))) :
            Fin R → SHlo (N * (s.oc * s.h * s.h))

            Strided block at sync-BN — rows 1, 3 and 11: the BN-only pre-DW and the expand at 2h, the post-DW (.depthwiseStrided, symmetric) carrying the stride, the project at h. Four sync sites; no skip (ic ≠ oc).

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem Proofs.StableHLO.mnv4StridedGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (s : UibSpec) (hh : 0 < s.h) (p : UibParams s) (bf16 : Bool) (hq : s.preDWk ≠ 0) (e : Fin R → SHlo (N * (s.ic * (2 * s.h) * (2 * s.h)))) (X : Vec (R * N * (s.ic * (2 * s.h) * (2 * s.h)))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (s.ic * (2 * s.h) * (2 * s.h)) X r) (r : Fin R) :
              den (mnv4StridedGraphSync epsStr R hR N s p bf16 e r) = batchShard R N (s.oc * s.h * s.h) ((mnv4StridedBodyOfRow (R * N) s p).fwd X) r
              def Proofs.StableHLO.mnv4SkipGraphSync {R N n : ℕ} (body : (Fin R → SHlo (N * n)) → Fin R → SHlo (N * n)) (e : Fin R → SHlo (N * n)) :
              Fin R → SHlo (N * n)

              One skip row at sync-BN: its body's family, plus the identity skip, replica by replica — the peer of mnv4SkipGraphB, and a named combinator for the same reason: the add needs the block's input family twice, and kept folded the whole-net term stays linear in the depth.

              Equations
              Instances For
                theorem Proofs.StableHLO.mnv4SkipGraphSync_shard {R N n : ℕ} (body : (Fin R → SHlo (N * n)) → Fin R → SHlo (N * n)) (f : Vec (R * N * n) → Vec (R * N * n)) (hb : ∀ (e' : Fin R → SHlo (N * n)) (X' : Vec (R * N * n)), (∀ (r : Fin R), den (e' r) = batchShard R N n X' r) → ∀ (r : Fin R), den (body e' r) = batchShard R N n (f X') r) (e : Fin R → SHlo (N * n)) (X : Vec (R * N * n)) (he : ∀ (r : Fin R), den (e r) = batchShard R N n X r) (r : Fin R) :
                den (mnv4SkipGraphSync body e r) = batchShard R N n (residual f X) r

                A skip row at sync-BN is shard r of residual of whatever its body shards to — generic in the body, so one lemma serves all eighteen and the body's shard lemma is the only input.

                def Proofs.StableHLO.mnv4HeadGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid oc nCls : ℕ} (W1 : Kernel4 mid c 1 1) (b1 : Vec mid) (ε1 : ℝ) (γ1 β1 : Vec mid) (W2 : Kernel4 oc mid 1 1) (b2 : Vec oc) (ε2 : ℝ) (γ2 β2 : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (c * h * w))) :
                Fin R → SHlo (N * nCls)

                Head at sync-BN, over the replica family, timm's order: 1×1 conv → sync-BN → relu, GAP, conv_head 1×1 conv → sync-BN → relu on the pooled features (that BN's statistics over the GLOBAL batch alone), dense — with the two castIdx relabellings MobileNetV4FullB's head graph carries.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem Proofs.StableHLO.mnv4HeadGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid oc nCls : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (W1 : Kernel4 mid c 1 1) (b1 : Vec mid) (ε1 : ℝ) (hε1 : 0 < ε1) (γ1 β1 : Vec mid) (W2 : Kernel4 oc mid 1 1) (b2 : Vec oc) (ε2 : ℝ) (hε2 : 0 < ε2) (γ2 β2 : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (c * h * w))) (X : Vec (R * N * (c * h * w))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (c * h * w) X r) (r : Fin R) :
                  den (mnv4HeadGraphSync epsStr R hR N h w W1 b1 ε1 γ1 β1 W2 b2 ε2 γ2 β2 Wd bd bf16 e r) = batchShard R N nCls ((mnv4Head (R * N) (cbReluLayer (R * N) W1 b1 ε1 hε1 γ1 β1) (gapLayer (R * N)) (cbReluLayer (R * N) W2 b2 ε2 hε2 γ2 β2) (denseLayer (R * N) Wd bd)).fwd X) r
                  def Proofs.StableHLO.mnv4FwdGraphSyncFull (R : ℕ) (hR : 0 < R) (N : ℕ) (epsStr : String) {nCls : ℕ} (w : Mnv4BWeights nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (3 * 224 * 224))) :
                  Fin R → SHlo (N * nCls)

                  The sync-BN data-parallel MobileNetV4-Conv-M forward graph, over the replica family. mnv4FwdGraphBFull with every one of its 77 BatchNorms a bnSyncSiteLA over all R replicas; parameter names are read off the rows and collective tags are the render's. bf16 selects the conv and depthwise kinds at every site, as mnv4FwdGraphBFull does.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Proofs.StableHLO.mnv4FwdGraphSyncFull_shard (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (epsStr : String) {nCls : ℕ} (w : Mnv4BWeights nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (3 * 224 * 224))) (X : Vec (R * N * (3 * 224 * 224))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (3 * 224 * 224) X r) (r : Fin R) :
                    den (mnv4FwdGraphSyncFull R hR N epsStr w bf16 e r) = batchShard R N nCls (mobilenetv4ForwardBFull (R * N) w X) r

                    At synchronised BatchNorm, replica r's forward is shard r of the global-batch forward. Given that the replicas' inputs are the shards of one batch X of R·N images, the sync-BN graph on replica r denotes batchShard r of mobilenetv4ForwardBFull (R * N) w X — the committed batch-BN forward, at the global batch. Eight stage lemmas — the stem, the fused stage, the five resolution groups, the head — the shard hypothesis threaded from each into the next, over the forward's own prefixes.