🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Distributed Training: Data Parallelism, Model Parallelism, FSDP — Asked at NVIDIA & Google

Deep Learning Premium InterviewsDistributed Training⭐ Premium
NVIDIA & Google

Distributed Training: Data Parallelism, Model Parallelism & FSDP

Premium Interview Preparation — Distributed Training Mastery

🎯 The Interview Question

"Explain the difference between data parallelism and model parallelism. How does PyTorch's DDP (Distributed Data Parallel) work? What is FSDP (Fully Sharded Data Parallelism) and how does it reduce memory usage? What are the communication patterns in distributed training, and how do you optimize for them?"

This question is critical for training large models at NVIDIA (hardware) and Google (TPU infrastructure).


📚 Detailed Answer

Why Distributed Training?

Large models don't fit on single GPUs:

ModelParametersMemory (FP32)Memory (FP16)
BERT-Large340M1.3 GB0.7 GB
GPT-3175B700 GB350 GB
LLaMA-70B70B280 GB140 GB

Even with A100 80GB, we need multiple GPUs.

Data Parallelism

Basic idea: Replicate model on each GPU, split data:

Architecture Diagram
GPU 0: Model replica + Batch 0 → Gradients 0
GPU 1: Model replica + Batch 1 → Gradients 1
GPU 2: Model replica + Batch 2 → Gradients 2
GPU 3: Model replica + Batch 3 → Gradients 3
                        ↓
              AllReduce gradients
                        ↓
              Update all replicas

AllReduce Operation

Computes sum/average of gradients across all GPUs:

Ring AllReduce: GPUs form a ring, each sends/receives once:

  • Communication: per GPU
  • Latency:

💡

DDP (Distributed Data Parallel) in PyTorch uses Ring AllReduce by default. It's bandwidth-optimal for homogeneous networks.

Model Parallelism

Split model across GPUs:

Pipeline Parallelism

Split model by layers:

Architecture Diagram
GPU 0: Layers 0-9
GPU 1: Layers 10-19
GPU 2: Layers 20-29
GPU 3: Layers 30-39

Problem: Pipeline bubbles — GPUs idle while waiting for activations.

Solution: Micro-batching (GPipe, PipeDream):

Architecture Diagram
Time →
GPU 0: [Micro-batch 1][Micro-batch 2][Micro-batch 3][Micro-batch 4]
GPU 1:                 [Micro-batch 1][Micro-batch 2][Micro-batch 3]
GPU 2:                                 [Micro-batch 1][Micro-batch 2]
GPU 3:                                                 [Micro-batch 1]

Tensor Parallelism

Split individual operations across GPUs:

For matrix multiplication :

Each GPU computes part of the output, then AllGather.

FSDP (Fully Sharded Data Parallel)

Combines data parallelism with model parallelism:

Key insight: Shard model parameters, gradients, and optimizer states:

Architecture Diagram
GPU 0: [Params shard 0][Gradients shard 0][Optimizer shard 0]
GPU 1: [Params shard 1][Gradients shard 1][Optimizer shard 1]
GPU 2: [Params shard 2][Gradients shard 2][Optimizer shard 2]
GPU 3: [Params shard 3][Gradients shard 3][Optimizer shard 3]

Memory savings:

  • Standard DDP: bytes (FP32 params + grads + optimizer states)
  • FSDP: bytes per GPU (where is number of GPUs)

Communication Patterns

OperationPatternBandwidthUse Case
AllReduceAll-to-allHighGradient sync
AllGatherAll-to-allHighParameter gathering
ReduceScatterAll-to-allHighGradient sharding
BroadcastOne-to-allLowParameter initialization

ZeRO Optimization

Stage 1: Shard optimizer states only Stage 2: Shard optimizer states + gradients Stage 3: Shard optimizer states + gradients + parameters

Memory comparison (GPT-3, 175B):

StageMemory/GPU
DDP700 GB
ZeRO-1175 GB
ZeRO-288 GB
ZeRO-3 (FSDP)22 GB

Communication Optimization

Overlap computation and communication:

python
# Overlap gradient all-reduce with backward pass
# PyTorch DDP does this automatically with find_unused_parameters=False

# Overlap parameter gathering with forward pass
# FSDP uses backward_prefetch=BACKWARD_PRE for this

Compression techniques:

  • Gradient quantization (FP32 → FP16/INT8)
  • Gradient sparsification (only send top-k gradients)
  • Error feedback (accumulate quantization errors)

Follow-Up Questions

Q: When should you use pipeline parallelism vs tensor parallelism? A: Pipeline parallelism for very deep models (split by layers). Tensor parallelism for very wide models (split within layers). Usually combined with data parallelism.

Q: How does FSDP compare to DeepSpeed ZeRO? A: FSDP is PyTorch native; DeepSpeed has more features (offloading, CPUAdam). FSDP is simpler; DeepSpeed is more flexible. Performance is similar.

Q: What is the communication bottleneck in distributed training? A: Gradient synchronization (AllReduce) during backward pass. Solutions: overlap with computation, gradient compression, reduce frequency of synchronization.

Related Topics


Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type — Always start by categorizing the problem
  2. Incorrect formula application — Verify the formula applies to your specific case
  3. Unit errors — Always check units are consistent throughout
  4. Sign errors — Pay careful attention to positive and negative values
  5. Rounding too early — Keep full precision until the final answer
  6. Forgetting constraints — Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
🔒

Premium Content

Distributed Training: Data Parallelism, Model Parallelism, FSDP — Asked at NVIDIA & Google

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
💼Interview Prep
📜Certificates
🤝Community Access

Already a member? Log in

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-11-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Advertisement