The sync-BN data-parallel kit — sharding, homogeneity and the collectives, per op kind #
Every net's sync-BN twin (its forward tie and its step tie) says that R replicas at batch N, each running the
render's replica program over its shard, compute the single-device step at the global batch R·N.
The per-op facts that argument is assembled from are stated here once:
| what | names | namespace |
|---|---|---|
the c·h·w ↔ c·(h·w) index cast and sharding through it; non-BN nodes commute with the batch cut; the BN sync site | castIdx, la_assoc, batchShard_castIdx, den_castIdx_shard, den_batchOp_shard, den_relu_shard, den_relu6_shard, den_swishF_shard, den_addVB_shard, den_addVB_shard_comm, den_addV_shard, bnSyncSiteLA | StableHLO |
| homogeneity — each cotangent step and gradient node is linear in its cotangent | *_smul | SyncKit |
| sharding — each input-VJP is per example, so it commutes with the batch cut; sync-BN's backward is the shard of the global one | *_shard, bnSyncInB_shard | SyncKit |
P4 — the replica mean of a weight-gradient node is 1/R of the global node | den_allReduceMeanF_*_shard | SyncKit (and DataParallel.Sync for conv W / BN β) |
per-parameter DP ties at R × the shards of a global cotangent | *Sync, *Sync_of_scaled | SyncKit |
the divisor: a replica's loss cotangent is R × its shard of the global one | replicaLossCot_eq | SyncKit |
Every twin cites these names.
References #
- Chan, Golub, LeVeque 1982, Updating Formulae and a Pairwise Algorithm for Computing Sample Variances (COMPSTAT; the pairwise combine rule). https://doi.org/10.1007/978-3-642-51461-6_3
Sharding commutes with relabelling the per-example index. The batch axis is outside the per-example one, so relabelling within an example and cutting the batch do not interact.
A per-example node on every replica denotes the shard of the same node on the global batch.
den_addVB_shard with the SECOND operand first on the right: ResNet-50's render emits
addVB(body, projection), and residualProj proj body adds proj + body.
The per-example identity skip spelled addV (EfficientNet-B0's MBConv) on every replica is
the shard of the global one.
relu6 on every replica is the shard of the global relu6 — the clamp reads one cell, so
cutting the batch before or after it is the same. Stated at the whole-batch relu6 the
committed forwards are written in.
A per-example relabel on every replica is the shard of the relabelled global batch — e.g.
MobileNetV4's head casts [N, c] ↔ [N, c, 1, 1], read at the network index.
One sync-BN forward site, at the network index, on replica r — bnFwdSite's
replicas > 1 branch: bnSyncF of this replica's operand, reading syncStats over all R
replicas' operands (the mean collective t, then Chan's variance collective t'), with the
mul_assoc relabelling on the way in and out.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The sync-BN site on replica r is shard r of the global-batch BatchNorm.
den_bnSyncF_allReduce (P1 on the graph), carried across the mul_assoc seam: the right-hand
side is bnBatchLA — what bnBatchF denotes — at N := R·N.
The two-sided relu6 mask is linear in the cotangent it gates.
The three-term BatchNorm input-gradient is linear in dy — both its reductions are.
The 3×3/s2 pool's select_and_scatter is linear in the cotangent it scatters.
Replica r's sync-BN input cotangent, as bnBackSite's replicas > 1 branch computes it,
in the network layout: this replica's [μ ‖ σ² ‖ mean(γ·dy) ‖ mean(x̂·γ·dy)]
(bnSyncDyStatsB, reading the forward's syncStats) all-reduced, then bnSyncBack. The
replica peer of BackLinks.bnInB, and like it written as the den of the emitted nodes
over .operand leaves.
Equations
- One or more equations did not get rendered due to their size.
Instances For
reassocB of a shard is the shard of the reassocB.
The sync-BN backward on replica r is shard r of the global-batch BN backward —
den_bnSyncBack_allReduce (P2 on the graph) at the network index. The right-hand side is
bnInB, the single-device chain's BN link, at N := R·N.
P4 at the STRIDED conv weight — den_allReduceMeanF_convWeightGradB_shard's strided peer.
P4 at the dense weight — the head's Σ_n outer product, split by replica.
P4 at the dense bias — Σ_n cot, split by replica.
One conv weight, DP-tied: the mean over replicas of each replica's weight-gradient node (at its shard of the layer input and its own cotangent) IS the single-device node at the global batch. Tags are the render's: the collective is named for the parameter.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The strided conv weight, DP-tied.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One BatchNorm's γ and β, DP-tied. Each replica's γ node is bnSyncGammaGradB, reading the
forward's all-reduced [μ ‖ σ²] (syncStats over the replicas' pre-BN activations, tagged
{tg}mu / {tg}var as bnFwdSite tags them), so its x̂ is the global batch's; the β node
reads no statistic. The right-hand sides are the single-device bnGammaGradB /
bnBetaGradB at N := R·N — BnPairTiedB's nodes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A replica family at R × the shards of COT gives the DP tie — the collective's 1/R
(inv_mul_R) cancels the R the homogeneity lemmas (*_smul) carry. The same three lines for
every kind below.
The divisor step. Replica r divides its smoothed-CE cotangent by B — the render's
divConstB at the per-replica batch — and the single-device step at the global batch divides
by R·B. At the replica's shard of the logits and targets, the replica's cotangent is R ×
its shard of the global one. Nothing else about the loss differs: softmax, the label-smoothing
shift and the target are per example.
The row-wise input-VJP dX = W·dy (the classifier's, and the SE excite dense's) is linear in
dy.
The row-wise input-VJP is batchMap of W·, so it shards like every per-example lift.
P4 at the depthwise weight — each replica's Σ_n over its own examples, averaged, is 1/R
of the global batch's Σ_n.
P4 at the strided depthwise weight.
P4 at the XLA-SAME strided depthwise weight (MobileNetV2's b2 / b4 / b7 / b14,
EfficientNet-B0's b2 / b4 / b6 / b12).
P4 at the XLA-SAME strided conv weight (the stem) — den_allReduceMeanF_convWeightGradB_shard's
peer. Only the certificate differs from the symmetric strided one; the batch split is the same.
A depthwise weight, DP-tied — the collective over the [c, 1, kH, kW] kernel the render
all-reduces, against the single-device node at the global batch.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The strided depthwise weight, DP-tied.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The stem's XLA-SAME strided conv weight, DP-tied. Tags are the render's: the collective is
named for the parameter, over its [oc, ic, kH, kW] shape.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The XLA-SAME strided depthwise weight, DP-tied.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The swish, sigmoid, SE and sync-BN links shard #
The SE gate cotangent, per example: channel k's spatial sum of x ⊙ dy.
Equations
Instances For
The SE gate cotangent reads one example at a time — seReduceB is batchMapAux of
gateEx — so it shards like ResNet-34's pool backward.
The sync-BN backward on replica r is shard r of the certified global BN backward —
bnSyncInB_shard (P2 at the network index) read through bnInB_eq_bnBackB, so the right-hand
side is bnBackB, the single-device tie's own BN link.