Skip to main content
Home › Categories › Artificial Intelligence & Computing › Distributed AI Training: DDP, FSDP/ZeRO, Tensor Parallelism, and Pipeline Parallelism

Distributed AI Training: DDP, FSDP/ZeRO, Tensor Parallelism, and Pipeline Parallelism

Author: ZUVDEX Team 4 min read
distributed ai training tensor vs pipeline parallelism ddp vs fsdp zero sharding tensor parallelism megatron nvlink pipeline parallelism 1f1b dualpipe context ring attention parallelism allreduce allgather reducescatter

A single 70-billion-parameter model in mixed-precision BF16 training requires roughly 140 GB for weights, 140 GB for gradients, and 560+ GB for FP32 master weights and AdamW moment buffers—exceeding 840 GB before a single activation tensor is allocated, more than ten times the memory of an 80 GB GPU. Distributed AI training overcomes single-chip memory and FLOP limits by combining multidimensional sharding strategies—Data/ZeRO Parallelism (FSDP), Tensor Parallelism (TP), Pipeline Parallelism (PP), Context Parallelism (CP), and Expert Parallelism (EP)—mapped carefully onto intra-node NVLink and inter-node RDMA topologies.

Key Highlights

  • Distributed Data Parallel (DDP) replicates the entire model on every GPU and averages gradients via All-Reduce—ideal only when the whole training state fits inside a single GPU.
  • DeepSpeed ZeRO (Stages 1/2/3) and PyTorch FSDP2 eliminate redundant copies by sharding optimizer states, gradients, and parameters across data-parallel ranks, fetching unsharded layers just-in-time via All-Gather and Reduce-Scatter.
  • Tensor Parallelism (Megatron-LM style) splits individual matrix multiplications column-wise and row-wise within a single node’s ultra-fast 900–1,800 GB/s NVLink domain (typically TP = 2, 4, or 8).
  • Pipeline Parallelism (1F1B / Interleaved / DualPipe) slices layer ranges across separate server nodes over slower InfiniBand/RoCE links while Context Parallelism (Ring Attention) shards ultra-long sequences.

Matching 4D Parallelism Dimensions to Hardware Bandwidth

Every collective communication primitive carries a distinct bandwidth sensitivity. Samyam Rajbhandari’s ZeRO insight noted that All-Reduce equals Reduce-Scatter followed by All-Gather—meaning sharding parameters across N GPUs (ZeRO-3 / FSDP) adds only 1.5× the communication volume of standard DDP and overlaps cleanly in the background while Tensor Cores compute the current layer.

Mohammad Shoeybi’s Megatron Tensor Parallelism shards attention heads and MLP columns inside a single layer, requiring blocking All-Reduce synchronization twice per Transformer layer on the critical latency path. Consequently, TP should almost never cross multi-node Ethernet/InfiniBand boundaries (keep TP <= 8 inside one NVLink chassis), whereas Pipeline Parallelism and ZeRO/FSDP scale cleanly across hundreds of racks.

Parallelism Mode What Is Sharded? Required Interconnect When to Enable
DDP (Data Parallel) Mini-batch rows only (full model replicated) Standard PCIe / 100G+ NIC Models <7B fitting comfortably inside 1 GPU
FSDP2 / DeepSpeed ZeRO-3 Optimizer states + Gradients + Weights Intra-node or 200G–400G RDMA Default first choice for 7B–70B multi-GPU fine-tuning & pretraining
Tensor Parallelism (TP) Intra-layer weight columns & rows + activations Intra-node NVLink / Infinity Fabric ONLY Models >30B where single-layer activations/weights strain 1 GPU
Pipeline Parallelism (PP) Contiguous blocks of layers across stages Inter-node InfiniBand / RoCE 100B–1T+ pretraining across dozens/hundreds of server nodes
Context Parallelism (Ring) Sequence length dimension L across GPUs NVLink / fast RDMA 128k–1M+ token long-context training where activations explode

Maximizing Model FLOPs Utilization (MFU) and Surviving Stragglers

In synchronous bulk-parallel training across 4,096 GPUs, the entire cluster marches at the speed of the single slowest thermally throttled GPU or degraded optical cable ("straggler"). High-reliability clusters run automated 60-second NCCL bandwidth and GEMM health checks prior to job launch, overlap async checkpointing to CPU RAM before flushing to object storage, and track Model FLOPs Utilization (achieved mathematical FLOPs divided by theoretical datasheet Tensor Core peak).

  • Keep Tensor Parallelism strictly <= GPUs-per-node (typically 4 or 8); running TP across inter-node network cables tanks MFU from 50% down below 15%.
  • Use Hybrid Sharded Data Parallel (HSDP)—ZeRO-3 within each 8-GPU node and ZeRO-1/DDP across nodes—when inter-node network bandwidth is modest.
  • Align hidden dimensions, vocabulary sizes, and micro-batch shapes to multiples of 64 or 128 for peak Tensor Core tile efficiency.

References & Sources

  • Rajbhandari, Samyam et al. (2020) — ZeRO: Memory Optimizations Toward Training Trillion Parameter Models, IEEE/ACM Supercomputing (SC20).
  • Shoeybi, Mohammad et al. (2019) — Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism, arXiv:1909.08053.
  • Zhao, Yanli et al. (2023) — PyTorch FSDP: Experiences on Scaling Fully Sharded Data Parallel, VLDB.