Zero-CPU-sync and multi-branch coalesced SyncBatchNorm for PyTorch 2.4+.
Two lossless (mathematically equivalent to ``torch.nn.SyncBatchNorm``) optimizations:
1. ``FastSyncBatchNorm`` (1A):
Replaces ``torch.nn.SyncBatchNorm``'s boolean-mask indexing
(``mask = count_all.squeeze(-1) >= 1; count_all[mask]...``), which triggers
``aten::nonzero`` CPU-GPU stream synchronizations on every SyncBN layer forward.
Empty ranks (``numel == 0``) send neutral stats (``mean=0, invstd=eps**-0.5,
count=0``) so non-empty ranks never hit division-by-zero without needing ``nonzero``.
2. ``MultiBranchSyncBNFunction`` / ``coalesced_sync_batchnorm`` (1B):
Fuses parallel independent Conv+SyncBN branches into a single
``dist.all_gather_into_tensor`` in forward and a single ``dist.all_reduce(SUM)``
in backward over packed 1D channel stats, keeping 4D feature maps unconcatenated.
Runtime toggles (enabled by default when ``sync_bn: True``):
- ``DFINE_FAST_SYNCBN=0``: disable both 1A and 1B and fall back to stock ``nn.SyncBatchNorm``.
- ``DFINE_COALESCE_SYNCBN=0``: disable 1B branch coalescing while keeping 1A active.
Packs local BatchNorm running_mean/running_var across ranks for ModelEMA.
When ``sync_interval == 1``, applies the exact Law-of-Total-Variance correction
using each rank's batch-mean deviation so multi-GPU ``running_var`` retains
inter-rank batch variance at ~0.08 ms/step (1 small packed all_reduce).