Documentation

LeanMlir.Proofs.Nets.EfficientNet.EfficientNetSyncB

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

EfficientNetFullB0.lean says the typed batch-BN graph denotes efficientnetForwardBFull N w on one device. At replicas > 1 the data-parallel render normalises every one of B0's 49 BatchNorms with the GLOBAL batch's statistics — the sync-BN composition bnFwdSite emits: this replica's mean all-reduced, then Chan's σ²_r + (μ_r − μ)² all-reduced, packed, then bnSyncF. This file is its data-parallel twin: 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 (efficientnetFwdGraphSyncFull R hR N epsStr w bf16 e r)
  = batchShard R N nCls (efficientnetForwardBFull (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 efficientnetForwardBFull, 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 the single-device graph), bf16 := true being the kinds the *bf16 DP renders emit — efficientnetin_emarmsdp64dropdowxeps0001bf16, the run the book reports, among them (its drop sites are outside this graph, as they are at f32); each conv's shard step erases the switch through Bf16Erasure (Bf16Fold.denOp_convAt_id, …) and the rest of the proof is the f32 one.

How it is proved #

ResNet-34's recipe (ResNet34SyncB.lean), block by block, the shard hypothesis ∀ r, den (e r) = batchShard R N _ X r carried from each block into the next:

The collectives are tagged as bnFwdSite tags them: a BN site whose γ is %{p}eg gathers {p}egmu and {p}egvar, each over a [c] statistic. den ignores every string, so the tags fix which graph is stated, not what it denotes.

What is NOT claimed here #

The backward and the parameter collectives are the step half (EfficientNetSyncStepTieG.lean). That the R replicas' inputs are the shards of one batch is the driver's. The emitted artifacts' stochastic-depth and classifier-dropout variants are efficientnetFwdGraphSyncFullDrop (replica r's dropPathB at its own per-example scale on each of the nine skip-carrying blocks, its dropoutB at its own mask before the dense), and efficientnetFwdGraphSyncFullDrop_shard says it denotes shard r of efficientnetForwardBFullDrop at the global batch and the global masks the replicas' are the shards of. The lowerer's all_reduce is trusted as every other op's lowering is.

def Proofs.StableHLO.mbNoExpGraphSync (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc rd kh kw : ℕ} (q : MBWNoExp ic oc rd kh kw) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * h * w))) :
Fin R → SHlo (N * (oc * h * w))

