Skip to content
mlmentorship

Profiling distributed ML workloads

Use step traces, roofline limits, and communication timelines to find the exposed bottleneck in training and inference.

Published · 7 min read ·Role-specific ·Advanced

Visual quick review

Distinguish an operation's total duration from the exposed portion that extends synchronized step time.

Critical-path accounting

Only the collective time exposed beyond useful computation extends the step

Only communication beyond useful overlap extends the stepA 40-unit collective overlaps 30 units of useful work. Its exposed tail is 10, not the full 40.Only communication beyond usefuloverlap extends the stepCommunication: forty shared-clockunitsUseful computation covers the firstthirtyTen units remain exposed aftercompute overlap
Read it this way: A 40-unit collective overlaps 30 units of useful work. Its exposed tail is 10, not the full 40. Is the exposed delay forty units or ten?
Full explanation 7 min read
Reading depth

Distributed workload profiling follows unfinished dependencies to the synchronized step boundary before selecting an optimization.

Summary

Which dependency must finish before the next optimizer transition can begin? Compare these hypothetical schedules, holding work and numerical results fixed. Assume aligned clocks and no compute/network resource interference.

ScheduleCompute interval, msCollective interval, msCompletion, msExposed tail, ms
Overlap0..104..10100
Serialized0..1010..16166

Both schedules contain sixteen milliseconds of aggregate activity, but only one needs sixteen milliseconds of elapsed time. The retained schematic also changes compute length; use the table, not that extra difference, to isolate overlap alone.

Learning objective: distinguish an operation’s total duration from the exposed portion that extends synchronized step time.

Critical-path accounting

Two step traces with the same collective duration but different exposed time

Two step traces with the same collective duration but different exposed time The upper trace has a long backward-compute bar and a shorter rounded collective bar on a second lane. The collective finishes before backward compute, so it contributes no exposed tail. The lower trace has a shorter backward-compute bar followed by a collective of exactly the same drawn length as the upper collective. A bracket labels that collective's full duration as exposed, and its step boundary is later. Direct labels identify all bars, boundaries, and conclusions. OVERLAPPED collective hidden compute network backward compute collective start step end exposed: 0 SERIALIZED collective exposed compute network backward compute same collective exposed tail: full duration start step end
the rounded network bars have equal duration. The upper collective finishes before compute; the lower collective extends completion. Compute lengths also differ here; the table isolates overlap with equal compute. This original schematic follows the DDP design note, JAX profiling guide, and Nsight Systems guide.
Check: Why can reducing equal-duration collectives have different effects on elapsed step time in the two traces?
Reference drawing

Critical-path accounting

Only the collective time exposed beyond useful computation extends the step

Only communication beyond useful overlap extends the stepA 40-unit collective overlaps 30 units of useful work. Its exposed tail is 10, not the full 40.Only communication beyond usefuloverlap extends the stepCommunication: forty shared-clockunitsUseful computation covers the firstthirtyTen units remain exposed aftercompute overlap
Derivation
Two step traces with the same collective duration but different exposed time The upper trace has a long backward-compute bar and a shorter rounded collective bar on a second lane. The collective finishes before backward compute, so it contributes no exposed tail. The lower trace has a shorter backward-compute bar followed by a collective of exactly the same drawn length as the upper collective. A bracket labels that collective's full duration as exposed, and its step boundary is later. Direct labels identify all bars, boundaries, and conclusions. OVERLAPPED collective hidden compute network backward compute collective start step end exposed: 0 SERIALIZED collective exposed compute network backward compute same collective exposed tail: full duration start step end
the rounded network bars have equal duration. The upper collective finishes before compute; the lower collective extends completion. Compute lengths also differ here; the table isolates overlap with equal compute. This original schematic follows the DDP design note, JAX profiling guide, and Nsight Systems guide.
Check: Why can reducing equal-duration collectives have different effects on elapsed step time in the two traces?
Read it this way: A 40-unit collective overlaps 30 units of useful work. Its exposed tail is 10, not the full 40. Is the exposed delay forty units or ten?

Read the trace from the outside in

1. Mark the training or inference step

Let compute finish at , a ready collective start at , and its duration be . If both results are required, completion is . The network tail is , not automatically . This simplified model excludes additional dependencies and interference. Launching an asynchronous operation does not establish that its result is ready.

