Course · Performance diagnosisPhase 08 · Study guide

What measured evidence identifies the bottleneck?

Training Systems · Local CPULaptop CPU5 lessons (~7.6h)

Revision v0.18.1 ·

Before changing an implementation, decide which part of the user's wait you are trying to reduce. Compilation, dispatch, transfer, device execution and synchronization can occupy different portions of a run. A fast return from a Python call may measure submission rather than completed work. First establish numerical equivalence, then choose a repeatable timing boundary. Read a retained trace by its named events and nesting, and use roofline or rematerialization calculations as hypotheses about a tradeoff. Connect a proposed change to the operation's share of the complete workload before expecting a large end-to-end gain.

Preparation: Neural network training

Runtime: CPU for timing concepts; TPU or GPU for profiling

Check your starting point

A JAX call returns an array handle almost immediately. Does a timer ending there necessarily measure completed computation?

Compare your reasoning

No. Synchronize the result inside the measured boundary. Report first-call setup separately from warmed execution and keep inputs, dtype and output checks fixed.

If this is unfamiliar, work through Benchmark asynchronous work correctly before attempting the project.

Build in stages

1. Choose a comparable measurement

Record warmup, synchronization and sample distributions. Change shapes and host reads separately so you can identify their effects.

2. Explain the evidence

Locate one annotated operation in a real trace, distinguish nested from additive time and state the memory level behind a roofline estimate.

3. Test a tradeoff

Compare rematerialized and ordinary gradients before timing. Distinguish saved residuals, compiler estimates and observed peak memory.

Try a changed condition

Make a prediction before opening the reasoning. Keep your answer and the evidence you would collect.

A step takes 100 ms, of which one kernel takes 10 ms. That kernel becomes twice as fast while everything else stays fixed. Predict the new step time.

Compare an approach

The estimate is 90+5=9590+5=95 ms, a speedup of about 1.053. A 2x kernel improvement is compatible with a small end-to-end gain. If the observed time differs, inspect the timing boundary, changed transfers, compilation and overlap rather than forcing the trace to fit the estimate.

Diagnose a likely failure

Symptom: A claimed speedup disappears in repeated runs.

Check next: Check equivalent work, compilation reuse, synchronization, sample spread and competing system activity; retain the raw samples.

Decide what is ready

Use the trace and timing stage of sharded-training. Keep before/after correctness, named measurement boundaries, trace locations and distributions with a justified accept/reject decision.

Where to put your project code

Write your code in: projects/performance-audit/starter/model.py (copy projects/performance-audit/starter/model.py first: cp projects/performance-audit/starter/model.py projects/performance-audit/starter/model.py).

Verify your implementation: python3 projects/performance-audit/tests/check.py --stage all --impl projects/performance-audit/starter/model.py

Run the staged project checks on your implementation in projects/performance-audit/starter/model.py and record your transfer experiment results in your portfolio.

Open Measure CPU JIT latency and changed-shape traces with retained JAXPR evidence

Open Resume and profile a sharded training run

What still needs further work

CPU traces do not characterize TPU/GPU communication or memory. Target traces and sustained workload measurements remain required for accelerator claims.