🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Distributed Training Architecture

AI System DesignDistributed ML TrainingđŸŸĸ Free Lesson

Distributed Training Architecture

Module 19 - Scaling Model Training Across Multiple GPUs and Nodes

Why This Matters

Training modern LLMs and vision models requires thousands of GPUs working in concert. Distributed training is not just about speed - it's about enabling models that cannot fit on a single device. Understanding parallelism strategies, communication patterns, and fault tolerance is essential for building and operating large-scale ML infrastructure.


System Architecture Overview

Distributed Training ArchitectureTraining CoordinatorOrchestrate, sync, checkpointData Parallelism+- Each GPU has full model copy+- Different data shard per GPU+- Gradient AllReduce after step+- DDP: PyTorch DistributedDataParallel+- FSDP: Fully Sharded Data Parallel| Shards parameters + gradients+- ZeRO: Zero Redundancy Optimizer Stage 1/2/3: optim/grad/paramBest for: models that fit on 1 GPUModel Parallelism+- Tensor Parallelism| Split layers across GPUs| Megatron-LM style+- Sequence Parallelism| Split sequence dimension+- Expert Parallelism| MoE: different experts on GPUs+- Context Parallelism Split long sequencesBest for: models too large for 1 GPUPipeline Parallelism+- Split model into stages| Each GPU owns a stage+- GPipe: micro-batch pipelining+- 1F1B: one forward, one backward+- Interleaved: virtual stages+- Bubble reduction strategies Schedule: F, F, F, B, B, B Pipeline bubbles: idle timeBest for: multi-node trainingMixed Precision Training- FP16/BF16 for forward pass- FP32 master weights- Loss scaling to prevent underflow- 2x memory reduction, 1.5-3x speedupCommunication- NCCL: GPU-to-GPU collective ops- InfiniBand: 200-400 Gbps interconnect- AllReduce, AllGather, ReduceScatter- Communication-computation overlapFault Tolerance- Periodic checkpointing- Async checkpoint writes- Elastic training (auto-scale)- Preemption-aware schedulingTraining FrameworksPyTorch DDP/FSDP - DeepSpeed (ZeRO) - Megatron-LM - ColossalAI - Ray Train - JAX/XLAInfrastructure: Kubernetes + GPU operator - Slurm - Lightning AI - Anyscale

Data Parallelism with FSDP

Fully Sharded Data Parallel (FSDP) shards model parameters, gradients, and optimizer states across GPUs. It uses an auto-wrap policy to determine which layers to shard (typically transformer layers), mixed precision with BF16 for forward/backward passes, and AllGather operations to reconstruct parameters only when needed. ZeRO Stage 1 shards optimizer states (4x reduction), Stage 2 adds gradient sharding (8x), and Stage 3 shards parameters (linear scaling with GPU count).


Pipeline Parallelism

Pipeline parallelism splits the model into sequential stages, each assigned to a different GPU. The 1F1B (one forward, one backward) schedule alternates forward and backward passes to minimize pipeline bubbles. During the warmup phase, forward passes fill the pipeline. In steady state, each stage alternates between forward and backward. The bubble ratio is (stages - 1) / micro_batches, which decreases with more micro-batches.


Gradient Accumulation

Gradient accumulation simulates larger batch sizes by summing gradients over multiple micro-batches before performing a weight update. Loss is scaled by 1/accumulation_steps before backward, gradients are clipped (max norm 1.0), and the optimizer steps only after all accumulation steps complete. The effective batch size equals per_device_batch x world_size x accumulation_steps.


Mixed Precision Training

Mixed precision uses BF16 or FP16 for forward/backward passes while maintaining FP32 master weights. BF16 has the same exponent range as FP32 and doesn't require loss scaling. FP16 requires GradScaler to prevent gradient underflow. Both achieve ~2x memory reduction and 1.5-3x speedup on modern GPUs with Tensor Core support.


Fault Tolerance

Checkpointing saves model state, optimizer state, epoch/step, and metrics to disk, with cleanup of old checkpoints (keeping last N). Elastic training handles worker failures by reloading from the latest checkpoint, redistributing data across remaining workers, and resuming training. For large-scale training, use async checkpoint writes to avoid blocking training.


Interview Q&A

Q1: When would you use tensor parallelism vs. pipeline parallelism?

Answer: Tensor parallelism splits individual layers across GPUs - best for single-node training with fast interconnects (NVLink). Pipeline parallelism splits layers into stages across GPUs - best for multi-node training where inter-node bandwidth is limited. In practice, use tensor parallelism within nodes and pipeline parallelism across nodes (3D parallelism).

Q2: What is the communication overhead of FSDP vs. DDP?

Answer: DDP broadcasts full parameters and AllReduces gradients - communication doubles with model size. FSDP shards parameters and only AllGathers when needed - communication scales with world size but reduces memory. For very large models, FSDP is necessary despite higher communication volume, since DDP can't fit the model.

Q3: How does gradient accumulation affect training?

Answer: Gradient accumulation simulates larger batch sizes by summing gradients over multiple micro-batches before updating weights. It's mathematically equivalent to using the larger batch (assuming no batch norm), but with lower memory usage. Common for fitting large effective batch sizes on limited GPU memory.

Q4: What are the trade-offs of BF16 vs. FP16 for mixed precision?

Answer: BF16 has the same range as FP32 (8 exponent bits), so it doesn't need loss scaling. FP16 has limited range (5 exponent bits) and requires loss scaling to prevent gradient underflow. BF16 is preferred on Ampere+ GPUs; FP16 works on older hardware with better Tensor Core support.

Q5: Design a fault-tolerant training system for 1000 GPUs.

Answer: Use: 1) Periodic async checkpointing to distributed storage, 2) Elastic training with auto-scaling (TorchElastic), 3) Preemption-aware scheduling (spot instances), 4) Graceful degradation (train on remaining GPUs), 5) Health monitoring per GPU, 6) Automatic bad-worker detection and exclusion, 7) Checkpoint resume with proper RNG state restoration.


Quiz

  1. What does FSDP stand for?

    • A) Fast Shared Data Parallel
    • B) Fully Sharded Data Parallel
    • C) Fault-tolerant Synchronized Data Processing
    • D) Forward-Scattered Data Pipeline
  2. Which ZeRO stage shards parameters?

    • A) Stage 1
    • B) Stage 2
    • C) Stage 3
    • D) None
  3. What is a pipeline bubble?

    • A) Network congestion
    • B) GPU idle time in pipeline parallelism
    • C) Memory overflow
    • D) Gradient explosion
  4. Why is BF16 preferred over FP16?

    • A) Faster computation
    • B) Larger dynamic range, no loss scaling needed
    • C) Smaller memory footprint
    • D) Better accuracy
  5. What does AllReduce do?

    • A) Reduces model size
    • B) Aggregates gradients across all GPUs
    • C) Splits data across nodes
    • D) Optimizes learning rate

Answers: 1-B, 2-C, 3-B, 4-B, 5-B

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert AI System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement