Documentation

LeanMlir.Proofs.Nets.MobileNet.MobileNetV2SyncStepTieB

MobileNetV2's data-parallel step at synchronised BatchNorm is the single-device step at R·N #

MobileNetV2StepTieB.lean threads the label-smoothed loss cotangent down the batch-BN backward chain on one device and ties every parameter gradient node to the certified gradient at that chain's cotangent. This is its data-parallel twin, for the render MobileNetV2RenderB emits at replicas > 1: R replicas at batch N, every one of the 52 BatchNorms synchronised, every parameter gradient all-reduced by its mean. The capstone mnv2_net_syncTiedB says that, for every parameter the render emits,

mean over the R replicas of replica r's gradient node, loss divided by B
  = the single-device gradient node at the global batch R·N, loss divided by R·B

— the gradient node mnv2_net_tiedB at N := R·N ties to the certified gradient. The right-hand side is the existing single-device chain at N := R·N, so the spec has not moved.

The same four steps as ResNet-34's twin #

ResNet34SyncStepTieB.lean is the template, and everything net-agnostic is imported from it rather than restated: the replica BN link bnSyncInB and its shard lemma, the ConvWSync / BnSync / DenseSync statements and their *_of_scaled closers, the divisor step replicaLossCot_eq, and the homogeneity of bnInB and cInB. The inverted-residual pieces it shares with EfficientNet-B0 — the depthwise, GAP and dense input-VJPs, the depthwise and XLA-SAME stem weight collectives — come from DataParallel.SyncKit.

  1. Sharding — each replica's backward chain, handed its shard of a global cotangent, computes the shard of the global chain. The relu6 mask is pointwise, so it shards by rfl; the conv, depthwise, XLA-SAME strided depthwise, GAP and dense input-VJPs are per-example maps; every BN link is bnSyncInB.
  2. The collectives — the mean over replicas of each replica's gradient node is 1/R of the global node at the global cotangent. MobileNetV2 adds three kinds the ResNet-34 kit does not have: the XLA-SAME strided conv weight (the stem), the depthwise weight and its XLA-SAME strided peer (§4).
  3. Homogeneity — the single-device chain and its gradient nodes are linear in the loss cotangent (§1): R × the cotangent gives R × every node.
  4. The divisor — replica r's loss cotangent is R × its shard of the global one, and that R cancels the collective's 1/R at every parameter.

What the DP render emits, and what is tied #

At the committed convBias := false, MobileNetV2RenderB emits 158 parameter gradients — stem 3 (sW, sg, sbt), b1 6, sixteen blocks × 9 (eW eg ebt dW dg dbt pW pg pbt), head 3 (hW, hg, hbt), dense 2 (Wd, bd) — and the capstone ties all 158. The 52 conv, depthwise and project BIAS nodes the single-device tie also states are not emitted at convBias := false and are not tied here (mnv2_net_tiedB keeps them for the flag).

What is NOT claimed #

The replicas' saved forward activations enter as the shards of the single-device forward's (batchShard r (mnv2PreB{k} (R*N) w X)); that the sync forward graph computes exactly those is StableHLO.mobilenetv2FwdGraphSyncFull_shard, the forward half. That the replicas' inputs are the shards of one batch is the driver's. The lowerer's all_reduce is trusted as every other op's lowering is.

Precision is a flag on the statement. The ImageNet run the book reports trains from mobilenetv2in_rmsdp64wxdols0eps0001bf16, whose conv and depthwise weight gradients are the bf16 kinds. Every conv and depthwise weight collective below is stated on the renderers' switch — ConvWSyncAt bf16 / ConvStridedXlaWSyncAt bf16 / DepthwiseWSyncAt bf16 / DepthwiseStridedXlaWSyncAt bf16 (Foundation.GradNodesBAt): the replicas' nodes and the batch-R·N node are the f32 kind at false and the bf16 kind at true — and the capstone takes bf16, so it covers the f32 DP artifacts (mobilenetv2_adamdp, mobilenetv2in_adamdp64, mobilenetv2in_rmsdp64, mobilenetv2in_rmsdp128) and the *bf16 ones' step read over ℝ at the identity rounding (Bf16Erasure), where each bf16 collective is 1/R of the batch-R·N bf16 node exactly as at f32. At a real rounding the bf16 weight-gradient collective differs from the single-device node by the per-replica rounding of each partial sum, which DataParallel.SyncBf16 states and this file does not model, as the f32 tie does not model f32 rounding.

