Data Parallelism

Volume IV, Chapter 19 — Part I. Distributed training via data parallelism: gradient aggregation, AllReduce, synchronous SGD theory, communication complexity, and scaling efficiency analysis.

Intermediate

Table of Contents

  1. Learning Objectives
  2. Prerequisites
  3. Notation
  4. Core Intuition
  5. Single-Device Training Recap
  6. Data Parallelism Formulation
  7. Gradient Aggregation and AllReduce
  8. Synchronous Distributed SGD
  9. Communication Complexity
  10. Scaling Efficiency and Amdahl's Law
  11. Effective Batch Size and Learning Rate
  12. Worked Examples
  13. Connection to the Broader Curriculum
  14. Common Pitfalls and Misconceptions
  15. Research Perspective
  16. Summary of Takeaways
  17. Exercises

Learning Objectives

After reading this chapter, you should be able to:

  1. Define data parallelism: replicate model, partition data across KK devices.
  2. Derive synchronous gradient averaging: gˉ=1Kk=1Kgk\bar{\mathbf{g}} = \frac{1}{K}\sum_{k=1}^K \mathbf{g}_k.
  3. Explain AllReduce as the communication primitive for gradient aggregation.
  4. Analyze communication volume O(Kθ)O(K \cdot |\boldsymbol{\theta}|) vs. ring AllReduce O(θ)O(|\boldsymbol{\theta}|).
  5. Apply Amdahl's law to parallel training efficiency.
  6. Relate effective batch size to learning rate scaling rules.

Prerequisites


Notation

  • KK — Number of parallel workers (GPUs)
  • Bk\mathcal{B}_k — Mini-batch on worker kk
  • gk\mathbf{g}_k — Local gradient on worker kk
  • gˉ\bar{\mathbf{g}} — Averaged global gradient
  • θ\boldsymbol{\theta} — Shared model parameters

Core Intuition

Training large models requires multiple GPUs. Data parallelism is the simplest strategy: replicate the full model on each device, split the mini-batch across devices, compute local gradients, average gradients, and apply synchronized update.

This is equivalent to Gradient Descent on a larger effective batch — but requires communication (AllReduce) that can become the bottleneck at scale.

Series context. Volume IV, Chapter 19 (Parallelism). Orthogonal to Flash Attention (memory) and Quantization (precision).

Interactive: Distributed Training Parallelism

Each GPU gets a copy of the full model, different data batch

GPU 0

Full Model
Batch 1/4

↕ AllReduce gradients

GPU 1

Full Model
Batch 2/4

↕ AllReduce gradients

GPU 2

Full Model
Batch 3/4

↕ AllReduce gradients

GPU 3

Full Model
Batch 4/4

↕ AllReduce gradients

Data Parallel: Scales batch size linearly. Each GPU needs full model memory. Communication: gradient AllReduce.

Single-Device Training Recap

Definition 1 (SGD Update).

θt+1=θtα1BiBθLi(θt).(1)\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \alpha \cdot \frac{1}{|\mathcal{B}|}\sum_{i \in \mathcal{B}} \nabla_{\boldsymbol{\theta}} \mathcal{L}_i(\boldsymbol{\theta}_t). \tag{1}

Each step: forward + backward on batch B\mathcal{B}, then update.


Data Parallelism Formulation

Definition 2 (Data Parallel Setup). KK devices, each holds copy of θ\boldsymbol{\theta}. Mini-batch B\mathcal{B} split into B1,,BK\mathcal{B}_1, \ldots, \mathcal{B}_K with Bk=B/K|\mathcal{B}_k| = |\mathcal{B}|/K.

Algorithm:

  1. Each device kk computes local gradient gk=1BkiBkLi\mathbf{g}_k = \frac{1}{|\mathcal{B}_k|}\sum_{i \in \mathcal{B}_k} \nabla \mathcal{L}_i
  2. AllReduce: compute average gˉ=1Kkgk\bar{\mathbf{g}} = \frac{1}{K}\sum_k \mathbf{g}_k
  3. Each device updates: θθαgˉ\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} - \alpha \bar{\mathbf{g}}

Theorem 1 (Equivalence). Synchronized data parallel SGD with averaged gradients is equivalent to SGD on full batch B=kBk\mathcal{B} = \cup_k \mathcal{B}_k (assuming deterministic ops).

Proof. gˉ=1Kk1BkiBkLi=1BiBLi\bar{\mathbf{g}} = \frac{1}{K}\sum_k \frac{1}{|\mathcal{B}_k|}\sum_{i \in \mathcal{B}_k} \nabla \mathcal{L}_i = \frac{1}{|\mathcal{B}|}\sum_{i \in \mathcal{B}} \nabla \mathcal{L}_i. \blacksquare


Gradient Aggregation and AllReduce

Definition 3 (AllReduce). Collective operation: each of KK processes holds vector vk\mathbf{v}_k; after AllReduce, all processes hold kvk\sum_k \mathbf{v}_k (or average).

