Skip to content
All projects

mini-nccl

Distributed training collectives from first principles, over raw TCP.

Year
2026
Status
Open source
Links
Source on GitHub
Line chart of all-reduce bus bandwidth over loopback TCP at 2 and 4 ranks. At 2 ranks, mini-nccl’s ring is above gloo at every message size.
From the project’s own benchmark suite.

The problem

Libraries like NCCL decide how gradients move between GPUs, and most people only ever see them as a black box. I wanted the whole stack small enough to read in an afternoon and measured well enough to trust.

What I built

  • Ring, binomial-tree and recursive halving-doubling all-reduce, plus reduce-scatter, all-gather, broadcast and all-to-all, on nothing but TCP sockets. No torch.distributed, MPI or NCCL underneath.
  • Against the gloo backend, the ring is faster at every message size at 2 ranks, and 4.6x faster at 64 MiB.
  • Data parallel, fully sharded, Megatron-style tensor parallel and pipeline parallel (1F1B and GPipe), composed into 2D and 3D meshes and checked gradient by gradient against unpartitioned execution.
  • Alpha-beta and PCIe bandwidth cost models that decide which optimizations ship. One that measured slower ships disabled.
  • Pinned host staging with CUDA streams, worth 1.7x on host-to-device copies.
  • 106 tests across world sizes 1 to 8, 91% coverage, mypy clean, and a mutation checker in CI that breaks the library on purpose to prove the tests notice.

Stack

  • Python
  • PyTorch
  • CUDA streams and pinned memory
  • TCP sockets
  • pytest
  • mypy
  • GitHub Actions