Module resources
ML systems and interviews
Checked sources to go further than the lessons. Back to the module.
Recommended learning sequence
Work through these in order.
ndcg_score (scikit-learn API reference) (opens in a new tab)
Start with the scikit-learn page for ndcg_score. It applies a logarithmic discount, divides by the ideal score and averages tied predictions by default, which is what lesson 1 relies on and what its homework version leaves out.
Fixing Gradient Accumulation (opens in a new tab)
For lesson 2, the Hugging Face account of the accumulation mismatch in its Trainer. It shows why token-level losses are divided by the total number of non-padding tokens and not averaged per micro-batch.
Automatic Mixed Precision package - torch.amp (opens in a new tab)
Then the torch.amp page: loss scaling against underflow, unscaling before the optimizer step, the GradScaler defaults and the warning about bf16-pretrained models in fp16. Read it beside the loss-scaling trace in the lesson.
torch.distributed.fsdp.fully_shard (FSDP2) (opens in a new tab)
Next, the FSDP2 page for fully_shard, with per-parameter sharding and reshard_after_forward. Compare it with the FSDP1 strategies the lesson maps onto the ZeRO stages.
Distributed Checkpoint - torch.distributed.checkpoint (opens in a new tab)
Then sharded checkpoints: saving from several ranks in parallel and resharding at load time, which is what lets a run resume on a different number of devices.
For lesson 3, the KFold reference, with its default of no shuffling and the one-row-larger first folds that the homework splitter reproduces.
All resources
Official documentation
torch.nn.parallel.DistributedDataParallel (opens in a new tab)
The no_sync() context manager for skipping the gradient all-reduce on non-final micro-batches, and how the skipped gradients are synchronised on the next backward pass.
Automatic Mixed Precision examples (opens in a new tab)
Worked loops for unscaling before gradient clipping and for keeping the loss scale fixed while gradients accumulate over an effective batch.
torch.utils.data (DataLoader) (opens in a new tab)
How num_workers, pin_memory and the prefetch_factor default behave, to check against the loader step-time model in lesson 2.
Reproducibility (opens in a new tab)
What PyTorch does and does not promise about identical results, the cost of deterministic algorithms and how to seed the DataLoader workers.
Research papers
The batch normalisation paper, for the point that its statistics come from the mini-batch it sees. That is why gradient accumulation does not reproduce a larger batch for these layers.
Adam: A Method for Stochastic Optimization (opens in a new tab)
The Adam paper, with the first and second moment estimates, two of the three fp32 optimizer-state tensors (8 of the 16 bytes per parameter) in lesson 2.
Attention Is All You Need (opens in a new tab)
The original transformer paper. Read the footnote on scaled dot-product attention that supports the variance argument used in worked answer 8 of lesson 3.