Classifier dropout is an optional site on the statement, as in MobileNetV2StepTieB: the capstone takes cd : Option (Vec ((R * N) * 1280)), the GLOBAL mask, and replica r runs its chain at batchShard r of it — which is what the DP render's per-replica %do input is. none is the drop-free DP artifacts' statement exactly as it was; some M reaches mobilenetv2in_rmsdp64wxdols0eps0001bf16's head: the site is linear in the cotangent (dropoutOpt_smul) and commutes with the batch cut (dropoutOpt_shard, Foundation.DropSites), so the four steps above are unchanged, and the dense collective reads the dropped activation on every replica. The forward half with the site is StableHLO.mobilenetv2FwdGraphSyncFullDo_shard.

The block cotangents, each one line from the previous link's.

theorem Proofs.MobileNetV2SyncTieB.mnv2NoExpCotIn_smul (N h w : ℕ) {ic oc : ℕ} (p : IVWNoExp ic oc) (xin : Vec (N * (ic * h * w))) :
theorem Proofs.MobileNetV2SyncTieB.mnv2ResidCotIn_smul (N h w : ℕ) {c mid : ℕ} (p : IVW c mid c) (xin : Vec (N * (c * h * w))) :
theorem Proofs.MobileNetV2SyncTieB.mnv2StridedCotIn_smul (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (xin : Vec (N * (ic * (2 * h) * (2 * w)))) :
theorem Proofs.MobileNetV2SyncTieB.mnv2HeadCotBlk_smul (N h w : ℕ) {ic oc nCls : ℕ} (Wh : Kernel4 oc ic 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wd : Mat oc nCls) (cd : Option (Vec (N * oc))) (xin : Vec (N * (ic * h * w))) :
IsHomog (MobileNetV2TieB.mnv2HeadCotBlk N h w Wh bh εh γh βh Wd cd xin)
noncomputable def Proofs.MobileNetV2SyncTieB.mnv2NoExpSyncCotIn (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (p : IVWNoExp ic oc) (XIN : Vec (R * N * (ic * h * w))) (dys : Fin R → Vec (N * (oc * h * w))) (r : Fin R) :
Vec (N * (ic * h * w))

b1, replica r: the block-INPUT cotangent, handed to the stem.

Equations
Instances For
    theorem Proofs.MobileNetV2SyncTieB.mnv2NoExpSyncCotIn_shard (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVWNoExp ic oc) (XIN : Vec (R * N * (ic * h * w))) (dys : Fin R → Vec (N * (oc * h * w))) (DY : Vec (R * N * (oc * h * w))) (hdys : ∀ (r : Fin R), dys r = batchShard R N (oc * h * w) DY r) (r : Fin R) :
    mnv2NoExpSyncCotIn R hR N h w p XIN dys r = batchShard R N (ic * h * w) (MobileNetV2TieB.mnv2NoExpCotIn (R * N) h w p XIN DY) r
    noncomputable def Proofs.MobileNetV2SyncTieB.mnv2SyncCotInBody (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (XIN : Vec (R * N * (ic * h * w))) (dys : Fin R → Vec (N * (oc * h * w))) (r : Fin R) :
    Vec (N * (ic * h * w))

    Stride-1 body, replica r: the body's input cotangent — the whole block-input cotangent for a widening (b11, b17).

    Equations
    Instances For
      noncomputable def Proofs.MobileNetV2SyncTieB.mnv2ResidSyncCotIn (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid : ℕ} (p : IVW c mid c) (XIN : Vec (R * N * (c * h * w))) (dys : Fin R → Vec (N * (c * h * w))) (r : Fin R) :
      Vec (N * (c * h * w))

      Skip block, replica r: the body branch plus the identity skip.

      Equations
      Instances For
        theorem Proofs.MobileNetV2SyncTieB.mnv2SyncCotInBody_shard (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVW ic mid oc) (XIN : Vec (R * N * (ic * h * w))) (dys : Fin R → Vec (N * (oc * h * w))) (DY : Vec (R * N * (oc * h * w))) (hdys : ∀ (r : Fin R), dys r = batchShard R N (oc * h * w) DY r) (r : Fin R) :
        mnv2SyncCotInBody R hR N h w p XIN dys r = batchShard R N (ic * h * w) (MobileNetV2TieB.mnv2CotInBody (R * N) h w p XIN DY) r
        theorem Proofs.MobileNetV2SyncTieB.mnv2ResidSyncCotIn_shard (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVW c mid c) (XIN : Vec (R * N * (c * h * w))) (dys : Fin R → Vec (N * (c * h * w))) (DY : Vec (R * N * (c * h * w))) (hdys : ∀ (r : Fin R), dys r = batchShard R N (c * h * w) DY r) (r : Fin R) :
        mnv2ResidSyncCotIn R hR N h w p XIN dys r = batchShard R N (c * h * w) (MobileNetV2TieB.mnv2ResidCotIn (R * N) h w p XIN DY) r
        noncomputable def Proofs.MobileNetV2SyncTieB.mnv2StridedSyncCotIn (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (p : IVW ic mid oc) (XIN : Vec (R * N * (ic * (2 * h) * (2 * w)))) (dys : Fin R → Vec (N * (oc * h * w))) (r : Fin R) :
        Vec (N * (ic * (2 * h) * (2 * w)))

        Stride-2 block, replica r: the block-INPUT cotangent.

        Equations
        Instances For
          theorem Proofs.MobileNetV2SyncTieB.mnv2StridedSyncCotIn_shard (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (p : IVW ic mid oc) (XIN : Vec (R * N * (ic * (2 * h) * (2 * w)))) (dys : Fin R → Vec (N * (oc * h * w))) (DY : Vec (R * N * (oc * h * w))) (hdys : ∀ (r : Fin R), dys r = batchShard R N (oc * h * w) DY r) (r : Fin R) :
          mnv2StridedSyncCotIn R hR N h w p XIN dys r = batchShard R N (ic * (2 * h) * (2 * w)) (MobileNetV2TieB.mnv2StridedCotIn (R * N) h w p XIN DY) r
          noncomputable def Proofs.MobileNetV2SyncTieB.mnv2StemSyncCotC (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) (X : Vec (R * N * (ic * (2 * h) * (2 * w)))) (dys : Fin R → Vec (N * (oc * h * w))) (r : Fin R) :
          Vec (N * (oc * h * w))

          Stem, replica r: the stem BatchNorm's sync backward. Feeds sW.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Proofs.MobileNetV2SyncTieB.mnv2StemSyncCotC_shard (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) (X : Vec (R * N * (ic * (2 * h) * (2 * w)))) (dys : Fin R → Vec (N * (oc * h * w))) (DY : Vec (R * N * (oc * h * w))) (hdys : ∀ (r : Fin R), dys r = batchShard R N (oc * h * w) DY r) (r : Fin R) :
            mnv2StemSyncCotC R hR N h w Ws bs εs γs βs X dys r = batchShard R N (oc * h * w) (MobileNetV2TieB.mnv2StemCotC (R * N) h w Ws bs εs γs βs X DY) r
            noncomputable def Proofs.MobileNetV2SyncTieB.mnv2HeadSyncCotBlk (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) (cd : Option (Vec (R * N * oc))) (XIN : Vec (R * N * (ic * h * w))) (gs : Fin R → Vec (N * nCls)) (r : Fin R) :
            Vec (N * (ic * h * w))

            Head, replica r: the cotangent handed to b17.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem Proofs.MobileNetV2SyncTieB.mnv2HeadSyncCotBlk_shard (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) (cd : Option (Vec (R * N * oc))) (XIN : Vec (R * N * (ic * h * w))) (gs : Fin R → Vec (N * nCls)) (G : Vec (R * N * nCls)) (hgs : ∀ (r : Fin R), gs r = batchShard R N nCls G r) (r : Fin R) :
              mnv2HeadSyncCotBlk R hR N h w Wh bh εh γh βh Wd cd XIN gs r = batchShard R N (ic * h * w) (MobileNetV2TieB.mnv2HeadCotBlk (R * N) h w Wh bh εh γh βh Wd cd XIN G) r
              def Proofs.MobileNetV2SyncTieB.mnv2NetSyncTiedB (R : ℕ) (hR : 0 < R) (N : ℕ) {nCls : ℕ} (xN cotN vN epsStr : String) (w : MNV2BWeights nCls) (bf16 : Bool) (cd : Option (Vec (R * N * 1280))) (X : Vec (R * N * (3 * (2 * 112) * (2 * 112)))) (G : Vec (R * N * nCls)) (gs : Fin R → Vec (N * nCls)) :

              The whole-net statement, named — so the capstone (cotangents bound) and its smoothed-CE corollary (cotangents instantiated) state exactly one thing. The first 18 lets are mnv2_net_tiedB's chain at N := R·N, driven by the global cotangent G; the next 18 are the replicas' sync-BN chain, driven by the family gs; the 19 conjuncts are one per stage, every emitted parameter collective against mnv2_net_tiedB's node at the global batch.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem Proofs.MobileNetV2SyncTieB.mnv2_net_syncTiedB (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) {nCls : ℕ} (xN cotN vN epsStr : String) (w : MNV2BWeights nCls) (bf16 : Bool) (cd : Option (Vec (R * N * 1280))) (X : Vec (R * N * (3 * (2 * 112) * (2 * 112)))) (G : Vec (R * N * nCls)) (gs : Fin R → Vec (N * nCls)) (hgs : ∀ (r : Fin R), gs r = batchShard R N nCls (fun (i : Fin (R * N * nCls)) => ↑R * G i) r) :
                mnv2NetSyncTiedB R hR N xN cotN vN epsStr w bf16 cd X G gs

                The synchronised-BN data-parallel MobileNetV2 step is the single-device step at the global batch. R replicas at batch N, each running the render's sync-BN backward chain from its own cotangent gs r, with gs r the R-scaled shard of a global cotangent G; every parameter's all-reduced mean gradient — stem 3, b1 6, sixteen blocks × 9, head 3, dense 2: the 158 the render emits — equals the single-device batch-BN gradient node at batch R·N, at the cotangent mnv2_net_tiedB's chain delivers there from G.

                The left-hand chain is the replicas' own: sync-BN backward (bnSyncInB, a collective per BN layer), per-example conv / depthwise / relu6 / GAP / dense links. The right-hand chain is mnv2_net_tiedB's at N := R·N with g := G, whose nodes that capstone ties to the certified gradient at its chain cotangent — so this and it together say every all-reduced gradient a DP render emits is the global-batch step's gradient node. bf16 selects the conv and depthwise weight collectives' kind on both sides — true is the *bf16 renders', read at the identity rounding (Bf16Erasure). The optimizer update that follows (RMSProp/AdamW) is not stated here. cd is the classifier-dropout site, the global mask replica r runs at shard r of — none the drop-free DP artifacts, some M mobilenetv2in_rmsdp64wxdols0eps0001bf16 (the module's Scope). mnv2_net_syncTiedB_smoothedCE discharges the hypothesis for the label-smoothed chain the artifacts emit.

                With per-replica BatchNorm the corresponding statement is false in general; DataParallel.dpMeanGrad_ne_globalBatchGrad is a two-replica counterexample.

                theorem Proofs.MobileNetV2SyncTieB.mnv2_net_syncTiedB_smoothedCE (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) {nCls : ℕ} (xN cotN vN epsStr aStr negAK bStr logN ohN : String) (α B : ℝ) (w : MNV2BWeights nCls) (bf16 : Bool) (cd : Option (Vec (R * N * 1280))) (X : Vec (R * N * (3 * (2 * 112) * (2 * 112)))) (T : Vec (R * N * (1 * nCls))) :
                mnv2NetSyncTiedB R hR N xN cotN vN epsStr w bf16 cd X (BackLinks.unrowB (R * N) nCls (StableHLO.den (smoothedLossCotGraph (R * N) nCls α (↑R * B) aStr negAK bStr logN ohN (BackLinks.rowB (R * N) nCls (MobileNetV2TieB.mobilenetv2ForwardBFullDoOpt (R * N) w cd X)) T))) fun (r : Fin R) => BackLinks.unrowB N nCls (StableHLO.den (smoothedLossCotGraph N nCls α B aStr negAK bStr logN ohN (BackLinks.rowB N nCls (batchShard R N nCls (MobileNetV2TieB.mobilenetv2ForwardBFullDoOpt (R * N) w cd X) r)) (batchShard R N (1 * nCls) T r)))

                …and at the loss the artifacts emit. mnv2_net_syncTiedB with its cotangent hypothesis discharged by replicaLossCot_eq: each replica runs the label-smoothed softmax chain (smoothedLossCotGraph) on its shard of the logits and targets with divisor B; the single-device step runs it on the whole R·N batch with divisor R·B. Then every all-reduced gradient a DP render emits, at either precision, is the single-device node at batch R·N, loss divided by R·B.