Documentation

LeanMlir.Proofs.Nets.ResNet.ResNet50SyncB

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

ResNet50FullB (T2) says the typed batch-BN graph denotes resnet50ForwardB_full N q w on one device. At replicas > 1 the data-parallel render makes every BatchNorm site 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 T2'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 (resnet50FwdGraphSync_full R hR N q epsStr w e r)
  = batchShard R N nCls (resnet50ForwardB_full (R * N) q 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 resnet50ForwardB_full, at N := R·N. ⭐ The resolution stays a binder: one statement covers q = 7 (224 px) and q = 5 (160 px), the ladder written as T2 writes it, 2 * (…) nests throughout.

How it is proved #

By induction on the chain, one block at a time, exactly as T2 is — with the shard hypothesis ∀ r, den (e r) = batchShard R N _ X r as the invariant carried from block to block. Every piece that is not about the bottleneck is ResNet34SyncB's, imported:

What is new is the three bottleneck forms at variable shapes (N ic mid oc h w all variables), each with three sync sites (four with the projection). ⚠ The two projection forms add in the RENDER's order, addVB(body, projection), where residualProj proj body adds proj + body; that costs one commutation, den_addVB_shard_comm, exactly the add_comm T2 carries.

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 sync site carries the relabelling as castIdx on the AST value (ResNet-34's bnSyncSiteLA), which changes no emitted text.

What is NOT claimed here #

⚠ No stochastic depth: the graph is the drop-path-free forward, as T2's is. ⚠ The f32 nodes — the bf16 conv twins are not this statement. ⚠ The DP artifacts run with no conv biases; the bias operand is biasName false "" c, the render's own function, and the bias fields stay -quantified as in T2. ⚠ The backward and the parameter collectives are the T3 half (ResNet50SyncTieB.r50_net_syncTiedB). ⚠ That the R replicas' inputs ARE the shards of one batch is the driver's, as in DataParallelSync. ⚠ The lowerer's all_reduce is trusted as every other op's lowering is.

theorem Proofs.StableHLO.den_addVB_shard_comm {R N n : } (a b : Fin RSHlo (N * n)) (A B : Vec (R * N * n)) (ha : ∀ (r : Fin R), den (a r) = batchShard R N n A r) (hb : ∀ (r : Fin R), den (b r) = batchShard R N n B r) (r : Fin R) :
den ((a r).addVB (b r)) = batchShard R N n (fun (j : Fin (R * N * n)) => B j + A j) r

The residual fan-in on every replica, with the SECOND operand first on the right: the render emits addVB(body, projection) and residualProj proj body adds proj + body.

def Proofs.StableHLO.r50IdGraphSync (p epsStr : String) (R : ) (hR : 0 < R) (N h w : ) {mid oc : } (pw : R50IdW mid oc) (e : Fin RSHlo (N * (oc * h * w))) :
Fin RSHlo (N * (oc * h * w))

Identity bottleneck at sync-BN, over the replica family: relu(addVB(bn₃(conv₃(relu(bn₂(conv₂(relu(bn₁(conv₁ e))))))), e)), every BatchNorm a bnSyncSiteLA. T2's r50IdGraphB with the three sites swapped.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Proofs.StableHLO.r50IdGraphSync_shard (p epsStr : String) (R : ) (hR : 0 < R) (N h w : ) {mid oc : } (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (pw : R50IdW mid oc) (e : Fin RSHlo (N * (oc * h * w))) (X : Vec (R * N * (oc * h * w))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (oc * h * w) X r) (r : Fin R) :
    den (r50IdGraphSync p epsStr R hR N h w pw e r) = batchShard R N (oc * h * w) (r50IdB (R * N) h w pw X) r
    def Proofs.StableHLO.r50ProjGraphSync (p epsStr : String) (R : ) (hR : 0 < R) (N h w : ) {ic mid oc : } (pw : R50ProjW ic mid oc) (e : Fin RSHlo (N * (ic * h * w))) :
    Fin RSHlo (N * (oc * h * w))

    ⭐ Stride-1 projection bottleneck at sync-BN — stage 1 block 0: the identity bottleneck's body plus a 1×1 conv → sync-BN skip at unchanged resolution, added in the render's order addVB(body, projection). Four sync sites.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Proofs.StableHLO.r50ProjGraphSync_shard (p epsStr : String) (R : ) (hR : 0 < R) (N h w : ) {ic mid oc : } (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (pw : R50ProjW ic mid oc) (e : Fin RSHlo (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 (r50ProjGraphSync p epsStr R hR N h w pw e r) = batchShard R N (oc * h * w) (r50ProjB (R * N) h w pw X) r
      def Proofs.StableHLO.r50DownGraphSync (p epsStr : String) (R : ) (hR : 0 < R) (N h w : ) {ic mid oc : } (pw : R50ProjW ic mid oc) (e : Fin RSHlo (N * (ic * (2 * h) * (2 * w)))) :
      Fin RSHlo (N * (oc * h * w))

      Strided projection bottleneck at sync-BN — stages 2/3/4 block 0. ⚠⚠ v1.5: the stride is on the 3×3 and the 1×1 skip, so conv₁ and its sync-BN (bn₁) run at the INPUT resolution 2h × 2w — that site's statistics reduce over N·(2h)·(2w) per replica. Four sync sites, added in the render's order addVB(body, projection).

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Proofs.StableHLO.r50DownGraphSync_shard (p epsStr : String) (R : ) (hR : 0 < R) (N h w : ) {ic mid oc : } (hN : 0 < N) (hh : 0 < h) (hw : 0 < w) (pw : R50ProjW ic mid oc) (e : Fin RSHlo (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 (r50DownGraphSync p epsStr R hR N h w pw e r) = batchShard R N (oc * h * w) (r50DownB (R * N) h w pw X) r
        def Proofs.StableHLO.resnet50FwdGraphSync_full (R : ) (hR : 0 < R) (N q : ) (epsStr : String) {nCls : } (w : R50BWeights nCls) (e : Fin RSHlo (N * (3 * (2 * (2 * (2 * (2 * (2 * q))))) * (2 * (2 * (2 * (2 * (2 * q)))))))) :
        Fin RSHlo (N * nCls)

        The sync-BN data-parallel ResNet-50 forward graph, over the replica family. T2's resnet50FwdGraphB_full with every BatchNorm a bnSyncSiteLA over all R replicas; block prefixes (s1b0s4b2) and collective tags are the render's. The stem and head are ResNet-34's sync graphs, whose names R50 shares.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Proofs.StableHLO.resnet50FwdGraphSync_full_shard (R : ) (hR : 0 < R) (N : ) (hN : 0 < N) (q : ) (hq : 0 < q) (epsStr : String) {nCls : } (w : R50BWeights nCls) (e : Fin RSHlo (N * (3 * (2 * (2 * (2 * (2 * (2 * q))))) * (2 * (2 * (2 * (2 * (2 * q)))))))) (X : Vec (R * N * (3 * (2 * (2 * (2 * (2 * (2 * q))))) * (2 * (2 * (2 * (2 * (2 * q)))))))) (he : ∀ (r : Fin R), den (e r) = batchShard R N (3 * (2 * (2 * (2 * (2 * (2 * q))))) * (2 * (2 * (2 * (2 * (2 * q)))))) X r) (r : Fin R) :
          den (resnet50FwdGraphSync_full R hR N q epsStr w e r) = batchShard R N nCls (resnet50ForwardB_full (R * N) q w X) r

          ⭐⭐ T2 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 resnet50ForwardB_full (R * N) q w X — the committed batch-BN forward, at the global batch, at the same resolution binder q (q = 7 the 224-px net, q = 5 the 160-px one). One block lemma per block, the shard hypothesis threaded from each into the next. 0 < q is what makes every BatchNorm's reduction width nonzero.