Unit 3 of 10 · about 5 hours · implement
Activation and gradient transfer, send and receive protocols and stalled peers
Activations move forward and gradients move back over point-to-point links with no collective to hide a mismatch. Tag, shape and order agreements are the contract, and a stalled peer is usually a broken one.
You'll be able to
- Send activations forward and gradients backward between two gloo processes with per-microbatch tags and shape assertions.
- Explain tag, shape and ordering agreements and how a mismatch stalls a peer.
- Read a per-rank event trace to name the unmatched send or receive.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Tagged microbatch transfers and per-rank schedulesTorchFeather - Pipeline Minimal Example and Runtime
run_schedule:IRECV_FORWARDandISEND_FORWARDwithFORWARD_TAG_BASEplus microbatch,IRECV_BACKWARDandISEND_BACKWARDwithBACKWARD_TAG_BASEplus microbatch, wait-before-use ordering, and the printed per-rank schedule - Raw pipeline communicate callsPicotron - Pipeline Parallelism
pipeline_communicatewithrecv_forward,send_forward,recv_backwardandsend_backwardoverbatch_isend_irecv,bidirectional_pipeline_communicatepairing one send with one receive, and theVERBOSEstep prints - The pipeline process groupPyTorch Pipeline Parallelism Tutorial
init_distributed(page read 2026-10-14):pp_groupfromdist.new_groupas the send and receive group,stage_indexequal to rank,num_stagesequal to world size, with the note that the group can be a subgroup in the N-D parallel case - Forward and backward handoffs between devicesFirst-Principles Video - Pipeline Parallelism Segment
06:06:14 to 06:11:12: layer groups per GPU, forward activation handoffs to the next device, and backward upstream-gradient handoffs to the previous device
Focus on
- Each transfer is identified by direction plus microbatch: TorchFeather adds the microbatch index to a per-direction tag base so in-flight microbatches cannot match the wrong receive.
- Picotron leans the other way: single ops on the default tag pair up in strict program order, so any rank-specific branch in the op sequence deadlocks the pair.
- Shapes and dtypes are agreed out of band: the receiver allocates the buffer from
tensor_shapesbefore the transfer. On gloo a size mismatch aborts the receiving process; on other backends it can hang or corrupt, so assert shapes before the transfer instead of waiting for an error. - First and last stages skip one direction each: the first stage never receives forward, the last stage never receives backward, and the skip must be in the protocol, not just the compute.
Common mistakes · 3
- Reusing one tag for every microbatch and trusting call order. Tag per microbatch as TorchFeather does, or prove every rank runs an identical op sequence as Picotron requires.
- Calling
torch.cuda.synchronizeafter a gloo transfer on a CPU-only run. It raises when no GPU is visible (a CPU-only machine orCUDA_VISIBLE_DEVICES=), so gate device sync on the backend instead of copying GPU code. - Posting a blocking send before the peer posts its receive on both ranks at once. Pair each send with a receive through one bidirectional call, or keep the recv-first order on both sides.
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.Why do TorchFeather tags add the microbatch index to the base instead of using one tag per direction?Answer
Several microbatches are in flight at once, so one tag per direction could match a receive with the wrong microbatch's send. Each direction-plus-microbatch pair gets its own tag.
2.Picotron posts single ops with
batch_isend_irecvand waits immediately. What ordering property does the schedule rely on?AnswerEvery rank calls the same op sequence, so sends and receives pair in program order on the default tag. Any rank-specific branch breaks the pairing and stalls the peer.
3.A run hangs after changing
FORWARD_TAG_BASEon one rank only. What is the first check?AnswerTag agreement across peers, then shape and dtype agreement, then a per-rank event log in the TorchFeather schedule-print style to find the unmatched op.
4.Where does the pipeline group come from when pipeline composes with data parallelism?Answer
A subgroup over the pipeline ranks, built with
dist.new_group. Gradient averaging uses the separate replicate group, never the pipeline group.
Practice
- TorchFeather
pp_gpipe.pystock run on CPUtorchrun --standalone --nproc-per-node=8 ./minimal_examples/pp_gpipe.pyon CPU with gloo; rank 0 prints the GPipe PASS line and every rank prints its schedule and trace pathRun from the pinned commit with 8 processes. The script pins the gloo backend on CPU, so one GPU or none both work; then break one tag on purpose and read which rank stalls.
You're done when
Rank 0 prints PASS, every rank prints its schedule and trace path, your two-process tag script round-trips, and you can name the stalled side of a broken-tag run from its event log.
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. - 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.
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. - 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.