2. Find large idle gaps

Trace each wait back to input readiness, a producing kernel, another rank, or host synchronization. If one rank’s required bucket is ready at twelve ms, the collective cannot start at four ms. With a six-ms collective, completion is at least eighteen ms in this simplified arrival model. Inspect all ranks, not only the fastest backward pass.

3. Find the longest exposed operations

Moving the six-ms collective inside the ten-ms compute window saves six ms in the controlled example. Halving a completely hidden collective saves zero ms there. Resource contention can invalidate either prediction; measure the resulting compute duration too.

Run controlled experiments

Keep shapes, batch, dtype, topology and timing scope fixed. Check numerical outputs before accepting a speedup. Record one hypothesis, change, predicted boundary movement, correctness result, measured median/tail, trace difference and keep/revert decision. Retain unsuccessful trials.

Change bucket readiness

New task: overlap the last bucket without using gradients before they exist.

Picture and change: move readiness from ten ms to four ms by changing bucket order or size. The six-ms collective then ends at ten instead of sixteen ms, if compute remains unchanged.

Check: a bucket ready at nine ms ends at fifteen ms; the tail is still five ms. An earlier API call without earlier data readiness does not produce the predicted gain.

Use when: the trace shows a genuinely exposed final communication bucket.

Change tensor handoff

New task: remove a redundant gather/reshard between adjacent operations.

Picture and change: a serial handoff costs two ms around ten-ms useful work, giving twelve ms total. A compatible producer/consumer layout removes that event, predicting ten ms before resource effects.

Check: two ranks holding additive partial results two and three represent five, not two. Removing their reduction is incorrect, even if the trace becomes shorter. Verify global outputs, communication semantics and temporary memory peaks.

Use when: layout conversion, rather than required mathematical reduction, extends the dependency path.

Reconstruct the diagnosis

Why can a shorter local backward pass leave the synchronized step unchanged?

Reasoned answer

Another rank or required transfer may still finish later. Compare input-ready, kernel and collective timestamps on aligned clocks. Only movement of the completion dependency establishes a step-time improvement.

Why AI labs care

Low utilization can reflect input stalls, small kernels, memory traffic, network waits, pipeline bubbles or host work. It does not identify a repair.

Start with stable measurements

Verify correctness, exclude compilation/warmup and capture several representative steady steps. Store software versions, topology, shapes, seed and profiler settings. State whether median and p95 measure rank-local device work or synchronized wall-clock steps. Check instrumentation overhead and clock alignment.

Build three lower bounds

Compute bound

Useful FLOPs divided by applicable peak FLOPs gives an optimistic compute-time floor. State precision and the FLOP convention.

Memory bound

Bytes moved divided by effective bandwidth bounds a specified kernel’s memory time. Roofline compares intensity against the compute/bandwidth ratio.

Communication bound

Use latency plus per-device bytes divided by measured collective bandwidth for the matching message size and group. Peak link bandwidth is insufficient. These bounds may overlap; adding them is not a general elapsed-time bound.

4. Group kernels by type

Separate matmuls, attention, elementwise work, copies and collectives. Tiny kernels suggest launch/fusion investigations; poor matmul shapes suggest a different experiment.

5. Compare ranks

Compare input lengths, arrivals, device clocks, network placement and thermal behavior.

Common trace patterns

PatternDiscriminating check
Early idle gapinput-ready timestamp
Tiny kernels and gapslaunch overhead versus fusion
Late bucketreadiness and rank arrivals
Repeated reshardproducer/consumer layouts
Pipeline bubblesstage balance and microbatches

Profiling a sharded program

Record layouts and identify inserted gathers, reduce-scatters, all-reduces, all-to-alls and host transfers. Preserve the distinction between complete values and additive partial results.

Profiling compilation

Match source operations and shapes to compiled fusions, device kernels, communications and allocation peaks. One source operation need not correspond to one kernel.

In an interview

Define the workload and metric, locate the completion dependency, predict one change, then measure correctness and timing together.

Common mistakes

One fast warmup-contaminated sample is not a steady-state speedup. Changing batch size confounds a kernel comparison. Synthetic timelines establish arithmetic, not measured hardware performance.

Related: GPU memory hierarchy, strong scaling and parallelism selection, and optimize an accelerator workload. Further reading: profiling in the JAX Scaling Book.