Unit 2 of 10 · about 4 hours · derive
Microbatches, the forward and backward dependency graph and divisibility
Microbatches turn a sequential layer stack into a parallel schedule, but only if batch accounting and cross-stage dependencies are exact. Every bubble number and equivalence check later divides by these counts.
You'll be able to
- Derive global batch and token counts from microbatch size, microbatch count and data-parallel degree.
- Draw the forward activation and backward gradient edges across stages and place the synchronous update.
- State divisibility constraints and a remainder policy that keeps the loss mean correct.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Microbatching and synchronous accumulationGPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelism
Sections 2 and 3 (arXiv:1811.06965v5): splitting each mini-batch of size into equal microbatches, forward and backward dependencies across stages, gradients applied synchronously after accumulating over all
- Microbatch constants and divisibility gatesTorchFeather - Pipeline Minimal Example and Runtime
LOCAL_BATCH_SIZE8 withMICRO_BATCH_SIZE2, theLOCAL_BATCH_SIZE % MICRO_BATCH_SIZEguard,inputs.split(MICRO_BATCH_SIZE), and each microbatch loss divided bynum_microbatchesbefore summing grad_acc_stepsas the microbatch countPicotron - Pipeline Parallelismpp_enginebranch calling the AFAB or 1F1B step withgrad_acc_stepsmicrobatches, andMicroBatchDataLoaderwithglobal_batch_sizeequal to microbatch size timesgrad_acc_stepstimesdp_world_size- Pipelining pseudocode and dependency walkHow to Scale Your Model - Pipeline Parallelism in Chapter 5
Pipelining section: layer-by-layer forward with device handoffs, loss derivative seeding the backward walk, per-stage input-gradient and weight-gradient computation
Focus on
- Global batch is a product: microbatch size times microbatch count times data-parallel degree, and token counts multiply by sequence length on top.
- Forward edges carry activations to the next stage; backward edges carry input gradients to the previous stage; weights never move between stages.
- The synchronous update sits after the last microbatch's gradients accumulate at mini-batch end, which is what makes the pipeline update match a large-batch update.
- Equal microbatches keep every mean exact; a short tail microbatch needs explicit reweighting or padding, never silent averaging.
Common mistakes · 3
- Reading the microbatch size as the global batch. Multiply by the microbatch count and the data-parallel degree first.
- Letting a short last microbatch keep weight 1 in the loss mean. Size-weight it or pad it, or the update drifts from the oracle.
- Starting backward before microbatch 0 reaches the last stage. The loss seed does not exist until then, so early backward calls have nothing to differentiate.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Microbatch size 2, microbatch count 4, data-parallel degree 4. What is the global batch?Answer
examples before any sequence-length factor.
2.Where does the synchronous update sit in GPipe, and why does that placement matter?Answer
After gradients accumulate over all microbatches at mini-batch end. That placement is what equates one pipelined step with one large-batch synchronous step.
3.What happens on setting
MICRO_BATCH_SIZE3 withLOCAL_BATCH_SIZE8 in the TorchFeather example?AnswerThe divisibility guard raises. Either pad or re-split into equal microbatches, or implement a remainder policy that reweights the loss mean.
4.In the JAX pipelining pseudocode, what is copied between devices on the forward pass and on the backward pass?Answer
Forward copies activations to the next device; backward copies the loss derivative with respect to the input to the previous device. Weights stay sharded per device.
Practice
- TorchFeather
pp_gpipe.py: microbatch-count variation with reference checkRun the stock 8-rank CPU launch with
MICRO_BATCH_SIZE2 and again with 4; both runs must print the GPipe PASS lineChange only the microbatch constant and recompute the expected per-microbatch loss scaling. CPU gloo timings are not interconnect evidence; the reference match is the gate.
You're done when
Both microbatch settings print PASS, and you can write the global-batch product and the cross-stage edge directions without notes.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 8 more in the section
- 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.
- TorchFeather - Pipeline Minimal Example and RuntimeTorchFeather · required
Run
minimal_examples/pp_gpipe.pywith 8 Gloo processes on CPU (two stages by four replicas); it checks outputs and averaged gradients against a reference. Read its taggedisendandirecvcalls, thendistributed/pipeline_parallel.py, and compare the event order with Picotron. - 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.
Also in this 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 Tutorial - Steps 7 and 8Hugging Face · support
Read
step7_pipeline_parallel_afabandstep8_pipeline_parallel_1f1bwith 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.
- PyTorch Pipeline Parallelism TutorialPyTorch · required
Complete the tutorial and compare
ScheduleGPipeandSchedule1F1B, 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. - 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.