MBConv1 (b1, no expand) at sync-BN, over the replica family: depthwise → sync-BN → swish → SE → 1×1 project → sync-BN.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.StableHLO.mbNoExpGraphSync_shard (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc rd kh kw : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (q : MBWNoExp ic oc rd kh kw) (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 (mbNoExpGraphSync p epsStr R hR N h w q bf16 e r) = batchShard R N (oc * h * w) (mbNoExpW (R * N) h w q X) r
    def Proofs.StableHLO.mbBodyGraphSync (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc rd kh kw : ℕ} (q : MBW ic mid oc rd kh kw) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * h * w))) :
    Fin R → SHlo (N * (oc * h * w))

    The MBConv6 body at sync-BN — expand 1×1 → sync-BN → swish → depthwise → sync-BN → swish → SE → project 1×1 → sync-BN — shared by the residual (b3, b5, …) and the no-skip widening (b9, b16) blocks.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.StableHLO.mbBodyGraphSync_shard (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc rd kh kw : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (q : MBW ic mid oc rd kh kw) (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 (mbBodyGraphSync p epsStr R hR N h w q bf16 e r) = batchShard R N (oc * h * w) (mbExpW (R * N) h w q X) r
      def Proofs.StableHLO.mbResidGraphSync (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid rd kh kw : ℕ} (q : MBW c mid c rd kh kw) (bf16 : Bool) (e : Fin R → SHlo (N * (c * h * w))) :
      Fin R → SHlo (N * (c * h * w))

      The residual MBConv6 block (b3, b5, b7, b8, b10, b11, b13–b15): the body plus the identity skip, addV body e — body first, the order mbResidGraphB uses.

      Equations
      Instances For
        theorem Proofs.StableHLO.mbResidGraphSync_shard (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid rd kh kw : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (q : MBW c mid c rd kh kw) (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 (mbResidGraphSync p epsStr R hR N h w q bf16 e r) = batchShard R N (c * h * w) (mbResidW (R * N) h w q X) r
        def Proofs.StableHLO.mbStridedGraphSync (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc rd kh kw : ℕ} (q : MBW ic mid oc rd kh kw) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * h) * (2 * w)))) :
        Fin R → SHlo (N * (oc * h * w))

        The strided MBConv6 block (b2, b4, b6, b12): expand at the input grid 2h×2w, the strided depthwise down to h×w, SE and project there. Three sync sites, the expand one at 2h×2w.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Proofs.StableHLO.mbStridedGraphSync_shard (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic mid oc rd kh kw : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (q : MBW ic mid oc rd kh kw) (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 (mbStridedGraphSync p epsStr R hR N h w q bf16 e r) = batchShard R N (oc * h * w) (mbStridedW (R * N) h w q X) r
          def Proofs.StableHLO.stemGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (Ws : Kernel4 oc ic 3 3) (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 conv (XLA-SAME) → sync-BN → swish.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Proofs.StableHLO.stemGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (Ws : Kernel4 oc ic 3 3) (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 (stemGraphSync epsStr R hR N h w Ws bs εs γs βs bf16 e r) = batchShard R N (oc * h * w) (stemB (R * N) Ws bs εs γs βs X) r
            def Proofs.StableHLO.headGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c oc nC : ℕ} (Wh : Kernel4 oc c 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (bf16 : Bool) (e : Fin R → SHlo (N * (c * h * w))) :
            Fin R → SHlo (N * nC)

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

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem Proofs.StableHLO.headGraphSync_shard (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c oc nC : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (Wh : Kernel4 oc c 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (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 (headGraphSync epsStr R hR N h w Wh bh εh γh βh Wfc bfc bf16 e r) = batchShard R N nC (headFwdB (R * N) Wh bh εh γh βh Wfc bfc X) r
              def Proofs.StableHLO.mbResidDropGraphSync (p epsStr mN : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid rd kh kw : ℕ} (q : MBW c mid c rd kh kw) (bf16 : Bool) (s : Fin R → Vec N) (e : Fin R → SHlo (N * (c * h * w))) :
              Fin R → SHlo (N * (c * h * w))

              mbResidGraphSync with its drop site: replica r's dropPathB at its own per-example scale s r on the branch before the skip add — mbResidDropGraphB over the replica family.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem Proofs.StableHLO.mbResidDropGraphSync_shard (p epsStr mN : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c mid rd kh kw : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (q : MBW c mid c rd kh kw) (bf16 : Bool) (s : Fin R → Vec N) (S : Vec (R * N)) (hs : ∀ (r : Fin R), s r = exampleShard R N S r) (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 (mbResidDropGraphSync p epsStr mN R hR N h w q bf16 s e r) = batchShard R N (c * h * w) (mbResidDropW (R * N) h w q (some S) X) r

                With the replicas' scales the shards of one per-example mask S, replica r's block is shard r of mbResidDropW at S — the site's step is dropPath_shard, the rest mbResidGraphSync_shard's.

                def Proofs.StableHLO.headGraphSyncDo (epsStr mN : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c oc nC : ℕ} (Wh : Kernel4 oc c 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (bf16 : Bool) (ms : Fin R → Vec (N * oc)) (e : Fin R → SHlo (N * (c * h * w))) :
                Fin R → SHlo (N * nC)

                headGraphSync with the classifier-dropout site: replica r's dropoutB at its own mask ms r between the GAP and the dense — headGraphBDo over the replica family.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem Proofs.StableHLO.headGraphSyncDo_shard (epsStr mN : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c oc nC : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (Wh : Kernel4 oc c 1 1) (bh : Vec oc) (εh : ℝ) (γh βh : Vec oc) (Wfc : Mat oc nC) (bfc : Vec nC) (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 * (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 (headGraphSyncDo epsStr mN R hR N h w Wh bh εh γh βh Wfc bfc bf16 ms e r) = batchShard R N nC (headDoFwdB (R * N) Wh bh εh γh βh Wfc bfc (some M) X) r
                  def Proofs.StableHLO.efficientnetFwdGraphSyncFull (R : ℕ) (hR : 0 < R) (N : ℕ) (epsStr : String) {nCls : ℕ} (w : B0Weights nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (3 * 224 * 224))) :
                  Fin R → SHlo (N * nCls)

                  The sync-BN data-parallel EfficientNet-B0 forward graph, over the replica family. The single-device efficientnetFwdGraphBFull with every one of the 49 BatchNorms a bnSyncSiteLA over all R replicas, fed each replica's own input subgraph e r; block prefixes and collective tags are EfficientNetRender.Basic's.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Proofs.StableHLO.efficientnetFwdGraphSyncFull_shard (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (epsStr : String) {nCls : ℕ} (w : B0Weights 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 (efficientnetFwdGraphSyncFull R hR N epsStr w bf16 e r) = batchShard R N nCls (efficientnetForwardBFull (R * N) w X) r

                    The forward 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 efficientnetForwardBFull (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.efficientnetFwdGraphSyncFullDrop (R : ℕ) (hR : 0 < R) (N : ℕ) (epsStr : String) {nCls : ℕ} (w : B0Weights nCls) (bf16 : Bool) (ss : Fin 9 → Fin R → Vec N) (ms : Fin R → Vec (N * 1280)) (e : Fin R → SHlo (N * (3 * 224 * 224))) :
                    Fin R → SHlo (N * nCls)

                    The sync-BN data-parallel EfficientNet-B0 forward graph with both sites, over the replica family — efficientnetFwdGraphSyncFull with mbResidDropGraphSync at the nine skip-carrying blocks (replica r at its scales ss i r, the mask names dpName's at the render's block indices) and headGraphSyncDo as its head (replica r at its mask ms r); the forward of the dropdo DP train steps, efficientnetin_emarmsdp64dropdowxeps0001bf16's among them.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem Proofs.StableHLO.efficientnetFwdGraphSyncFullDrop_shard (R : ℕ) (hR : 0 < R) (N : ℕ) (hN : 0 < N) (epsStr : String) {nCls : ℕ} (w : B0Weights nCls) (bf16 : Bool) (ss : Fin 9 → Fin R → Vec N) (SD : Fin 9 → Vec (R * N)) (hs : ∀ (i : Fin 9) (r : Fin R), ss i r = exampleShard R N (SD i) r) (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 * 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 (efficientnetFwdGraphSyncFullDrop R hR N epsStr w bf16 ss ms e r) = batchShard R N nCls (efficientnetForwardBFullDrop (R * N) w (some SD) (some M) X) r

                      efficientnetFwdGraphSyncFull_shard at the sites: with the replicas' inputs the shards of one batch X, their scales the exampleShards of one per-example mask per site SD i and their masks the shards of one mask M, replica r's forward denotes shard r of efficientnetForwardBFullDrop (R * N) w (some SD) (some M) X.