Unit 4 of 10 · about 5 hours · derive

GPipe fill-drain and 1F1B schedules with their phases

GPipe and 1F1B are the two schedules every later variant modifies. Their phases decide which tensors are alive when, which is what the bubble and memory derivations price.

You'll be able to

  • Write the AFAB two-loop schedule and the 1F1B warmup, steady-state and cooldown phases for any rank.
  • Derive each stage's warmup count and the FIFO drain order of stored tensors.
  • Explain why 1F1B bounds in-flight activations while keeping the same bubble.

Covers

Fill-drain GPipe scheduleOne-forward-one-backward scheduleWarmup, steady state and cooldown phases
1

Read

In this order, only the parts listed

0 of 5 done

  1. AFAB schedule and codeUltra-Scale Playbook - Pipeline Parallelism

    Splitting layers on various nodes - All forward, all backward with FIG.XLVIII and CODE.VII: the all-forward then all-backward loops, loss on the last stage, and the note that plot numbers are microbatches from here on

  2. 1F1B schedule and codeUltra-Scale Playbook - Pipeline Parallelism

    One forward, one backward and Llama 3.1 schemes with FIG.XLIX and CODE.VIII parts 1 and 2: warmup forwards, steady state alternating one forward and one backward, cooldown backward drain

  3. AFAB and 1F1B step functionsPicotron - Pipeline Parallelism

    train_step_pipeline_afab all-forward then all-backward loops with FIFO tensor pops, and train_step_pipeline_1f1b with warmup count min(pp_world_size - pp_rank - 1, grad_acc_steps), bidirectional steady-state exchanges and cooldown drain

  4. AFAB then 1F1B as cumulative diffsPicotron Tutorial - Steps 7 and 8

    step7_pipeline_parallel_afab with pipeline_parallel.py and patch_step_7.diff for the AFAB step, then step8_pipeline_parallel_1f1b with its diff for the 1F1B step; read the step-8 diff as the exact AFAB-to-1F1B change

  5. GPipe grid, 1F1B steady state and activation freeingFirst-Principles Video - Pipeline Parallelism Segment

    06:26:15 to 06:38:33: GPipe grid inefficiency, 1F1B warmup into alternating steady state, backward costing about twice a forward for matmul-heavy layers, and why 1F1B frees each microbatch's activations earlier

2

Focus on

  • AFAB keeps both waves sequential: all forwards complete before any backward starts, so every stage holds all microbatches at the wave boundary.
  • 1F1B starts each microbatch's backward as soon as its loss exists, which alternates one forward with one backward in steady state and frees activations stage by stage.
  • Warmup on rank of stages is : the last stage warms up zero forwards and the first stage warms up the most.
  • Stored tensors drain first-in first-out: the oldest forward pairs with the incoming gradient, and the cooldown loop exists only to finish the warmup leftovers.
Common mistakes · 3
  • Expecting 1F1B to shrink the bubble at fixed microbatch count. The bubble is the same size as AFAB; the win is bounded activation memory that permits more microbatches.
  • Starting steady state before microbatch 0 reaches the last stage. No loss exists yet, so early backward calls have no seed gradient.
  • Forgetting the cooldown. Warmup forwards leave stored tensors behind, and their backward passes still have to run after the last steady-state step.
3

Try it yourself

Closed-book, before checking anything

Closed-book, draw the 1F1B event grid for 3 stages and 4 microbatches: mark warmup, steady state and cooldown on each stage and count each stage's forwards and backwards.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.A run has 4 stages and 8 microbatches. How many warmup forwards does each rank do?Answer

    : ranks 0 to 3 do 3, 2, 1 and 0 warmup forwards.

  2. 2.Why does the video draw backward blocks about twice as wide as forward blocks?Answer

    A matmul backward needs two matmuls, one for the input gradient and one for the weight gradient, so it costs about twice one forward matmul.

  3. 3.What work remains after the last 1F1B steady-state iteration on a rank with nonzero warmup?Answer

    One backward per warmup forward, drained oldest-first from the stored tensors: the cooldown phase.

  4. 4.In the step-8 tutorial diff, what is the structural change from AFAB to 1F1B?Answer

    The single all-backward loop becomes warmup forwards, an alternating forward-backward steady state with paired exchanges, and a cooldown drain of the leftover stored tensors.

