Unit 4 of 14 · about 5 hours · measure
Timeline attribution and multi-rank trace alignment
A single step-time number hides whether input, kernels or collectives dominate. Aligned traces turn the number into an attributable timeline.
You'll be able to
- Attribute step time to CPU, input, kernel, memory and communication regions from a trace.
- Collect PyTorch profiler traces with NVTX ranges and align multi-rank timelines by collective markers.
- State observer overhead and cross-rank timing limits for every trace claim.
Covers
Read
In this order, only the parts listed
0 of 4 done
- PyTorch profiler, NVTX and Nsight timelinesAI Systems Performance Engineering - Chapters 1 to 5, 13 and 14
Chapter 13, Profiling PyTorch to Identify Bottlenecks, with Using PyTorch Profiler and System Profiling with Nsight Systems and NVTX Timelines
- Nsight traces and memory timelinesCS336 Assignment 2 (Spring 2026) - Profiling and Parallelism Analysis
Section 2.1.4
nsys_profileand Section 2.1.6memory_profilingin the Spring 2026 handout: trace-to-timer match, top kernels and the memory timeline - Reading a trace against predictionsHow to Scale Your Model - Chapters 1, 5, 9 and 12
Trace Viewer through the worked problems, including the feedforward versus ReduceScatter timing check and the memory profile
- Systematic profiling and fleet tracesMachine Learning Systems Volume II - Fleet Orchestration and Performance Engineering
System Profiling with the drill from application to operation, and Measurement at Scale on fleet traces and gray stragglers
Focus on
- Split the step into input wait, host transfer, forward and backward kernels, bucket collectives, optimizer and checkpoint.
torch.cuda.nvtx.range_pushandrange_popname regions so kernels map to source. - Ranks have skewed clocks, so align by collective entry and exit markers and sequence numbers, never by raw wall-clock order.
- The profiler perturbs the run: the MLSys book puts full traces with memory profiling at 10 to 20 percent overhead, and a recorded run can keep buffers alive longer and raise peak memory. Compare with and without profiling and state the overhead beside every trace claim.
Common mistakes · 3
- Ordering cross-rank events by unsynchronized wall-clock. Clock skew exceeds collective latency, so apparent order is not causal order.
- Quoting a profiled run's peak memory or step time as the production number. The trace shows the structure of the step correctly, but its absolute numbers overstate the unobserved run.
- Blaming the network for an NCCL wait when the peer is stalled in the data loader. The waiter is the victim; the straggler is the cause.
Try it yourself
Closed-book, before checking anything
torch.profiler.profile, record_shapes=True and torch.profiler.record_function labels around forward and backward (NVTX ranges show up in Nsight Systems, not in this trace), export the chrome trace, and name the top operation class by time.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.What do NVTX ranges add to a profiler trace?Answer
Named source regions around forward, backward and transfers. Kernels inside a range inherit its label, so time maps to code instead of anonymous kernels.
2.How do you align two rank timelines?Answer
By shared collective markers with matching sequence numbers and entry or exit events. Raw timestamps cannot order across skewed clocks.
3.How do you check profiler overhead?Answer
Compare step time and key counters with and without the profiler on the same fixed workload. Report the difference beside trace-derived numbers.
4.Rank 0 waits in
all_reducewhile rank 1 loads data. Which is the cause?AnswerRank 1 input stall is the cause. Rank 0 wait is the victim symptom; fixing the network would not move the step.
Practice
- CS336 Assignment 2:
nsys_profileandmemory_profilingSection 2.1.4
nsys_profileand Section 2.1.6memory_profilingin the Spring 2026 handout; match trace totals to timers and attribute peaks on the memory timelineStart with the CPU profiler path on your machine. Nsight portions need NVIDIA tooling; state observer overhead in the report.
You're done when
Your attributed timeline names the dominant region for one step, aligned across two ranks by collective markers, with overhead stated.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 7 more in the section
- Machine Learning Systems Volume II - Fleet Orchestration and Performance EngineeringML Systems Textbook · primary
Read Scheduling Problem, Orchestration Paradigms, Topology-Aware Scheduling, Elastic Scheduling, Cost Optimization, Multi-Tenancy and Quotas and Debugging Cluster Utilization, then Memory Wall and Roofline Diagnosis, Graph Compilation, Communication-Computation Overlap, System Profiling and Measurement at Scale at https://mlsysbook.ai/vol2/performance_engineering/performance_engineering.html. Use the framework to choose one bottleneck-specific lab and one rollback metric.
- AI Systems Performance Engineering - Chapters 1 to 5, 13 and 14Chris Fregly (O'Reilly) · required
Use Chapter 1 for goodput and reproducibility, Chapters 2 to 5 for topology, orchestration, communication, storage and the data pipeline, Chapter 13 for PyTorch profiling and scaling, and the Chapter 14 sections on graph breaks and recompilation. Run only the companion labs for the bottleneck you observe, preserve workload correctness and record hardware assumptions.
- How to Scale Your Model - Chapters 1, 5, 9 and 12Google DeepMind · required
Use rooflines, training cost models, profiling workflow and GPU topology to predict the dominant limit of one run. Compare the prediction with a trace and quantify the residual before proposing a change.
- CS336 Assignment 2 (Spring 2026) - Profiling and Parallelism AnalysisStanford University · required
Revisit Section 2 profiling and Section 8 communication analysis. Produce warmup-controlled timing, Nsight or PyTorch traces, memory evidence and analytic DP, FSDP, TP and 2D comparisons on configurations you can execute honestly.
Also in this section
- Machine Learning Engineering Open Book - Network, Debug, Training Performance and OrchestrationStas Bekman · required
Use
network/debug/README.md, the hang, crash and OOM sections ofdebug/pytorch.md,training/performance/README.md,storage/README.mdandorchestration/slurm/users.mdas an incident-driven reference. Build one symptom-to-evidence-to-cause runbook rather than reading every page. - PyTorch Flight Recorder TutorialsPyTorch · support
Read the environment-variable Flight Recorder tutorial (trace buffer, dump on timeout,
fr_traceanalysis), then the newer tutorial at https://docs.pytorch.org/tutorials/intermediate/debug_hangs_with_flight_recorder.html, which needstorchcommsand can run on CPU with Gloo. Diagnose one injected hang from per-rank dumps. - MegaScale: Scaling Large Language Model Training to More Than 10,000 GPUsJiang et al. (NSDI 2024) · support
Read the efficiency optimizations, the fault-tolerance loop (heartbeats, diagnostics, fast restart) and the straggler and diagnosis tooling. Its MFU and scale numbers are its own cluster's results.
- Revisiting Reliability in Large-Scale Machine Learning Research ClustersKokolis et al. (2024) · support
Read the failure taxonomy, mean time to failure versus job size and the scheduler-side metrics. Use them to model goodput with failures for one job size.
- Ultra-Scale Playbook - Benchmarking ConfigurationsHugging Face · support
Study the configuration-search experiments and Lessons learned on benchmarking as method. Its heatmaps are its own H100 cluster's results; reproduce the method on a tiny legal search space, separating analytic predictions, simulations and measurements.
- TorchTitanPyTorch · depth
Read
docs/debugging.md(memory snapshots, fake-backend modes, Flight Recorder dumps) and the CPU unit tests undertests/unit_tests/cpu/, then the configuration, metrics, profiling, checkpoint and parallelization seams at a pinned commit. Select one bounded issue or measurable improvement and follow the contribution standards; do not attempt a wholesale rewrite. - Distributed Training Systems LaboratoryRoadmap-Final · support
Complete the capstone with a fixed workload, correctness oracle, analytic plan, fault campaign, aligned traces and one real-code extension. Label CPU simulation, single-GPU evidence and multi-GPU evidence separately.