Unit 12 of 13 · about 4 hours · implement

Correctness tests for a composed 2D or 4D plan

Correct dimensions in isolation do not guarantee a correct composition. The same global batch and optimizer state must produce the intended update after group construction, accumulation and transfers interact.

You'll be able to

  • Execute a CPU-safe composed plan and compare outputs, global loss, gradients and updates with an unpartitioned oracle.
  • Test sample identity, global normalization and complete state ownership across groups.
  • Localize a composition defect with group, tensor-layout and collective-order evidence.

Covers

Correctness tests for a composed 2D or 4D plan
1

Read

In this order, only the parts listed

0 of 2 done

  1. A composed PP-plus-DP numerical checkTorchFeather - ParallelDims and Composition Plan

    run_schedule, average_gradients, run_reference, assert_parameter_gradients_match and the assertions in main

  2. Compare a second composition's ownershipDistributed Training Guide - Chapter 7 FSDP plus TP

    Applying FSDP after TP and Controlling TP size

    Read the ownership path without launching the GPU trainer. Extend CPU checks with the reduced sharding and TP mechanisms you already built; the README has no independent update oracle.

2

Focus on

  • The supplied example checks two-stage PP with four DP replicas on CPU gloo. It compares final-stage outputs and loss, and all stage-local parameter gradients; it does not step an optimizer or test checkpoint resume.
  • Its reference averages gradients through the same DP groups. Add a stronger oracle that concatenates all replicas' distinct input and target tensors and computes one global mean loss in a single process.
  • Keep model and data seeds, token identities, loss denominator and optimizer hyperparameters identical. Compare floating-point tensors with justified absolute and relative tolerances, not bitwise equality.
  • Test nontrivial data on every replica, accumulation changes, tied-state ownership and invalid layouts. Log collective group, sequence, shape and dtype; reject known bad meshes before entering collectives.
Common mistakes · 3
  • Reusing the distributed reduction in the only oracle. A wrong group or divisor can then appear correct in both paths.
  • Claiming the supplied PASS message proves optimizer or recovery equivalence. Those are not tested by this example.
  • Running every replica on identical data. That can hide missing synchronization and incorrect sample ownership.
3

Try it yourself

Closed-book, before checking anything

Run the CPU example with its supplied model/data seeds and shapes. Then add one SGD update at learning rate 0.01 to a reduced PP-plus-DP trainer and to an independent concatenated-batch oracle. Compare stage parameters and global loss before and after the update, under a stated tolerance. Perturb one replica's reduction denominator and require the oracle test to fail; keep the first mismatching tensor and its owner.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.What is the reference loss for the example's equal-sized DP replicas?Answer

    The supplied reference is per replica: the mean squared error on that replica's own 8-sample batch. Its global equivalent is the mean squared error over the concatenation of all replicas' outputs and targets; with equal local sizes averaging the local means gives the same value, while unequal sizes need count weighting. Your added oracle should compute the concatenated form directly.

  2. 2.Why compare gradients as well as final parameters?Answer

    A small learning rate or rounding can hide a gradient-scale defect in parameters. Gradients expose the error before the optimizer transforms it.

  3. 3.Does one-step equivalence establish long-run convergence equivalence?Answer

    No. It checks a bounded update contract. Stochastic streams, repeated numerical error and altered optimization policies need trajectory or convergence evidence.

5

Practice

  • TorchFeather CPU example: GPipe with replicated DP

    Run torchrun --nnodes=1 --nproc-per-node=8 --master-port=29884 minimal_examples/pp_gpipe.py from the repository root

    The standalone example uses only PyTorch and CPU gloo; it passed on PyTorch 2.14.1. Its checks cover outputs, loss and averaged gradients for the stated fixture, not optimizer state. The section mini-project adds a concatenated-batch oracle, update checks and negative cases in trainlab.

You're done when

The supplied example passes, your independent oracle matches one composed SGD update, and a wrong reduction denominator produces a localized failing test.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 11 more in the section
  • Distributed Training Guide - Chapter 7 FSDP plus TPLambda Labs · support

    Read the 2D FSDP plus TP path in 07-2d-parallel and explain why FSDP is applied after TP and what limits the TP degree. Running it needs several GPUs.

  • 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

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

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

  • 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_calcs and fsdp_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.