← Back to AI Infrastructure Mind Map
🖥️ AI InfrastructureID: distributed-parallel

4D Parallelism DP/TP/PP/SP

4D 并行 DP/TP/PP/SP
🎯Core Definition
Four parallelism dimensions that shard parameters, gradients, activations and sequences across GPUs. ① DP (data parallel): every rank holds a full model copy, only data is sharded; one full gradient AllReduce per step, the ring version costs 2N−1NS≈2S2\frac{N-1}{N}S \approx 2S per rank (SS = per-rank gradient size, growing linearly with parameter count — a 70B model has about 140GB of gradients per rank, so DP sync is expensive for large models); communication happens only between steps and can be hidden by bucket-async overlap. ② TP (tensor parallel): intra-layer matrices are split column/row-wise (see megatron-3d-bubble); each transformer layer runs 2 AllReduces, each message only about b×s×hb \times s \times h activations (independent of parameter count, but frequent and latency-sensitive) — it needs intra-node NVLink (900GB/s+) to be viable. ③ PP (pipeline parallel): layers are split into stages; communication only at stage boundaries, one activation and one gradient message (~b×s×hb \times s \times h) per microbatch — low volume, low frequency, latency adds linearly, so it fits cross-node IB; the cost is the pipeline bubble (bubble ratio p−1m+p−1\frac{p-1}{m+p-1}, see megatron-3d-bubble). ④ SP (sequence parallel): the sequence dimension is split into N chunks across N ranks, fixing KV/activation memory growing linearly with seq length; two implementations: Megatron-SP (combined with TP, also shards LayerNorm/Dropout activations to cut TP's activation traffic) and Ring-Attention (KV blocks circulate on a ring, O(1) memory per rank). 3D combination DP × TP × PP: GPT-3 175B used 1024 A100s = DP 64 × TP 8 × PP 2; the allocation rule: fill TP inside a node first (it consumes NVLink bandwidth), PP across nodes (least traffic), DP outermost for gradient sync — communication cost decreases from the inside out while scalability increases from the inside out.
💡Use Cases
a training-infra interview staple: how much each of DP/TP/PP communicates, why TP cannot span nodes, how SP relates to TP, and how to configure 3D parallelism for a given GPU count.
⚡Key Problems Solved
the single GPU runs out of memory (weights + optimizer + activations) and saturates neither compute nor bandwidth — TP shards weights, PP shards layers, DP shards data, SP shards the sequence; stacked together, arbitrarily large models train on arbitrarily many GPUs with near-linear efficiency, and every per-layer message lands on the right interconnect (intra-node NVLink vs inter-node IB).
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of 4D Parallelism DP/TP/PP/SP.
Use Cases
In production engineering, what are the primary use cases for 4D Parallelism DP/TP/PP/SP and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Derive DP's communication: the ring AllReduce per step is 2N−1NS≈2S2\frac{N-1}{N}S \approx 2S (SS = per-rank gradient), independent of N; explain why DP is still expensive for large models — S grows linearly with parameters (70B gradients ≈ 140GB).
2
TP communication profile: 2 AllReduces per layer, each ~b×s×hb \times s \times h and independent of parameter count; argue why TP must stay intra-node (NVLink 900GB/s, low latency) and what happens across nodes.
3
PP communication: why its volume is small (one activation + one gradient per microbatch between adjacent stages, ~b×s×hb \times s \times h) and fits across nodes; what is its cost (bubble p−1m+p−1\frac{p-1}{m+p-1}, see its card).
4
SP: what is sharded (the sequence dimension), what it fixes (KV/activation memory linear in seq), and the communication cost and fit of Megatron-SP vs Ring-Attention.
5
3D configuration problem: given total GPUs and model size, allocate TP intra-node → PP inter-node → DP outermost; recite GPT-3 175B's 1024 GPUs = DP 64 × TP 8 × PP 2 and justify each dimension.
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "4D Parallelism DP/TP/PP/SP"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardCollective Comm & NVLink TopologyNext Card →Megatron 3D & Pipeline Bubble

🔗 More AI Infrastructure Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/AI_Infra/card/distributed-parallel
中文速览与面试要点

4D 并行 DP/TP/PP/SP (4D Parallelism DP/TP/PP/SP)

定义: 大模型训练把参数量、梯度、激活、序列切到多卡上的四种并行维度。① DP 数据并行: 每卡一份完整模型, 只切数据; 每步迭代结束做一次全量梯度 AllReduce, 环形实现下每卡通信量 2 N-1NS 2S(S = 单卡梯度总大小, 随参数量线性增长——70B 每卡梯度 ≈ 140GB, 因此大模型 DP 同步很贵); 通信只发生在 step 之间, 可被 bucket 异步重叠隐藏。② TP 张量并行: 层内矩阵按列/行切分(详见 megatron-3d-bubble), 每个 transformer 层 2 次 AllReduce, 每次消息量仅 ~b s h 的激活(与参数量无关, 但发生频率高、延迟敏感)——必须用节点内 NVLink(900GB/s+)才能承受。③ PP 流水线并行: 层按 stage 切分, 每 stage 持有若干层; 通信只在相邻 stage 边界, 每个 microbatch 传一次激活与一次梯度(~b s h), 量大频率低、延迟线性叠加——适合跨节点 IB 链路; 代价是气泡(bubble, 气泡率 p-1m+p-1, 见 megatron-3d-bubble)。④ SP 序列并行: 把序列维度切成 N 段分到 N 卡, 解决长序列下 KV/激活显存随 seq 线性膨胀; 两种实现: Megatron-SP(与 TP 结合, 把 LayerNorm/Dropout 的激活也切分, 削减 TP 的激活通信)与 Ring-Attention(ring 传递 KV, 每卡显存 O(1))。3D 并行组合 DP × TP × PP: 以 GPT-3 175B 为例, 1024 张 A100 = DP 64 × TP 8 × PP 2; 分配原则: TP 先切满节点内(吃 NVLink 带宽)、PP 跨节点(通信最少)、DP 最外层做梯度同步——通信代价自内向外递减, 可扩展性自内向外递增。 使用场景: 训练 Infra 面试必考: “DP/TP/PP 各通信多少”“为什么 TP 不能跨节点”“SP 与 TP 什么关系”“给 512 张卡怎么配 3D 并行”。 解决的问题: 单卡显存放不下(权重+优化器+激活)与单卡算力/带宽打不满——TP 切权重、PP 切层、DP 切数据、SP 切序列, 四者叠加让任意大的模型在任意多的卡上以接近线性的效率训练, 且每层通信量都能落在合适的互联(节点内 NVLink / 跨节点 IB)上。

核心要点

  • 手算 DP 通信量: 每步环形 AllReduce 2 N-1NS 2S(S = 单卡梯度), 与卡数 N 无关; 解释为什么大模型 DP 仍然贵——S 随参数量线性增长(70B 梯度 ≈ 140GB)。
  • TP 通信特征: 每层 2 次 AllReduce、每次消息量 ~b s h 与参数量无关; 推导为什么 TP 只能在节点内(NVLink 900GB/s、低延迟), 跨节点会怎样。
  • PP 通信: 为什么 PP 通信量小(每 microbatch 相邻 stage 一次激活 + 一次梯度, ~b s h)且适合跨节点; 它的代价是什么(气泡率 p-1m+p-1, 见对应卡片)。
  • SP 序列并行: 切什么(序列维度)、解决什么(KV/激活显存随 seq 线性)、两种实现 Megatron-SP 与 Ring-Attention 各自的通信代价与适用场景。
  • 3D 并行配置题: 给定 GPU 总数与模型规模, 按「TP 节点内 → PP 节点间 → DP 最外层」分配; 复述 GPT-3 175B 的 1024 卡 = DP 64 × TP 8 × PP 2 并解释每层选择的理由。