Unit 6 of 13 · about 5 hours · derive
Per-layer FLOPs and the collective volume of every dimension
Use Counting parameters and FLOPs and Operation counts for projections, MLPs, output and attention as inputs. The new task is to distribute those operations and count the communication that makes them valid.
You'll be able to
- Derive local matmul shapes and forward, backward and recomputation FLOPs for each stage.
- List every DP, FSDP, TP, SP, CP, PP and EP transfer with group, dtype, payload and frequency.
- Keep logical payload, per-rank transmitted bytes and critical-path time distinct.
Covers
Read
In this order, only the parts listed
0 of 3 done
- A gated FFN with explicit forward and backward communicationCS336 Assignment 2 (Spring 2026) - Section 8 Analyzing Parallelism Strategies
Sections 8.1 to 8.4, Communication Primitives through Analyzing Tensor Parallel, printed pp. 40 to 45
- Transformer terms beyond the FFNHow to Scale Your Model - Chapters 4 to 6
Global FLOPs and Params Calculation: MLPs, Attention, Other Operations and Fractional cost of attention with context length
- Sequence, context, pipeline and expert transfersThe Ultra-Scale Playbook - 5D Parallelism and Finding the Best Configuration
Summarizing it all, the combined MoE-layer diagram; follow back to Sequence parallelism, Ring Attention and Expert Parallelism for the transfer paths
Use the diagrams to enumerate transfers. Do not use Appendix A3's shard-size lines as transmitted bytes: an input shard is not the total traffic, and element counts need their dtype multiplier.
Focus on
- For a gated FFN with token rows , hidden width and MLP width , three projections cost forward FLOPs and about backward FLOPs. Distribute rows and weights according to actual layouts, not every mesh degree blindly.
- For a ring on ranks and full logical tensor size bytes, all-gather or reduce-scatter sends per rank; all-reduce sends twice that. At degree 1 all three have zero network traffic.
- DP reduces gradients once per synchronization; FSDP gathers each live parameter unit and scatters gradients; TP/SP moves activations at layout boundaries. PP sends boundary activations and their gradients. CP exchanges attention blocks; EP dispatches and combines routed tokens, including backward transfers.
- Include attention score/value matmuls, vocabulary projection, recomputation and replicated operations. CP and EP counts depend on algorithm, masks, routing and padding; count the actual messages rather than assuming uniform traffic.
Common mistakes · 3
- Treating FLOPs divided by peak FLOP/s as a measured kernel time. Local shard shapes can reduce attainable throughput.
- Adding send and receive bytes and then dividing by an egress-only bandwidth. Keep the byte and bandwidth convention consistent.
- Counting only EP forward dispatch. Combine and the backward routing paths also move tensors.
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 is the gated FFN forward count larger than a two-matrix MLP count?Answer
It has gate, up and down projections rather than just up and down. Each costs twice token rows times the two weight dimensions.
2.What happens to FSDP traffic if parameters are retained across the forward/backward boundary?Answer
A backward parameter gather may be avoided for retained units, but memory rises. Count gathers from the retention policy, not a fixed slogan.
3.Why is the 1 MiB ring input not the per-rank all-reduce traffic?Answer
Each rank sends three quarters of the tensor in reduce-scatter and again in all-gather. That totals 1.5 MiB.
Practice
- CS336 Assignment 2:
data_parallel_calcs,fsdp_calcsandtp_calcsSection 8.2 problem on p. 42, Section 8.3 problem on pp. 43 to 44 and Section 8.4 problem on pp. 44 to 45
These are written derivations, not public autograded tests. Retain the finite-rank ring factors and the handout's FP16 and egress-bandwidth assumptions. The section mini-project extends your transfer ledger to CP, PP and EP.
You're done when
Your three written solutions agree with an independent shape-and-message count, and the composed ledger names every active transfer and its units.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 10 more in the section
- The Ultra-Scale Playbook - 5D Parallelism and Finding the Best ConfigurationHugging Face · primary
Study 5D Parallelism in a Nutshell, then Finding the Best Training Configuration (fitting a step in memory, reaching the global batch, optimizing throughput) at https://nanotron-ultrascale-playbook.static.hf.space/index.html#finding_the_best_training_configuration. Rebuild a small planner that enumerates legal DP, TP, CP, PP and EP degrees and ranks them by predicted memory and step time; its heatmaps are its own H100 cluster's results.
- How to Scale Your Model - Chapters 4 to 6Google DeepMind · required
Use Part 4 (transformer math), Part 5 (training parallelism) and Part 6 (LLaMA 3 case study) to independently estimate parameters, FLOPs, memory, communication, time and cost for one configuration, then the GPU rooflines in Part 12. Keep TPU constants labeled and compare its recommendation with the Playbook.
- CS336 Assignment 2 (Spring 2026) - Section 8 Analyzing Parallelism StrategiesStanford University · required
Solve
data_parallel_calcs,fsdp_calcs,tp_calcsandfsdp_tp_calcs(Sections 8.2 to 8.5) with your planner, and reconcile any disagreement before trusting either.
Also in this section
- Picotron - 4D CompositionHugging Face · required
Trace create_config.py, process_group_manager.py and train.py across DP, TP, PP and CP. Run the CPU 3D example or a smaller equivalent, assert group membership and compare observed event order with the planner.
- First-Principles Video - Device Mesh Composition SegmentUmar Jamil · support
Watch 08:37:34 on device meshes and combining pipeline with data parallelism. Reconstruct its rank-coordinate table and compare it with Picotron process groups and your planner output.
- Distributed Training Guide - Chapter 7 FSDP plus TPLambda Labs · support
Read the 2D FSDP plus TP path in
07-2d-paralleland explain why FSDP is applied after TP and what limits the TP degree. Running it needs several GPUs. - Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LMNarayanan et al. (SC 2021) · required
Read the composition of tensor, pipeline and data parallelism, the interleaved schedule and the performance analysis of parallel configurations. Check its guidance against your planner on one model and cluster.
- Transformer Math 101 - Distributed TrainingEleutherAI · support
Use the sharded-optimizer, 3D-parallelism and activation equations as a cross-check of your planner's memory terms.
- TorchFeather - ParallelDims and Composition PlanTorchFeather · support
Inspect distributed/parallel_dims.py and model/parallelize.py. Build the exact mesh product and divisibility table for one FSDP, TP, CP, PP and EP configuration, then identify ordering assumptions in its composition.
- TensorTonic - Choose a Topology-Aware Parallel PlanTensorTonic · support
Solve Choose a Topology-Aware Parallel Plan, then compare its memory and communication model with yours.
- NanotronHugging Face · depth
Inspect configuration, parallel context and trainer paths used by the Ultra-Scale benchmarks only after the planner works. Its "3D" means DP, TP and PP: there is no context or expert parallelism.
- Bumblebee - Parallel State and CompositionBumblebee · depth
Only as a possible capstone target: read
primitive/parallel/and the composition tests in a clean checkout to compare TP, EP, ETP, CP and PP contracts. Its multi-GPU paths are untested upstream. - HetPipe - Heterogeneous Partitioning and PlacementPark et al. · support
Read arXiv:2005.14038v1 Section 4, Pipelined Model Parallelism Within a VW, for its Model Partitioning paragraph, Section 7, Partitioning Algorithm, and Section 8.1, Methodology, for resource allocation to virtual workers. Reuse device-specific compute, memory and placement constraints in a synchronous simulator; do not adopt its stale-weight update semantics or source speedups.