Topic 40 of 62 · Training at scale
Choosing TP, PP and DP for a large run
HardGiven a 70B model and 1,024 GPUs, how do you choose tensor, pipeline and data parallel degrees?
1 · Start with the intuition
Start from memory: the model state must fit. Then map each kind of parallelism to the network it tolerates. Tensor parallelism is communication-heavy, so it goes inside a node. Pipeline parallelism sends little data but creates idle bubbles, so it spans nodes when the model still does not fit. Data parallelism, with sharded optimizer state, fills the remaining GPUs to raise throughput.
2 · How the mechanism works
Mechanism step 1 of 3 · no question to answer
Fit memory
Count bytes per parameter for weights, gradients and optimizer states, plus activations.
Next, we will look at: Place TP, then PP. Move on when this operation makes sense.
Visualizing the behavior
Model-state memory per GPU for 70B (excludes activations)
Derived3 · The governing equation
GPUs = TP × PP × DP Global batch = DP × micro-batch × microbatches per step Bubble fraction = (PP − 1) / (m + PP − 1)
Notation: m is the number of microbatches each pipeline processes per step. Constraints: attention heads (and KV heads) divisible by TP; layers divisible by PP or virtual stages.
Too much TP makes each GPU’s matrices small and communication-bound; too much PP needs many microbatches to hide the bubble, which forces a large global batch; too much DP runs into the maximum useful batch size. The practical guidance from Megatron-LM is TP up to the node size, PP across nodes as needed, and DP for the rest. ZeRO-1 or FSDP sharding over DP removes optimizer-state replication. Activation checkpointing and sequence parallelism then handle activation memory.
4 · Put concrete numbers on it
Worked numbers (from stated assumptions)5 · Common misconception to avoid
“Maximize tensor parallelism to minimize memory.” Across nodes it stalls every layer on slow links, and at high degrees each GPU’s matmuls become too small to run efficiently.
In practice · implementation & engineering rule of thumb
Verify divisibility constraints up front: both H_q and H_kv must be divisible by TP, total layers L must be divisible by PP, and TP × PP × DP must equal total GPUs.
assert num_query_heads % tp_size == 0 and num_kv_heads % tp_size == 0 assert num_layers % pp_size == 0 assert (tp_size * pp_size * dp_size) == world_size
Go one level deeper
Follow-ups that often come after a correct first answer.
- FSDP instead of TP/PP
- For models up to tens of billions of parameters, FSDP or ZeRO-3 alone, often hybrid-sharded within nodes, can avoid pipeline bubbles and TP complexity. It pays with parameter all-gathers every layer, so it depends on good overlap and enough tokens per GPU.
- Validate with a small-scale dry run
- Before launching, run a few steps at the target layout to measure memory headroom, step time and MFU, and to catch a mismatched degree (for example KV heads not divisible by TP). Fixing layout on a live thousand-GPU run is expensive.
6 · Self-check & interview synthesis
Explain it in your own words first
Before revealing the reference answer, try answering the opening question aloud in four beats: what it is → how the math works → what trade-off it makes → a concrete number or failure mode.
Follow-up question interviewers often ask next
MediumContext length jumps from 8K to 128K tokens. What do you add?
Show follow-up reasoning
Activation memory per sequence grows roughly linearly with length (with FlashAttention), so add context/sequence parallelism, which splits the sequence across GPUs using ring attention or all-to-all schemes, plus activation checkpointing. You may also lower the micro-batch and rebalance PP.