mini-nccl
Distributed training collectives from first principles, over raw TCP.

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