A training step ends when its longest required dependency path ends
Construct an execution dependency graph and identify which duration changes can actually reduce completed training-step time.
On this page
The question for today
What you’ll understand
- Distinguish aggregate operator time from completed wall time.
- Calculate earliest finishes in a duration-weighted dependency DAG.
- Predict a bottleneck switch before proposing an optimization.
A profile table may report more device time than the wall time of a training step because operations on different resources overlap. It may also hide a costly wait beneath an operator whose own kernel is short. To explain the step, reconstruct the required dependencies between input readiness, forward computation, backward computation, communication, and the optimizer. The relevant finish is the declared completion boundary. Summing every visible duration does not identify the path that determines it.
Make completion and dependencies explicit
Represent an operation or required wait as a node with a nonnegative duration. Directed edges indicate that one operation must finish before another can begin. Data dependencies, same-stream ordering, collective completion, and an optimizer's need for particular gradients all contribute edges. A CPU launch call is different from the device work it enqueues. Decide whether a step ends after launches, after device completion, or after a valid optimizer update; these boundaries answer different questions. Include input and communication only when the chosen end-to-end boundary actually requires them.
For an ideal dependency DAG with sufficient resources, the earliest finish of a node is its duration plus the latest predecessor finish. The latest required sink gives the schedule's completion time. Real resources can serialize otherwise independent nodes or introduce contention and queuing. Add the corresponding constraints or describe the DAG result as a lower bound. A trace gives one observed schedule, not all counterfactual schedules after optimization. Removing an operation can change resource pressure and the chosen kernel path, so preserve the model's assumptions when making predictions.
Optimize a required path rather than a large total
An operation can consume substantial aggregate device time while having slack before the next required join. Shortening it within that slack need not change step completion. Conversely, a small exposed communication tail at the end of backward execution can lie directly on the finish path. Inspect launch readiness and the consuming operation, not only the total size of a category. A ranked operator table helps select candidates, but its inclusive entries may overlap each other and cannot safely be added as independent pieces of wall time.
Even in a fixed ideal DAG, speeding up the currently longest branch can make a previously shorter branch become critical. A projected saving therefore saturates when another required path catches up. For a single shortened node, the graph's finish reduction cannot exceed the amount removed from that node, and it may be zero. If an experiment saves more, investigate changed scheduling, contention, work, or measurement boundaries rather than claiming the fixed-duration DAG predicted that effect. Counterfactual reasoning is useful precisely because its assumptions are visible.
Validate the predicted path with completed work
Capture enough adjacent steps to distinguish steady execution from initialization, compilation, allocator growth, and data-loader startup. Correlate operator names with stream dependencies and required collective completions. State whether gradient accumulation spans several microbatches before the optimizer boundary. After a change, verify equivalent valid work and numerical behavior, then compare the observed finish with the predicted saving. A shorter kernel that moves a wait elsewhere is not yet an end-to-end improvement. Preserve the before-and-after trace and the hypothesis it was meant to test.
The roofline lab supplies a separate resource ceiling rather than a scheduler. Reset, set both intensity I=2 FLOP/byte and memory bandwidth B=100 decimal GB/s, predict 200 GFLOP/s, then Play. Reset and set both I=4 and B=100 to predict 400. Its fixed compute roof is 1000 GFLOP/s and playback traces that roof without changing the chosen kernel. The instrument contains no training DAG, launch queue, collective, or completion boundary. Use its ceiling to ask about a resource constraint; use the dependency calculation to explain when improving that resource can shorten the step.
Work it through
A faster branch can have no effect until the other branch changes
A toy completed step has a 3 ms preparation, followed by independent 8 ms compute and 5 ms communication branches, followed by a 2 ms join-dependent update. Assume sufficient resources, fixed durations, and no other edges.
Both branches begin at 3 ms. Compute ends at 11 ms and communication at 8 ms, so the update ends at 13 ms. Summing node durations would give 18 ms and incorrectly count overlap twice.
Reducing communication from 5 ms to 2 ms still leaves compute ending at 11 ms, so the completed step remains 13 ms. This communication branch originally had 3 ms of slack at the join.
Reducing compute instead from 8 ms to 4 ms makes communication the longer branch. The new step is 3+max(4,5)+2=10 ms, a saving of 3 ms and speedup 13/10=1.3 rather than a 4 ms saving.
The dependency path, including its possible switch, determines the saving in this ideal example. The result is a counterfactual model to validate against an actual completed-step measurement.
The living notebook
Explore the model
Interactive lab · roofline
A resource ceiling is one input to a path analysis
Reset, set both I=2 FLOP/byte and B=100 decimal GB/s, predict 200 GFLOP/s, then Play. Reset and re-enter both I=4 and B=100 for 400. The synthetic ceiling is min(1000,B×I); playback does not run a scheduler or change kernel parameters. It cannot turn an operator's resource ceiling directly into a completed training-step speedup.
- Attainable ceiling
- 640 GFLOP/s
- Ridge intensity
- 12.5 FLOP/byte
- Ceiling regime
- Memory-bound ceiling
Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forConnect a proposed resource improvement to a required dependency path before predicting wall-time savings.
Pause & reason
Check your understanding
Your turn
Try it yourself
A 2 ms source precedes parallel branches of 6 ms and 10 ms, then a 1 ms sink. Find completion, then compare separately shortening the 6 ms branch to 3 ms and shortening the 10 ms branch to 7 ms.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Recompute the maximum branch finish after each separate change rather than subtracting every saved duration.
Compare with the solution
Baseline completion is 2+max(6,10)+1=13 ms. Shortening the 6 ms branch alone leaves 13 ms. Shortening the 10 ms branch alone gives 2+max(6,7)+1=10 ms. These predictions assume the durations, dependencies, resources, and completion boundary otherwise remain unchanged.
Keep the idea
Take it with you
- A completed step follows required dependencies rather than the sum of all profile entries.
- Slack and bottleneck switches limit savings even in an ideal fixed DAG.
- Validate a predicted path reduction using equivalent completed work and correlated traces.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.