MLP Forward and Backward Core
Set up data and parameters, then implement the forward pass, loss, and manual backprop for a two-layer MLP.
Implement accumulation, checkpointing, mixed precision, all-reduce, and ZeRO-style optimizer sharding.
Every source step is its own lesson with intuition, concepts, correctly rendered MathJax mathematics, implementation, tests, mistakes, and a checkpoint.
Set up data and parameters, then implement the forward pass, loss, and manual backprop for a two-layer MLP.
Split batches into micro batches and accumulate gradients to emulate a large batch step under a tight memory budget.
Trade compute for memory by recomputing activations during backward and verify correctness and savings.
Run forward and backward in half precision while keeping a full precision master copy of the weights, with loss scaling and non-finite detection.
Shard data across workers, compute local gradients, and synchronize them with all-reduce, including a ring all-reduce and bucketed communication.
Partition Adam optimizer state and parameter updates across workers, then all-gather to reconstruct the full model.
Quantify model, optimizer, and activation memory, compare with and without optimizations, and run the end-to-end distributed memory-aware training loop.