Unit 3 of 13 · about 4 hours · derive
Batch and token equations and divisibility across dimensions
The model-parallel ranks cooperate on the same data. Counting them as data replicas changes the update contract before any performance comparison begins.
You'll be able to
- Derive unique examples and valid loss tokens per update for a composed mesh.
- Build a divisibility table for heads, widths, vocabulary, sequence, layers and experts.
- Separate mathematical constraints from a chosen implementation's equal-shard restrictions.
Covers
Read
In this order, only the parts listed
0 of 5 done
- Hit the batch without inventing data replicasThe Ultra-Scale Playbook - 5D Parallelism and Finding the Best Configuration
Step 2: Achieving the target global batch size; cross-check with Revisiting global batch size
Treat the CP bullets as allocation advice, not batch equations. Changing CP alone partitions existing sequences and does not multiply unique examples.
- Implementation-specific divisibilityTorchFeather - ParallelDims and Composition Plan
parallelize_deepseekv3sequence and head checks;apply_non_moe_tpembedding, attention, output and MLP layouts - Mesh and balanced-context restrictionsTorchFeather - ParallelDims and Composition Plan
_validateexpert-mesh constraints andseq_len_divisor - Uneven layer partitionsTorchFeather - ParallelDims and Composition Plan
generate_llm_fqn_per_model_part: effective layer weights, remainder distribution and stage bounds - Equal expert-owner chunksTorchFeather - ParallelDims and Composition Plan
ExpertParallel._token_dispatch:num_local_expertsand the reshape ofnum_tokens_per_expertinto expert-owner chunksTrace the equal-expert-count layout only. Do not run the full expert stack here.
Focus on
- With independent data degree , microbatch examples , microbatches per update and full sequence length , unique examples are and dense input tokens are . Count unmasked loss tokens separately.
- For equal head shards, query heads must divide by TP; GQA needs a stated KV-head sharding or replication policy. Check hidden and MLP widths, and vocabulary padding, against the actual tensor layouts.
- Balanced CP may require two chunks per rank; combined SP can strengthen the sequence divisor. Equal layers per stage and equal experts per EP rank are planner policies, not universal requirements. Uneven partitions need explicit metadata and costs.
Common mistakes · 3
- Multiplying global batch by PP, TP or CP. None introduces independent examples in this convention.
- Rejecting every uneven layer count as mathematically impossible. A pipeline can have uneven stages, but the planner must cost their imbalance.
- Dividing a mean loss by world size. Weight gradients by the global valid-token denominator, accounting for replicated outputs.
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.Does doubling CP at fixed data degree and full sequence length double update tokens?Answer
No. It reduces local sequence ownership while keeping the same full sequences.
2.Why might TP exceed the number of KV heads legally?Answer
An implementation may replicate KV heads across TP ranks. That changes ownership and memory costs; it is not equal KV-head sharding.
3.What changes when some tokens are masked out of the loss?Answer
The valid-token denominator and useful-token count. Input processing cost can remain unchanged, so report both counts.
You're done when
Your ledger recovers the stated unique-token count and your table explains every rejection as a mesh, data or implementation-layout constraint.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 11 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.
- 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.
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. - 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.
- 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.
- 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. - 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.
- 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.