Definition 4 (Ring AllReduce). Arrange KK GPUs in ring; pass gradient chunks in K1K-1 steps. Bandwidth-optimal: each GPU sends/receives 2(K1)/K22(K-1)/K \approx 2 × gradient size total.

Proposition 1. Naive AllReduce: O(Kθ)O(K \cdot |\boldsymbol{\theta}|) data transferred. Ring AllReduce: O(θ)O(|\boldsymbol{\theta}|) per device regardless of KK (bandwidth-limited).


Synchronous Distributed SGD

Definition 5 (Synchronous Training). All devices wait for slowest before update — straggler problem.

Definition 6 (Asynchronous Training). Devices update independently with stale gradients — convergence complications.

Production LLM training uses synchronous data parallelism with gradient accumulation for large effective batches (Scaling Laws).


Communication Complexity

Definition 7 (Communication Time).

Tcomm=2θbytesKbandwidth+latency,(2)T_{\text{comm}} = \frac{2|\boldsymbol{\theta}| \cdot \text{bytes}}{K \cdot \text{bandwidth}} + \text{latency}, \tag{2}

for ring AllReduce (factor 2 for send + receive).

Definition 8 (Compute Time).

Tcompute=BCfwd+bwdKFLOPS.(3)T_{\text{compute}} = \frac{|\mathcal{B}| \cdot C_{\text{fwd+bwd}}}{K \cdot \text{FLOPS}}. \tag{3}

Proposition 2. Training is communication-bound when Tcomm>TcomputeT_{\text{comm}} > T_{\text{compute}} — common for small models on fast GPUs or large KK.


Scaling Efficiency and Amdahl's Law

Definition 9 (Strong Scaling Efficiency).

η=T1KTK,(4)\eta = \frac{T_1}{K \cdot T_K}, \tag{4}

where TKT_K is time with KK devices.

Theorem 2 (Amdahl's Law). If fraction pp of work is parallelizable:

η1(1p)+p/K.(5)\eta \leq \frac{1}{(1-p) + p/K}. \tag{5}

Sequential overhead (communication, I/O) limits speedup.

Proposition 3. For LLM training with large batches, p1p \approx 1 and η>0.9\eta > 0.9 achievable up to hundreds of GPUs with optimized AllReduce.


Effective Batch Size and Learning Rate

Definition 10 (Effective Batch Size). Beff=K×Bk×accumulation stepsB_{\text{eff}} = K \times |\mathcal{B}_k| \times \text{accumulation steps}.

Proposition 4 (Linear Scaling Rule). When increasing BeffB_{\text{eff}} by factor KK, scale learning rate αKα\alpha \leftarrow K \alpha (up to stability limit) — preserves SGD dynamics approximately.

Proposition 5 (Square Root Scaling). Alternative: αKα\alpha \leftarrow \sqrt{K}\,\alpha — more conservative, better for large KK.

See Gradient Descent and Scaling Laws.


Worked Examples

Example 1: AllReduce Volume

θ=7×109|\boldsymbol{\theta}| = 7 \times 10^9, FP32, K=8K = 8: gradient size 28 GB; ring AllReduce \approx 56 GB total transferred across network.

Example 2: Effective Batch

K=64K=64, local batch 2, accumulation 4: Beff=512B_{\text{eff}} = 512.


Connection to the Broader Curriculum


Common Pitfalls and Misconceptions

Pitfall 1: Assuming linear speedup to arbitrary KK.

Pitfall 2: Ignoring straggler effects in synchronous training.

Pitfall 3: Not scaling learning rate with batch size.

Pitfall 4: Confusing data parallelism with model/tensor parallelism.


Research Perspective

Distributed data parallelism underpins virtually all large-scale neural network training. Ring AllReduce (Baidu, 2017) established bandwidth-optimal gradient aggregation. Horovod (Sergeev & Balso, 2018) standardized collective communication across heterogeneous clusters. Megatron-LM and subsequent systems combine data parallelism with tensor and pipeline parallelism for models that exceed single-device memory. ZeRO (Rajbhandari et al., 2020) shards optimizer states across devices, reducing per-GPU memory while preserving the data-parallel abstraction. Gradient compression and error-feedback methods remain active research directions for bandwidth-constrained environments.


Summary of Takeaways

  • Data parallel — Replicate model, split batch
  • Gradient — Average via AllReduce
  • Ring AllReduceO(θ)O(\lVert \boldsymbol{\theta} \rVert) bandwidth
  • Efficiency — Amdahl limits speedup
  • Batch scaling — Effective batch KBkK \cdot — \mathcal{B}_k —

Exercises

Exercise 1. Prove Theorem 1.

Exercise 2. Derive ring AllReduce communication volume.

Exercise 3. Compute TcommT_{\text{comm}} vs TcomputeT_{\text{compute}} for given config.

Exercise 4. Amdahl: if 5% sequential, max speedup at K=100K=100?

Exercise 5. Linear vs. sqrt learning rate scaling.

Exercise 6. Compare data vs. model parallelism for 70B model.

Exercise 7. Gradient accumulation equivalence.

Exercise 8. Connect to Scaling Laws compute budget.