Documentation

LeanMlir.Proofs.Nets.MobileNet.MobileNetV2SyncB

MobileNetV2's data-parallel forward at SYNCHRONISED BatchNorm — replica r IS shard r #

MobileNetV2FullB.lean says the typed batch-BN graph denotes mobilenetv2ForwardBFull N w on one device. MobileNetV2RenderB's data-parallel step normalises with the GLOBAL batch's statistics at replicas > 1: every one of the 52 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 mobilenetv2FwdGraphBFull_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 (mobilenetv2FwdGraphSyncFull R hR N epsStr w bf16 e r)
  = batchShard R N nCls (mobilenetv2ForwardBFull (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 mobilenetv2ForwardBFull, at N := R·N, and it does not move with the precision either: bf16 selects the conv and depthwise kinds at every site (.convAt / .convStridedXlaAt / .depthwiseAt / .depthwiseStridedXlaAt, as MobileNetV2FullB), bf16 := true being the kinds the *bf16 DP renders emit — mobilenetv2in_rmsdp64wxdols0eps0001bf16, the run the book reports, among them; each conv's shard step erases the switch through Bf16Erasure (Bf16Fold.denOp_convAt_id, …) and the rest of the proof is the f32 one. The *do* DP artifacts' forward — that run's — is mobilenetv2FwdGraphSyncFullDo: the same graph with replica r's dropoutB at its own mask %do between the GAP and the dense, and mobilenetv2FwdGraphSyncFullDo_shard says it denotes shard r of mobilenetv2ForwardBFullDo at the global batch and the global mask the replicas' masks are the shards of.

How it is proved #

As ResNet34SyncB.lean proves ResNet-34's: by induction on the chain, one block at a time, with the shard hypothesis ∀ r, den (e r) = batchShard R N _ X r carried from block to block.

The graph reuses ResNet34SyncB's site verbatim — it is net-agnostic — and relu6's shard lemma is the kit's, so this file is MobileNetV2's six block shapes and their chain.

Names #

Parameter names are MobileNetV2FullB's (%b{k}{e,d,p}{W,g,bt}, %sW, %hW, …, the convBias := false zero-bias operands %zb{c}). A BatchNorm site with γ %b{k}dg gathers its statistics as %arsum / %armean of b{k}dgmu and b{k}dgvar, each over a [c] vector — the γ name without %, then mu / var.

What is NOT claimed here #

The backward and the parameter collectives are MobileNetV2SyncStepTieB.lean's. That the R replicas' inputs are the shards of one batch is the driver's, as in DataParallel.Sync. The rounding the bf16 kinds perform is not modelled, as f32 rounding is not: den is over ℝ at either value of the flag. The lowerer's all_reduce is trusted as every other op's lowering is.

def Proofs.StableHLO.mnv2StemGraphSync (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: 3x3/s2 XLA-SAME conv → sync-BN → relu6.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.StableHLO.mnv2StemGraphSync_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 (mnv2StemGraphSync epsStr R hR N h w Ws bs εs γs βs bf16 e r) = batchShard R N (oc * h * w) (mnv2StemB (R * N) h w Ws bs εs γs βs X) r
    def Proofs.StableHLO.mnv2NoExpGraphSync (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (p : IVWNoExp ic oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * h * w))) :
    Fin R → SHlo (N * (oc * h * w))

    t = 1 bottleneck (b1) at sync-BN, over the replica family: depthwise → sync-BN → relu6 → project 1x1 → sync-BN. Two sync sites.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.StableHLO.mnv2NoExpGraphSync_shard (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVWNoExp ic oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * h * w))) (X : Vec (R * N * (ic * h * w))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (ic * h * w) X r) (r : Fin R) :
      den (mnv2NoExpGraphSync pfx epsStr R hR N h w p bf16 e r) = batchShard R N (oc * h * w) (mnv2NoExpB (R * N) h w p X) r
      def Proofs.StableHLO.mnv2ExpOnlyGraphSync (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * h * w))) :
      Fin R → SHlo (N * (oc * h * w))

      Stride-1 no-skip bottleneck (b11, b17) at sync-BN, over the replica family: expand → depthwise → project, a sync site 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.mnv2ExpOnlyGraphSync_shard (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVW ic mid oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * h * w))) (X : Vec (R * N * (ic * h * w))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (ic * h * w) X r) (r : Fin R) :
        den (mnv2ExpOnlyGraphSync pfx epsStr R hR N h w p bf16 e r) = batchShard R N (oc * h * w) (mnv2ExpOnlyB (R * N) h w p X) r
        def Proofs.StableHLO.mnv2ResidGraphSync (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid : ℕ} (p : IVW c mid c) (bf16 : Bool) (e : Fin R → SHlo (N * (c * h * w))) :
        Fin R → SHlo (N * (c * h * w))

        Stride-1 skip bottleneck at sync-BN: the body plus the addVB identity skip, the block input shared between both arms on every replica.

        Equations
        Instances For
          theorem Proofs.StableHLO.mnv2ResidGraphSync_shard (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVW c mid c) (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 (mnv2ResidGraphSync pfx epsStr R hR N h w p bf16 e r) = batchShard R N (c * h * w) (mnv2ResidB (R * N) h w p X) r
          def Proofs.StableHLO.mnv2StridedGraphSync (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * h) * (2 * w)))) :
          Fin R → SHlo (N * (oc * h * w))

          Stride-2 downsampling bottleneck at sync-BN, over the replica family: expand at 2h x 2w, the XLA-SAME strided depthwise, project at h x w; three sync sites.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Proofs.StableHLO.mnv2StridedGraphSync_shard (pfx epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVW ic mid 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 (mnv2StridedGraphSync pfx epsStr R hR N h w p bf16 e r) = batchShard R N (oc * h * w) (mnv2StridedB (R * N) h w p X) r
            def Proofs.StableHLO.mnv2HeadGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (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 : Fin R → SHlo (N * (ic * h * w))) :
            Fin R → SHlo (N * nCls)

            Head at sync-BN, over the replica family: 1x1 conv → sync-BN → relu6 → GAP → dense.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem Proofs.StableHLO.mnv2HeadGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc nCls : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * h * w))) (X : Vec (R * N * (ic * h * w))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (ic * h * w) X r) (r : Fin R) :
              den (mnv2HeadGraphSync epsStr R hR N h w Wh bh εh γh βh Wd bd bf16 e r) = batchShard R N nCls (mnv2HeadB (R * N) h w Wh bh εh γh βh Wd bd X) r
              def Proofs.StableHLO.mnv2HeadGraphSyncDo (epsStr mName : String) (R : ℕ) (hR : 0 < R) (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) (ms : Fin R → Vec (N * oc)) (e : Fin R → SHlo (N * (ic * h * w))) :
              Fin R → SHlo (N * nCls)

              mnv2HeadGraphSync with the classifier-dropout site: replica r's dropoutB at its own mask ms r (the render's per-replica %do input) between the GAP and the dense — mnv2HeadGraphBDo over the replica family.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem Proofs.StableHLO.mnv2HeadGraphSyncDo_shard (epsStr mName : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc nCls : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (bd : Vec nCls) (bf16 : Bool) (ms : Fin R → Vec (N * oc)) (M : Vec (R * N * oc)) (hm : ∀ (r : Fin R), ms r = batchShard R N oc M r) (e : Fin R → SHlo (N * (ic * h * w))) (X : Vec (R * N * (ic * h * w))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (ic * h * w) X r) (r : Fin R) :
                den (mnv2HeadGraphSyncDo epsStr mName R hR N h w Wh bh εh γh βh Wd bd bf16 ms e r) = batchShard R N nCls (mnv2HeadBDo (R * N) h w Wh bh εh γh βh Wd bd M X) r

                With the replicas' masks the shards of one global mask M, replica r's dropout head is shard r of the global mnv2HeadBDo — the site's step is batchShard_zipWith at the multiply, the rest mnv2HeadGraphSync_shard's.

                def Proofs.StableHLO.mobilenetv2FwdGraphSyncFull (R : ℕ) (hR : 0 < R) (N : ℕ) (epsStr : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (3 * (2 * 112) * (2 * 112)))) :
                Fin R → SHlo (N * nCls)

                The sync-BN data-parallel MobileNetV2 forward graph, over the replica family. mobilenetv2FwdGraphBFull with every BatchNorm a bnSyncSiteLA over all R replicas; block prefixes, parameter names and collective tags are the render's.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem Proofs.StableHLO.mobilenetv2FwdGraphSyncFull_shard (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (epsStr : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (3 * (2 * 112) * (2 * 112)))) (X : Vec (R * N * (3 * (2 * 112) * (2 * 112)))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (3 * (2 * 112) * (2 * 112)) X r) (r : Fin R) :
                  den (mobilenetv2FwdGraphSyncFull R hR N epsStr w bf16 e r) = batchShard R N nCls (mobilenetv2ForwardBFull (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 examples, the sync-BN graph on replica r denotes batchShard r of mobilenetv2ForwardBFull (R * N) w X — the committed batch-BN forward, at the global batch. One block lemma per stage, the shard hypothesis threaded from each into the next.

                  def Proofs.StableHLO.mobilenetv2FwdGraphSyncFullDo (R : ℕ) (hR : 0 < R) (N : ℕ) (epsStr mName : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (ms : Fin R → Vec (N * 1280)) (e : Fin R → SHlo (N * (3 * (2 * 112) * (2 * 112)))) :
                  Fin R → SHlo (N * nCls)

                  The sync-BN data-parallel MobileNetV2 forward graph with classifier dropout, over the replica family — mobilenetv2FwdGraphSyncFull with mnv2HeadGraphSyncDo as its head, replica r at its mask ms r; the forward of the *do* DP train steps.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Proofs.StableHLO.mobilenetv2FwdGraphSyncFullDo_shard (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (epsStr mName : String) {nCls : ℕ} (w : MNV2BWeights nCls) (bf16 : Bool) (ms : Fin R → Vec (N * 1280)) (M : Vec (R * N * 1280)) (hm : ∀ (r : Fin R), ms r = batchShard R N 1280 M r) (e : Fin R → SHlo (N * (3 * (2 * 112) * (2 * 112)))) (X : Vec (R * N * (3 * (2 * 112) * (2 * 112)))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (3 * (2 * 112) * (2 * 112)) X r) (r : Fin R) :
                    den (mobilenetv2FwdGraphSyncFullDo R hR N epsStr mName w bf16 ms e r) = batchShard R N nCls (mobilenetv2ForwardBFullDo (R * N) w M X) r

                    mobilenetv2FwdGraphSyncFull_shard at the site: with the replicas' inputs the shards of one batch X and their masks the shards of one mask M, replica r's dropout forward denotes shard r of mobilenetv2ForwardBFullDo (R * N) w M X.