advanced28 min studyLesson 564 in Engineering

Interleaved pipeline schedules

Map virtual chunks to physical ranks and trade a smaller ideal bubble against additional boundaries and schedule constraints.

On this page

What you’ll understand

  • Distinguish virtual stage order from physical device identity.
  • Calculate the original balanced interleaving bubble under its assumptions.
  • Account for extra communication and version-specific scheduling constraints.

A device can own several nonconsecutive chunks of the model instead of one contiguous stage. Interleaving those virtual stages can shorten the modeled flush bubble, but it adds boundaries and competition for the same physical device. This lesson follows the Megatron-LM 2021 interleaved 1F1B analysis and explicitly distinguishes it from PyTorch 2.8’s more flexible schedule constraints. A virtual stage is a scheduling unit, not another accelerator with independent compute capacity.

Separate logical order from rank ownership

With four physical ranks and two chunks per rank, a simple looped placement assigns virtual stages zero through three to ranks zero through three, then stages four through seven to those same ranks again. One microbatch must follow virtual order, including the boundary from virtual stage three on rank three to virtual stage four on rank zero. Two virtual stages on the same rank cannot both claim the full device compute resource at the same modeled time. The schedule chooses among their ready operations.

Each virtual chunk has its own activation identities and backward dependencies. A message needs to identify the logical boundary, microbatch, and direction rather than just a physical neighbor. A rank can receive traffic for different chunks, so a buffer indexed only by peer rank can be reused incorrectly. The local priority rule matters as well: depth-first and breadth-first policies choose different ready work. PyTorch 2.8 documents interleaved 1F1B’s preference for earlier microbatches when several local stages are ready.

rank⁡(j)=j mod P,chunk⁡(j)=⌊jP⌋,0≤j<Pv\operatorname{rank}(j)=j\bmod P,\qquad \operatorname{chunk}(j)=\left\lfloor\frac{j}{P}\right\rfloor,\qquad 0\leq j<Pv
For this particular looped placement, P physical ranks each own v chunks. The formula maps a virtual-stage index j to a physical rank and local chunk number. Other mappings are possible, and this arithmetic does not choose a valid execution order.↔ Scroll wide equations horizontally.

A shorter ideal bubble buys more boundaries

The original balanced analysis splits each device’s previous forward and backward work into v equal chunks. Under its legal interleaved order and ideal communication assumptions, the bubble duration is divided by v while useful per-device computation remains unchanged. That result is about a specific balanced model; smaller chunks can be less efficient, and their extra boundaries can expose communication startup and bandwidth costs. A nominal reduction in idle compute does not establish a shorter measured iteration when the link becomes the bottleneck.

The original Megatron schedule requires a microbatch count divisible by the physical pipeline size. PyTorch 2.8 describes a flex scheduling rule that relaxes that original restriction, with its own admissibility condition. Do not impose a paper’s constraint on every later runtime or assume every arbitrary count is legal. Validate the chosen schedule constructor and version, then trace its warmup and cooldown. A zero-bubble label on a different schedule also has separate backward-partition and timing assumptions and is not a property inherited by all interleaving.

Tbubble,int=(P−1)(f+b)v,Tideal=M(f+b)T_{\mathrm{bubble,int}}=\frac{(P-1)(f+b)}{v},\qquad T_{\mathrm{ideal}}=M(f+b)
In the original balanced interleaving model, f and b are total per-device forward and backward times per microbatch before splitting into v equal chunks. Positive times share units, and the microbatch count must satisfy that schedule’s constraints. Exposed communication and scheduling overhead are omitted.↔ Scroll wide equations horizontally.

Compare the complete resource trace

Count boundary tensors explicitly for the selected layout. In a simple chain with equal-size boundary payloads, more virtual stages mean more cross-rank sends for each microbatch, including wraparound transfers. Actual volume depends on tensor shapes and placement rather than merely multiplying a physical-device count. Include communication-buffer lifetimes and possible contention with tensor-parallel collectives. A useful comparison holds the model, global batch, precision, and optimizer semantics fixed while reporting changes in chunks, message count, memory, and end-to-end time.

The modular lab visualizes only the cyclic rank arithmetic. Reset, set modulus to 4 and additive step to 1, predict the period, then Step four times to return to zero. Compare a fresh Reset with both modulus at 4 and step at 2 before two Steps; only two residues are visited. This arithmetic explains why a placement stride can omit ranks, but it has no virtual-chunk operations, data dependencies, backward work, messages, or device resource conflicts.

Reduce a bubble while adding tensor boundaries

Use four physical devices, eight microbatches, and original per-device f = 2 ms and b = 4 ms. Compare one chunk with two equal chunks per device under the original ideal model. Assume a simple chain and every virtual boundary crosses a rank.

  1. Useful per-device computation is 8 × 6 = 48 milliseconds. Without interleaving, the bubble is (4 − 1) × 6 = 18 milliseconds, giving 66 milliseconds total.

  2. With two equal chunks per device, the ideal bubble is 18/2 = 9 milliseconds, giving 57 milliseconds total. Eight microbatches satisfy the original multiple-of-four constraint.

  3. A four-stage chain has three forward boundaries per microbatch; an eight-virtual-stage looped chain has seven. With matching backward transfers, eight microbatches require 48 versus 112 boundary messages under these declared equal-chain assumptions.

The result

The modeled nine-millisecond bubble saving must be weighed against the additional messages and any exposed communication.

Explore the model

Interactive lab

Interactive lab · modular

Cyclic physical-rank mapping

Reset, set modulus m = 4 and additive step a = 1, predict the period, then Step four times. Compare a fresh Reset with both m = 4 and a = 2 before two Steps. This modular orbit shows rank-index coverage only; it is not an interleaved pipeline scheduler.

Cyclic physical-rank mappingAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. 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 forA logical placement can revisit physical ranks, while execution still needs distinct chunk identities and dependencies.

Check your understanding

What must accompany the original ideal claim that v chunks reduce bubble duration by a factor of v?

Try it yourself

For P = 2, M = 4, f = 3 ms, b = 5 ms, and v = 2 equal chunks, compute the original model’s total time with and without interleaving. Name a case in which the modeled improvement may disappear.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Useful work is unchanged; divide only the bubble term by v.

Compare with the solution

Useful per-device time is 4 × 8 = 32 milliseconds. The ordinary bubble is eight milliseconds, so total time is 40. Interleaving reduces that ideal bubble to four, giving 36 milliseconds. Additional exposed point-to-point transfers, inefficient small kernels, chunk imbalance, or device resource conflicts can erase the four-millisecond saving; a valid measured execution is needed to establish actual benefit.

Take it with you

  • Virtual stages share their owner device rather than create independent compute capacity.
  • The original interleaved bubble formula assumes equal chunk costs and a legal schedule.
  • Additional boundaries, buffer lifetimes, and version-specific constraints belong in the comparison.

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.