Documentation

LeanMlir.Proofs.Nets.ResNet.ResNet34SyncB

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

ResNet34FullB.lean says the typed batch-BN graph denotes resnet34ForwardBFull N w on one device (resnet34FwdGraphBFull_faithful). ResNet34RenderB renders the data-parallel step differently: at replicas > 1 every BatchNorm site is bnFwdSite's sync-BN composition — this replica's mean all-reduced, then Chan's σ²_r + (μ_r − μ)² all-reduced, packed, then bnSyncF — so the statistics each replica normalises by are the GLOBAL batch's. This file is that theorem's 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 (resnet34FwdGraphSyncFull R hR N epsStr w bf16 e r)
  = batchShard R N nCls (resnet34ForwardBFull (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 resnet34ForwardBFull, at N := R·N, and it does not move with the precision either: bf16 selects the conv kinds at every site (.convAt / .convStridedAt, as ResNet34FullB), bf16 := true being the graph of resnet34in_momdp64bf16, the run the book reports; 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 #

By induction on the chain, one block at a time, exactly as resnet34FwdGraphBFull_faithful is — with the shard hypothesis ∀ r, den (e r) = batchShard R N _ X r as the invariant carried from block to block:

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)), the index bnBatchTensor4 is stated at. bnBatchF hides that seam inside its den (bnBatchLA is bnBatchTensor4 conjugated by the mul_assoc relabelling). The sync site cannot, because its statistics subgraph is shared across replicas, so it carries the relabelling as castIdx on the AST value — h ▸ e, the move ConvNeXtRenderB's reassocB already makes. It changes no emitted text: skel never sees an index, and the render writes the same SSA name at both types (bnFwdSite's zbn operand beside its zin one).

What is NOT claimed here #

The backward and the parameter collectives are ResNet34SyncStepTieB.lean's. 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.r34IdGraphSync (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c : ℕ} (pw : R34IdW c) (bf16 : Bool) (e : Fin R → SHlo (N * (c * h * w))) :
Fin R → SHlo (N * (c * h * w))

Identity basic block at sync-BN, over the replica family: relu(addV(bn₂(conv₂(relu(bn₁(conv₁ e)))), e)) with both BatchNorms bnSyncSiteLA.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.StableHLO.r34IdGraphSync_shard (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {c : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (pw : R34IdW 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 (r34IdGraphSync p epsStr R hR N h w pw bf16 e r) = batchShard R N (c * h * w) (r34IdB (R * N) h w pw X) r
    def Proofs.StableHLO.r34DownGraphSync (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (pw : R34DownW ic oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * h) * (2 * w)))) :
    Fin R → SHlo (N * (oc * h * w))

    Downsample basic block at sync-BN, over the replica family: relu(addV(bnₚ(projection), bn₂(conv₂(relu(bn₁(convStrided₁ e)))))) — projection first, as residualProj and the render order it. Three sync sites.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.StableHLO.r34DownGraphSync_shard (p epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (pw : R34DownW ic 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 (r34DownGraphSync p epsStr R hR N h w pw bf16 e r) = batchShard R N (oc * h * w) (r34DownB (R * N) h w pw X) r
      def Proofs.StableHLO.r34StemGraphSync (epsStr : String) (R : ℕ) (hR : 0 < R) (N h w : ℕ) {ic oc : ℕ} (Ws : Kernel4 oc ic 7 7) (bs : Vec oc) (εs : ℝ) (γs βs : Vec oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * (2 * h)) * (2 * (2 * w))))) :
      Fin R → SHlo (N * (oc * h * w))

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

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Proofs.StableHLO.r34StemGraphSync_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 7 7) (bs : Vec oc) (εs : ℝ) (γs βs : Vec oc) (bf16 : Bool) (e : Fin R → SHlo (N * (ic * (2 * (2 * h)) * (2 * (2 * w))))) (X : Vec (R * N * (ic * (2 * (2 * h)) * (2 * (2 * w))))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (ic * (2 * (2 * h)) * (2 * (2 * w))) X r) (r : Fin R) :
        den (r34StemGraphSync epsStr R hR N h w Ws bs εs γs βs bf16 e r) = batchShard R N (oc * h * w) (r34StemB (R * N) h w Ws bs εs γs βs X) r
        def Proofs.StableHLO.r34HeadGraphSync {R : ℕ} (N h w : ℕ) {c nCls : ℕ} (Wd : Mat c nCls) (bd : Vec nCls) (e : Fin R → SHlo (N * (c * h * w))) :
        Fin R → SHlo (N * nCls)

        Head over the replica family: GAP then dense — no BatchNorm, so the single-device head graph per replica.

        Equations
        Instances For
          theorem Proofs.StableHLO.r34HeadGraphSync_shard {R : ℕ} (N h w : ℕ) {c nCls : ℕ} (Wd : Mat c nCls) (bd : Vec nCls) (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 (r34HeadGraphSync N h w Wd bd e r) = batchShard R N nCls (r34HeadB (R * N) h w Wd bd X) r
          def Proofs.StableHLO.resnet34FwdGraphSyncFull (R : ℕ) (hR : 0 < R) (N : ℕ) (epsStr : String) {nCls : ℕ} (w : R34BWeights nCls) (bf16 : Bool) (e : Fin R → SHlo (N * (3 * (2 * (2 * 56)) * (2 * (2 * 56))))) :
          Fin R → SHlo (N * nCls)

          The sync-BN data-parallel ResNet-34 forward graph, over the replica family. resnet34FwdGraphBFull with every BatchNorm a bnSyncSiteLA over all R replicas; block prefixes and collective tags are ResNet34RenderB's.

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

            Forward-graph faithfulness 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 resnet34ForwardBFull (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.