IIntroduction to AI Systems Performance EngineeringTechnical textbook
Chapter 14

Distributed Model Parallelism

Partition model state and computation across devices

Derive the state ownership, local tensor shapes, communication, memory, and scheduling effects of each parallel dimension before composing a physical rank mesh.

Suppose a transformer training process needs 96 GiB for model weights, gradients, and optimizer state, but one graphics processing unit (GPU) has only 80 GiB of high-bandwidth memory (HBM). Adding a second GPU does not make the model fit automatically. Software must decide which bytes each GPU stores, which matrix operations each GPU performs, and when the GPUs exchange partial results.

Distributed training frameworks normally run one central processing unit (CPU) process per GPU. The process receives an integer identifier called a rank. Rank 0 is a process identity, not a claim that its GPU is faster or physically central. A process group names the ranks that participate in a particular sequence of communication operations. PyTorch logs, profiler events, and NCCL messages use these rank and group identifiers to relate local activity to the complete job.

A memory report collected after model construction shows persistent allocations such as parameters and optimizer tensors. A profiler trace collected for one step shows temporary parameter gathers, gradient reductions, activation transfers, and idle intervals. Local tensor shapes printed at selected module boundaries show how each general matrix multiplication (GEMM) changed on every rank. GPU communication kernels can also occupy streaming multiprocessors (SMs) while model kernels wait. Together, the observations reveal whether a parallel method solved the original capacity problem and what new work the method introduced.

This chapter derives data, fully sharded, tensor, pipeline, expert, and combined parallelism from those concrete objects. Every section names the owner of each tensor, the exact local shape, the required communication, and the point in forward or backward execution where another rank's data becomes necessary.

Prerequisites

Learning objectives

  • State tensor ownership and local shapes for every parallel axis
  • Calculate persistent memory, peak transient memory, collective bytes, and readiness
  • Map a multidimensional rank mesh to measured physical topology
Lessons

Study this chapter

  1. 14.1
    Data parallelism and gradient synchronization

    Derive the synchronized global-batch gradient and explain replicated memory, bucket readiness, and slowest-rank behavior in distributed data parallel training

    Begin lesson →
  2. 14.2
    ZeRO and fully sharded data parallelism

    Draw one module's parameter and gradient lifetimes through fully sharded forward and backward execution and identify the measured memory peak

    Begin lesson →
  3. 14.3
    Tensor and sequence parallelism

    Derive local forward and backward matrix shapes, ownership, and collectives for column- and row-parallel linear layers

    Begin lesson →
  4. 14.4
    Pipeline and expert parallelism

    Read a pipeline-stage timeline and an expert token-count distribution to locate structural idle time, stage imbalance, and routing skew

    Begin lesson →
  5. 14.5
    Parallel mesh design

    Construct rank coordinates, process groups, memory timelines, collective tables, and physical placement for one feasible combined mesh

    Begin lesson →
Chapter projects

Extended exercises

Complete these projects after the lesson-level practice tasks. Each project combines several mechanisms from the chapter.

01
Check

Linear-layer sharding

For X[8,192, 4,096] and W[4,096, 16,384], derive four-rank column and row partitions through forward and backward computation.

Evidence: Global and local tensor shapes, ownership after each operation, and exact collective type and payload at every transition.

02
Practice

Training resource comparison

Compare data parallelism, full sharding, and tensor parallelism for the recurring 1-billion-parameter model on one eight-GPU server with declared sequence length, microbatch, precision, and links.

Evidence: Per-rank persistent and peak memory, local matrix shapes, communication bytes and readiness, plus one measured slice for the largest assumption.

03
Challenge

Mesh proposal

Design a multidimensional rank mesh for a declared model that cannot fit on one server and compare it with one serious alternative.

Evidence: Rank coordinates, process-group lists, topology mapping, memory timeline, collective schedule, predicted step time, restore plan, and measured reason for rejecting the alternative.

References

Sources and further reading

The lesson explanations synthesize primary papers and official references. Follow the originals for proofs, exact APIs, architecture details, and version-sensitive behavior.

  1. Efficient Large-Scale Training with Megatron-LM
  2. ZeRO: Memory Optimizations
  3. PyTorch FSDP2
  4. GPipe