Unit 11 of 11 · about 4 hours · derive, measure
Choosing TP and CP degrees, and asynchronous tensor parallelism
Increasing a degree shrinks local work but adds communication and can worsen kernel efficiency. Choose a correct, memory-feasible plan before testing whether overlap reduces its critical path.
You'll be able to
- Derive feasible TP and CP degree candidates from head policy, memory, sequence length and link bandwidth.
- Measure synchronous and asynchronous CPU correctness paths without claiming GPU overlap from their timings.
- Distinguish an asynchronous launch from hidden communication using a dependency model and, when hardware permits, a GPU trace.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Degree choice depends on the workload and linksUltra-Scale Playbook - Tensor, Sequence and Context Parallelism
Closing TP throughput/memory trade-off; Sequence parallelism closing benchmark summary; Context Parallelism and Ring Attention overlap discussion
Use the trends and dependencies, not the plotted throughput as a target. The node boundary and eight-GPU threshold describe the authors' topology, not a universal TP limit.
- Chunked communication and matmul overlapHow to Scale Your Model - Chapters 3 and 5
Chapter 3, How to overlap matmul communication with compute: collective-matmul animation and chunked matmul/ring-reduction explanation
Read this subsection only. Transfer the dependency reasoning; TPU bandwidth and tiled-kernel behavior are not GPU measurements.
- Input-gradient reduction beside weight-gradient computePicotron - Tensor and Context Parallelism
LinearWithAsyncAllReduce.backward;linear_with_all_reduceandlinear_with_async_all_reduceTrace launch, independent weight/bias work and final wait. This is backward overlap at one column layer, not a tiled forward asynchronous-TP implementation.
- Asynchronous results still need completionPyTorch Tensor Parallel Tutorial
DTensor.redistribute:async_op;DTensor.to_local:AsyncCollectiveTensorreturn andwaitcontract
Focus on
- TP shards large weights and feature work but communicates at projection boundaries. CP partitions tokens and attention work without sharding parameters by itself. Longer sequences supply more attention compute per streamed KV byte, but causal imbalance and small local blocks can limit that advantage.
- Enumerate legal degrees, keep global valid tokens and model semantics fixed, and combine the earlier storage/traffic ledger with launch latency and effective bandwidth. Local GEMM efficiency and temporary-buffer peaks can invalidate an otherwise attractive byte-only plan.
- Picotron computes the input gradient, launches its all-reduce, computes independent weight/bias gradients, then waits before returning. Tiled forward asynchronous TP instead overlaps partial matmuls with communication chunks; it requires additional scheduling and buffer dependencies.
- For ideal independent compute and communication durations, an overlap window costs , not their sum. Startup, final drain and contention remain. CPU timings and a host's early return establish neither this ideal nor real GPU overlap.
Common mistakes · 3
- Timing only the asynchronous launch or reading a collective output before completion. Neither measures the completed operation.
- Increasing TP until local matmuls become too small, or choosing CP to solve parameter memory that remains replicated.
- Claiming overlap because compute and communication appear on different streams. Their actual intervals, dependencies and contention determine the exposed tail.
Try it yourself
Closed-book, before checking anything
async_all_reduce=False and async_all_reduce=True, keeping inputs and weights fixed. Compare all gradients and record warmed-up wall-clock backward samples with communication complete before stopping the timer; label them CPU execution, not GPU overlap evidence. In a deterministic timing model with independent 3 ms compute and 2 ms communication, compare a 5 ms serial window with a 3 ms ideal overlapped window. Sweep hypothetical bandwidth and sequence length for legal TP/CP candidates using the earlier ledger. With two or more GPUs, optionally repeat the matched NCCL variants with synchronized timing and a profiler trace; report exposed communication and any regression, not an assumed speedup.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Which work can Picotron place beside the input-gradient all-reduce?Answer
Weight- and bias-gradient computation. They use saved input and upstream gradient, not the reduced input gradient. The caller still needs completion before consuming that input gradient.
2.Does a longer sequence always make a larger CP degree faster?Answer
No. It can improve compute per KV byte, but local block size, imbalance, launch latency and link contention still constrain useful degrees.
3.Can an asynchronous variant pass every oracle and still be slower?Answer
Yes. Correct scheduling may add launches, waits, buffers or contention without hiding enough communication. Preserve correctness and report the measured regression.
You're done when
Your legal candidate table names memory and communication limits, both CPU variants match the gradient oracle, and your model or available GPU trace distinguishes launch, useful overlap and exposed communication.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 9 more in the section
- Ultra-Scale Playbook - Tensor, Sequence and Context ParallelismHugging Face · primary
Read Tensor Parallelism, Tensor parallelism in a transformer block, Sequence parallelism, Context Parallelism, Ring Attention and Zig-Zag Ring Attention in order. Redraw every tensor shape and collective for a concrete batch, sequence, hidden and head configuration; the context-parallel section gives no byte formula, so derive one yourself.
- Picotron - Tensor and Context ParallelismHugging Face · required
Read
tensor_parallel/tensor_parallel.py,tp_communications.py,context_parallel/context_parallel.pyandcp_communications.py.tests/test_tensor_parallel.pyhardcodes NCCL and CUDA; port it to Gloo on CPU and compare withtorch.testing.assert_close, because its exact equality check fails when sharded and full matmuls round differently. - PyTorch Tensor Parallel TutorialPyTorch · required
Use the tutorial to map
ColwiseParallel,RowwiseParallel,SequenceParallel,PrepareModuleInputand loss parallelism to the ownership model you derived, with the DTensor reference at https://docs.pytorch.org/docs/2.14/distributed.tensor.html forShard,Replicate,Partialandredistribute. Add assertions around every layout transition. - How to Scale Your Model - Chapters 3 and 5Google DeepMind · support
Solve the sharded-matrix multiplication layouts in Chapter 3 and the Megatron sharding section of Chapter 5. Translate the results into PyTorch DTensor placements and collective counts.
Also in this section
- Megatron-LM: Training Multi-Billion Parameter Language Models Using Model ParallelismShoeybi et al. (2019) · required
Read the model-parallel section: the and operators, MLP and self-attention partitioning, and the parallel embedding and cross-entropy. Derive each forward and backward collective before reading the code.
- Reducing Activation Recomputation in Large Transformer ModelsKorthikanti et al. (MLSys 2023) · support
Read the sequence-parallelism and selective-recomputation sections and the activation-memory equations. Check them against your own per-layer memory derivation.
- Ring Attention with Blockwise Transformers for Near-Infinite ContextLiu et al. (ICLR 2024) · support
Read the ring algorithm and its overlap condition, then compare it with all-gather context parallelism and DeepSpeed-Ulysses (arXiv 2309.14509) when choosing a context-parallel scheme.
- Picotron Tutorial - Step 4 and Part 2 VideoHugging Face · support
Follow
step4_tensor_parallelwith its diff and the Part 2 video. Write your own column and row layers first. - TorchFeather - TP and Ring Attention Minimal ExamplesTorchFeather · required
Run
minimal_examples/block_matrix_multiply.py, thentp_swiglu.pyandtp_attention.pywith 2 processes andring_attention.pywith 4, all on Gloo on CPU; each checks its output and gradients against ordinary tensors. Change one placement or mask and watch the check fail. - Distributed Training Guide - Chapter 6 Tensor ParallelismLambda Labs · support
Read colwise and rowwise linear layers, embeddings, norms, loss parallelism and throughput accounting in
06-tensor-parallelas a practitioner second view. Its script needs one GPU per rank. - PyTorch Context Parallel TutorialPyTorch · support
Read the
context_parallelAPI, buffer sequence dimensions, rotation methods and the rotary-frequency trap. It needs CUDA GPUs and NCCL; on CPU, keep to the TorchFeather ring-attention example. - TensorTonic - Reconstruct a Column-Parallel MLP LayerTensorTonic · support
Solve Reconstruct a Column-Parallel MLP Layer, including its uneven-shard cases.
- PyTorch 2.14 SDPA - explicit masks and dropoutPyTorch · reference
Use the equivalent attention implementation and
attn_mask/dropout_pcontract to build a CPU packed-document oracle before translating masks to context-parallel blocks. Do not assume the experimental CP wrapper supports every SDPA mask.