advanced28 min studyLesson 563 in Engineering

One-forward-one-backward schedules

Trace warmup, alternating steady state, cooldown, and the activation lifetimes of a synchronous 1F1B pipeline.

On this page

What you’ll understand

  • Distinguish steady-state alternation from the full iteration schedule.
  • Count outstanding forwards using matching backward completion.
  • Explain activation savings without claiming automatic bubble elimination.

One-forward-one-backward describes a steady-state scheduling pattern, not an instruction to run backward immediately after every local forward. A stage must first receive the matching downstream gradient, so early stages need warmup and every stage eventually drains its outstanding work. This lesson uses the noninterleaved synchronous PipeDream-Flush schedule analyzed by Megatron-LM in 2021, with PyTorch 2.8 Schedule1F1B as an interface reference. Weight-updating asynchronous PipeDream is a separate algorithm.

Warm up enough work to make a backward ready

Consider a two-stage chain and label microbatches zero through three. Stage zero can run forward zero, then forward one while stage one runs forward zero. Stage zero cannot yet backward zero until stage one computes that microbatch’s backward. The local steady-state order then alternates another forward with an earlier ready backward. Stage one, having no downstream stage, can start its backward soon after its loss-producing forward. Different stage positions therefore have different warmup and cooldown lengths.

A valid schedule tracks activation ownership separately from whether a device is busy. The state produced by a local forward remains needed until its corresponding backward consumes or recomputes it. It cannot be recycled because another microbatch’s backward has finished. Include send buffers and recomputation inputs in the actual memory accounting; a nominal saved-activation count omits them. A trace with explicit microbatch identifiers makes these lifetime errors visible before a large implementation turns them into intermittent numeric corruption.

Ks(t)=∑m=0M−11 ⁣{ts,mF≤t<ts,mB}K_s(t)=\sum_{m=0}^{M-1}\mathbf1\!\left\{t^{F}_{s,m}\leq t<t^{B}_{s,m}\right\}
K_s counts outstanding local forwards after their completion times t^F and before matching backward-completion times t^B. Time uses one consistent unit. This simplified lifetime convention assumes the needed state remains owned through backward completion and excludes separate communication buffers.↔ Scroll wide equations horizontally.

Memory savings and bubble savings are different

In a standard noninterleaved 1F1B flush schedule, early stages maintain a bounded number of in-flight microbatches determined by their position and pipeline depth. By contrast, an all-forward schedule can retain M microbatches before backward begins. For sufficiently large M, this changes saved-activation memory substantially. The benefit comes from consuming old forward state earlier, not from removing parameters or optimizer state. Stage-specific peaks matter because the first and last stages need not retain the same number of activations.

Under the balanced compute-only assumptions used for the ordinary schedule comparison, the noninterleaved flush 1F1B schedule has the same modeled fill/drain bubble as GPipe. Its principal improvement in that comparison is lower activation residency. Real timing can still change through memory pressure, overlap, or kernel effects, but those require evidence. Keeping weights fixed until the flush also matters: the schedule’s memory behavior should not be confused with the asynchronous weight-stashing algorithm merely because both use the phrase one-forward-one-backward.

Ksmax⁡≤min⁡(M,P−s),Ms,saved=asKsmax⁡K_s^{\max}\leq\min(M,P-s),\qquad M_{s,\mathrm{saved}}=a_sK_s^{\max}
For the stated standard noninterleaved flush 1F1B ordering with zero-based stage s, one full saved-state bundle of a_s bytes per outstanding forward gives this count bound and byte estimate. It excludes interleaving, split backward variants, temporary workspace, and communication-buffer lifetimes.↔ Scroll wide equations horizontally.

Check the full timeline, including the tail

Warmup and cooldown are not optional corner cases. When M is smaller than the pipeline depth, the steady alternating portion can be short or absent. The schedule must still execute every required backward exactly once and delay the optimizer until the intended accumulation boundary. Test the last microbatch as carefully as the first; a missing cooldown can leave correct-looking outputs but incomplete gradients. Use a deterministic small model to compare all parameter gradients against the same synchronous unsplit update.

The queue lab supplies only an outstanding-work analogy. Reset, set arrival rate to 2 and service rate to 3, predict the backlog after one second, then Step twice: three units remain. Compare a fresh Reset with both arrival rate at 0 and service rate at 4 before two Steps: the initial four drain. This fluid instrument does not know a microbatch identifier, stage index, saved tensor, warmup, or backward readiness, so derive the actual activation bound from a hand trace.

Trace a two-stage, four-microbatch flush

Let each forward and backward take one millisecond, with zero communication cost. Use two stages and four microbatches in standard flush 1F1B order. Each saved-state bundle on stage zero is 40 MiB. Trace its lifetime peak and total time.

  1. Stage zero runs F0 at 0–1 ms and F1 at 1–2 ms. Stage one runs F0 at 1–2 and B0 at 2–3, so stage zero cannot start B0 until 3 ms. Two stage-zero forward bundles are outstanding.

  2. Stage zero then runs B0 at 3–4, F2 at 4–5, B1 at 5–6, F3 at 6–7, and B2 at 7–8. Its final B3 waits for stage one’s B3 at 8–9 and runs at 9–10.

  3. The stage-zero peak is two bundles, or 80 MiB, versus four bundles or 160 MiB for the all-forward schedule. Elapsed compute-only time is ten milliseconds in both schedules under these assumptions.

The result

Earlier backward consumption halves this stage’s saved-state peak without eliminating the modeled flush bubble.

Explore the model

Interactive lab

Interactive lab · queue

Outstanding work as a limited lifetime analogy

Reset, set λ = 2 and μ = 3, predict Q at one second, then Step twice: Q = 3. Compare a fresh Reset with both λ = 0 and μ = 4 before two Steps: Q = 0. This initial-four fluid model does not implement activation identities, stage warmup, or 1F1B scheduling.

Outstanding work as a limited lifetime analogyFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 s

Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. 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 forReleasing completed work changes residency, but an actual activation peak requires identity-aware schedule tracing.

Check your understanding

Why can synchronous noninterleaved 1F1B save activation memory without reducing the ordinary balanced bubble formula?

Try it yourself

For the same two-stage standard flush schedule with eight microbatches and 24-MiB stage-zero bundles, compare its stage-zero saved-state count bound with an all-forward schedule. What additional memory must an implementation still account for?

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

Give me a hint

The stated standard bound at stage zero is min(M,P). Count bundles before multiplying by bytes.

Compare with the solution

Stage zero retains at most min(8,2) = 2 bundles, or 48 MiB under the stated model. An all-forward schedule can retain eight bundles, or 192 MiB. Weights, optimizer state, temporary kernels, communication buffers, and any recomputation inputs still require storage; neither number is a complete process-memory prediction or a measured device allocation.

Take it with you

  • 1F1B alternation follows readiness and sits between warmup and cooldown.
  • Saved state belongs to a particular microbatch until its matching backward is complete.
  • Lower activation residency does not by itself remove a synchronous flush bubble.

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.