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

Point-to-point activation and gradient transferTag, shape and ordering protocols for send and receiveRank failure, stalled peer and timeout diagnosis
1

Read

In this order, only the parts listed

0 of 4 done

  1. Tagged microbatch transfers and per-rank schedulesTorchFeather - Pipeline Minimal Example and Runtime

    run_schedule: IRECV_FORWARD and ISEND_FORWARD with FORWARD_TAG_BASE plus microbatch, IRECV_BACKWARD and ISEND_BACKWARD with BACKWARD_TAG_BASE plus microbatch, wait-before-use ordering, and the printed per-rank schedule

  2. Raw pipeline communicate callsPicotron - Pipeline Parallelism

    pipeline_communicate with recv_forward, send_forward, recv_backward and send_backward over batch_isend_irecv, bidirectional_pipeline_communicate pairing one send with one receive, and the VERBOSE step prints

  3. The pipeline process groupPyTorch Pipeline Parallelism Tutorial

    init_distributed (page read 2026-10-14): pp_group from dist.new_group as the send and receive group, stage_index equal to rank, num_stages equal to world size, with the note that the group can be a subgroup in the N-D parallel case

  4. 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

2

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_shapes before 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.synchronize after a gloo transfer on a CPU-only run. It raises when no GPU is visible (a CPU-only machine or CUDA_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.
3

Try it yourself

Closed-book, before checking anything

Closed-book, write a two-process gloo script where rank 0 sends an activation tensor forward with tag 100 plus microbatch index and rank 1 returns its gradient with tag 200 plus microbatch index, asserting shape and dtype on receipt.
4

Quiz yourself

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

0 got · 0 missed

  1. 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. 2.Picotron posts single ops with batch_isend_irecv and waits immediately. What ordering property does the schedule rely on?Answer

    Every 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. 3.A run hangs after changing FORWARD_TAG_BASE on one rank only. What is the first check?Answer

    Tag 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. 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.

5

Practice

  • TorchFeather pp_gpipe.py stock run on CPU

    torchrun --standalone --nproc-per-node=8 ./minimal_examples/pp_gpipe.py on CPU with gloo; rank 0 prints the GPipe PASS line and every rank prints its schedule and trace path

    Run 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.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.

  • 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 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.

Also in this section