5

Practice

  • PyTorch pipelining tutorial: GPipe versus 1F1B

    Swap ScheduleGPipe for Schedule1F1B in the Step 2 script and run both under torchrun --nnodes 1 --nproc_per_node 2; compare the rank-1 losses lists

    Keep the 8-layer split and 4 microbatches fixed. The gate is matching losses across schedules, not timing.

You're done when

Both schedules print equal rank-1 losses, and you can write any rank's warmup, steady-state and cooldown counts without notes.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 8 more in the section
  • Ultra-Scale Playbook - Pipeline ParallelismHugging Face · primary

    Read Pipeline Parallelism through All forward, all backward, One forward, one backward, Interleaving stages and Zero bubble and DualPipe. Derive bubble fraction and peak activation count for your simulator before running any schedule.

  • Picotron - Pipeline ParallelismHugging Face · required

    Read pipeline_parallel/pipeline_parallel.py and pp_communications.py beside the pipeline branch in train.py. Build a schedule event simulator first, then reproduce GPipe and 1F1B with shape, tag and ordering assertions.

  • Picotron Tutorial - Steps 7 and 8Hugging Face · support

    Read step7_pipeline_parallel_afab and step8_pipeline_parallel_1f1b with their diffs; the video series stops before pipeline parallelism.

  • First-Principles Video - Pipeline Parallelism SegmentUmar Jamil · support

    Watch 06:06:17 for pipeline parallelism and 06:26:52 for GPipe, 1F1B and zero-bubble schedules. Stop after GPipe and 1F1B to draw and test those event traces; zero-bubble implementation remains depth work.

Also in this section

  • TorchFeather - Pipeline Minimal Example and RuntimeTorchFeather · required

    Run minimal_examples/pp_gpipe.py with 8 Gloo processes on CPU (two stages by four replicas); it checks outputs and averaged gradients against a reference. Read its tagged isend and irecv calls, then distributed/pipeline_parallel.py, and compare the event order with Picotron.

  • PyTorch Pipeline Parallelism TutorialPyTorch · required

    Complete the tutorial and compare ScheduleGPipe and Schedule1F1B, then read https://docs.pytorch.org/docs/2.14/distributed.pipelining.html for the interleaved, looped, zero-bubble and DualPipeV schedules the tutorial omits. Preserve the model split, microbatch and loss contracts before adapting it.

  • How to Scale Your Model - Pipeline Parallelism in Chapter 5Google DeepMind · support

    Work the pipeline bubble and communication examples in Chapter 5. Use them to test your cost model under different stage counts, microbatch counts and imbalanced layers.

  • GPipe: Efficient Training of Giant Neural Networks using Pipeline ParallelismHuang et al. (NeurIPS 2019) · support

    Read the partitioning, microbatching and re-materialization design and the bubble overhead statement. Use it as the fill-drain specification your simulator reproduces.

  • Memory-Efficient Pipeline-Parallel DNN TrainingNarayanan et al. (ICML 2021) · support

    Read the PipeDream-Flush (1F1B) schedule and its activation-memory bound. Compare its stashed-activation count with GPipe in your simulator.

  • Zero Bubble Pipeline ParallelismQi et al. (ICLR 2024) · support

    Read the split of backward into input and weight gradients and the handcrafted schedules. Optional vocabulary for zero-bubble and DualPipe schedules.

  • TensorTonic - Pipeline Bubble UtilizationTensorTonic · support

    Solve the pipeline bubble utilization problem, then extend its model to 1F1B and interleaved stages in your simulator.

  • Distributed Training Subsystem - Pipeline SchedulerRoadmap-Final · support

    Complete the scheduler, event trace, activation-lifetime accounting and failure injection required in Milestone B. Keep the simulator runnable without GPUs.