Unit 12 of 12 · about 5 hours · implement
Exact resume state and tiny deterministic fixtures for systems debugging
Systems debugging is iteration speed times certainty: a tiny fixture that resumes exactly lets every later fault experiment run in seconds with an oracle to check against.
You'll be able to
- Specify the complete resume state for a training job and reject incompatible checkpoints explicitly.
- Build tiny deterministic fixtures that run a full interrupt and resume cycle in seconds on CPU.
- Prove uninterrupted versus resumed equivalence for data order, RNG draws and optimizer trajectory.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Tiny models and fast-debug disciplineMachine Learning Engineering Open Book - Training and PyTorch Debugging
Fast debug with Tiny Models, Tokenizers and Datasets: shrink width, depth, layers and data to the smallest case showing the bug, including the layer-count edit and the tiny-dataset recipe; Memory usage for the OOM triage that keeps fixtures small
- Deterministic resume patternDistributed Training Guide - Chapter 1 and Related Topics
Save and restore of torch, NumPy, Python and CUDA RNG into
rng.ptwithtorch.use_deterministic_algorithms(True); the01-single-gpuresume branch in https://github.com/LambdaLabsML/distributed-training-guide/blob/aed748914472cca80d8cfe139ab43ec63103913a/01-single-gpu/train_llm.py as the commit-then-read pattern to copy - Subsystem Milestone A as the fixture contractDistributed Training Subsystem
Milestone A: frozen golden data, model and update with a hand-checked step, plus the single-process golden trainer everything later compares against
Focus on
- Complete resume state is model, optimizer, scheduler, scaler, every RNG stream, data position with dataset version, and the code and config identity. The fixture asserts all of them; a CPU check shows
get_rng_stateandset_rng_stateround-tripping arandndraw exactly. - Compatibility is a gate, not a warning: tokenizer identity, config version, manifest version and world layout must match before loading. Mismatched loads can produce confident wrong results instead of errors.
- Tiny means seconds on CPU with the same code paths: same sampler, same accumulation, same checkpoint format, miniature sizes. A fixture that swaps in toy logic for speed proves nothing about the real path.
- Equivalence has a tolerance policy stated up front. Bitwise identity holds for CPU deterministic replay with the same thread count and library build; GPU reductions and TF32-class modes need a norm tolerance with its justification.
Common mistakes · 3
- Testing resume with the same process instead of a fresh one. In-memory state masks missing checkpoint rows; kill and relaunch to test what was actually written.
- Freezing the seed but not the data position. Identical RNG with a restarted cursor replays early examples and silently overtrains them.
- Validating on training loss alone. Loss can match while example order differs; assert consumed IDs and optimizer state, not just the scalar.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Loss matches after resume but per-example IDs differ from the twin. Is resume correct?Answer
No. Matching loss with different order is coincidence or averaging luck; the run trains a different example sequence and later updates diverge.
2.Why must the resume test relaunch a fresh process?Answer
Only a fresh process reads exclusively from the checkpoint files. A same-process test inherits live optimizer, RNG and loader state that hides missing rows.
3.A fixture passes on CPU bitwise but fails bitwise on GPU. What changes?Answer
The tolerance policy, not the verdict method. Parallel reduction order and matmul modes vary device results; assert a justified norm tolerance while keeping the CPU bitwise gate.
4.The checkpoint loads but the tokenizer version differs. Proceed?Answer
No. Token IDs map to different embeddings and a different objective. Reject and re-tokenize or retrain from the compatible artifact.
You're done when
Your fixture interrupts and resumes to identical IDs, draws and parameters on CPU, and refuses a changed config with a named reason.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 10 more in the section
- Distributed Training Guide - Chapter 1 and Related TopicsLambda Labs · required
Trace
01-single-gpu/train_llm.pyend to end with its README (argument parsing, model initialization, checkpoint save of model, optimizer and scheduler, timers and memory statistics), then the related-topics folders on determinism, gradient accumulation, effective batch size and optimized data loading. Produce a state-ownership table and prove identical data order and optimizer trajectory after a controlled interruption. - Machine Learning Engineering Open Book - Training and PyTorch DebuggingStas Bekman · required
Read training/README.md, training/dtype.md, training/reproducibility/README.md and the tiny-model, memory and profiling sections of debug/pytorch.md. Use its commands as a field checklist while diagnosing your own loop.
- Distributed Training SubsystemRoadmap-Final · support
Start Milestone A with the deterministic sampler, state manifest, event trace and single-process oracle. Keep extending this repository through DT-9.
Also in this section
- Machine Learning Systems Volume I - ML Frameworks, Model Training and BenchmarkingML Systems Textbook · primary
Read Model Training (Iron Law of Training Performance, Pipeline Architecture, Identifying Bottlenecks, Pipeline Optimizations), then ML Frameworks (Execution Problem, Differentiation Problem, Anatomy of a Training Step) at https://mlsysbook.ai/vol1/frameworks/frameworks.html and Benchmarking (Training Benchmarks, Benchmarking Best Practices) at https://mlsysbook.ai/vol1/benchmarking/benchmarking.html. Turn the reading into a state-ownership table and a deterministic train-resume trace before the CS336 exercises.
- Ultra-Scale Playbook - First Steps: Training on One GPUHugging Face · required
Read Memory usage in transformers, Activation recomputation and Gradient accumulation, then Appendix A1 on profiling. Derive weight, gradient, optimizer and activation bytes for your tiny model before measuring; the interactive calculator does not show its sequence length or recomputation setting, so compare it with the formulas only after setting both.
- CS336 Assignment 2 (Spring 2026) - Sections 2 and 3Stanford University · required
Complete
benchmarking_script,nsys_profile,mixed_precision_accumulation,benchmarking_mixed_precision,memory_profilingandgradient_checkpointingon model sizes your hardware fits, with your own solutions. Keep timing tables, memory predictions and failure notes; the FlashAttention kernel (Section 4) and the leaderboard (Section 9) are outside this stage. - AI Systems Performance Engineering - Chapters 13 and 14Chris Fregly (O'Reilly) · support
Read Chapter 13 on NVTX markers, the PyTorch profiler, memory and allocator tuning, activation checkpointing and the data input pipeline, and the Chapter 14 sections on graph breaks and recompilation. Use them to explain one profiled step of your own trainer; treat bundled expectations as the author's hardware results.
- Transformer Math 101EleutherAI · support
Use the compute, parameter, optimizer, gradient and activation memory equations as a second derivation of your memory ledger. Check each per-dtype byte count against your own trainer's state.
- Mixed Precision TrainingMicikevicius et al. (ICLR 2018) · support
Read the sections on FP32 master weights, loss scaling and FP32 accumulation. Connect each to a failure your trainer can show: lost small updates, underflowed gradients or overflowed products.
- PyTorch Profiler RecipesPyTorch · support
Use the profiler, memory snapshot and benchmark recipes only when the CS336 handout calls for them. Annotate one complete step and explain every visible gap or synchronization event.
- TensorTonic - Training Arithmetic ProblemsTensorTonic · support
Solve Training FLOP Estimator, Mixed-Precision Training Memory Accountant and Gradient Accumulation Equivalence (free problems in the Language Modeling from Scratch plan) before the CS336 measurements.
- PyTorch data loading API - DataLoader, Sampler and multi-process loadingPyTorch · reference
Read Data Loading Order and Sampler, Single- and Multi-process Data Loading with its Randomness subsection, and the DistributedSampler entry for
set_epoch,drop_lastpadding and worker seeding. Use it to define sampler position and worker sharding for the lineage and resume units. - PyTorch Autograd mechanics notePyTorch · reference
Read How autograd encodes the history with Saved tensors, Hooks for saved tensors, and Backward Hooks execution (whether each hook fires and in which order). Use it for the autograd graph, saved-tensor and hook-ordering claims.