Reading an introduction to Megatron-LM, I encountered data, tensor and pipeline parallelism in quick succession and separately searched for tensor parallelism. That afternoon BigScience’s retrospective showed all three in one training job. BLOOM used 48 machines with eight A100 GPUs each, 384 in all, on France’s Jean Zay supercomputer. When one passage enters the model, which GPUs work on it? What are the rest computing? 12
Start with memory. The numbers a model learns are parameters. BLOOM has roughly 176 billion. Even two bytes each makes about 352 GB for the values alone, against 80 GB on one A100. Training also retains intermediate results, propagates errors back to determine changes and updates parameters. First we need to fit one model, then coordinate several copies. 3
Pipeline parallelism: what does the first stage do while the second is busy?
Simplify the network to an input and four fully connected layers. In the top half of Figure 1 each column of circles is a set of computed values. Every output uses all values in the previous column. The leftmost is input; the four remaining columns are layers. Put layers 1–2 on GPUs 0 and 1 as the first stage, and layers 3–4 on GPUs 2 and 3 as the second. The first stage sends intermediate outputs to the second to continue the forward pass. Sending a whole batch at once leaves each stage idle while the other works.
Pipeline parallelism (PP) processes different batches in different stages simultaneously. Split the text into three independently computable microbatches, A1, A2 and A3. At tick 2, the second stage runs layers 3–4 on A1 while the first runs layers 1–2 on A2. A1 still follows all four layers in order, but two groups advance during the same tick. 2
Figure 1. Follow the top diagram left to right: at the dashed boundary, layer 2’s output passes to the next stage. Read tick 2 vertically below to see different microbatches processed together. If each stage takes one tick per batch, three forward passes take four ticks instead of six.
Training also needs a return trip. The second stage compares the prediction with the target and passes back the error’s effect on the stage input: backpropagation. Each stage computes parameter gradients, describing how error changes with those parameters. Gray empty cells are idle time, or pipeline bubbles. Real schedules can interleave forward and backward passes. Stage duration and microbatch count affect idle time. Eight-tick diagram including backpropagation. 2
Where should the boundary go in a real network? Figure 1 assumes equal stage speeds. If the first takes one tick and the second three, a full pipeline produces at most one batch every three ticks despite equal layer counts. Follow computation dependencies: a skip connection crossing the boundary requires transmitting that earlier result too. Compare stage forward and backward times, peak memory and intermediate values transferred between GPUs.
BLOOM encountered memory imbalance. With about 250,000 tokens, its BF16 embedding matrix alone occupied 7.2 GB, compared with roughly 4.9 GB per Transformer block. When distributing 70 blocks, the team counted embeddings at each end as a block slot, effectively placing 72 slots across 12 stages. Each end took one fewer ordinary block to leave room. 2
Tensor parallelism: how do two GPUs divide one stage?
Zoom in on the first stage at tick 2. GPUs 0 and 1 process the same layer on A2. The layer multiplies an input by a weight matrix. If it produces 4,096 outputs, GPU 0 can hold the weights for the first 2,048 and GPU 1 the rest. They read the same input and each produces half the outputs. Which shards the next step needs determines what must be exchanged.
That is tensor parallelism (TP). One cell in the pipeline diagram already includes cooperation between two GPUs. Movement between cells along the time axis shows the handoff of microbatches. BLOOM used Megatron-LM’s within-layer partitioning. 3
Data parallelism: how can models reading different text learn the same weights?
GPUs 0–3 together contain all four layers. Put all four layers, the same initial weights and the same partitioning on GPUs 4–7 and we have a complete model replica B. A and B can read separate batches simultaneously, each taking its own data all the way through its pipeline. One update now uses both batches: data parallelism (DP). 2
Consider one parameter in the first stage’s left weight shard. On GPUs 0 and 4 it starts at 1.0. With equal sample counts, their mean gradients are 2 and 6. Plain gradient descent at learning rate 0.1 subtracts 0.1 times the gradient. Separate updates would produce 0.8 and 0.4, diverging after one step.
Instead, synchronize gradients before each GPU updates. Equal batch sizes give a mean of (2 + 6) ÷ 2 = 4. Both GPUs then perform the same calculation:
New weight = old weight − learning rate × mean gradient = 1.0 − 0.1 × 4 = 0.6.
Figure 2. The average gradient is 4; the amount subtracted is 0.4. Each GPU runs the update and stores 0.6. BLOOM’s optimizer also maintains additional state.
Where do we split a batch, a four-layer network and a matrix multiplication?
Suppose this update uses four samples. Follow sample ③ through all three forms of parallelism.
Figure 3. Eight-GPU teaching example. Circled numbers are samples, horizontal arrows are the forward pass and the purple dashed line magnifies layer 1.
- Follow the samples. ③ and ④ go to B, ① and ② to A. Both replicas contain all four layers and read their samples simultaneously. DP splits the training data. At update time corresponding gradients combine as in Figure 2.
- Follow the layer boundary. Sample ③ moves from layer 1 to 4 in B. At the orange line, GPUs 4 and 5 give layer 2’s outputs to 6 and 7. PP splits network depth. The first stage can start the next microbatch when the second takes over.
- Look inside layer 1. GPUs 4 and 5 read sample ③’s input simultaneously and multiply by separate halves of the weight columns. One computes the first half of outputs and the other the second. TP splits work inside a layer.
Scale up Figure 3 and you get the configuration in Figure 6 of the BLOOM paper. 3
| Division of work | Eight-GPU example | BLOOM |
|---|---|---|
| GPUs cooperating on a layer matrix in one stage (TP) | 2 | 4 |
| Depth stages per model (PP) | 2 | 12 |
| Model copies reading different samples (DP) | 2 | 8 |
One BLOOM replica occupies 4 × 12 = 48 GPUs. A sample traverses its 12 stages, four GPUs cooperating in each. Seven other replicas process other samples. Eight copies total 384 GPUs. At eight GPUs per physical server, 48 GPUs equal six servers’ worth. 3
What is ZeRO’s relationship to DeepSpeed, and why keep tensor parallelism?
I later searched for why tensor parallelism is needed if ZeRO already reduces memory. DeepSpeed is a distributed training library. ZeRO (Zero Redundancy Optimizer) is a family of memory optimizations it implements. DP already gives different text to A and B. ZeRO asks which data needed to train the same weights is duplicated and can be shared across replicas. 4
GPUs 0 and 4 both manage the first stage’s left shard. Suppose it contains 100 parameters updated by Adam. An optimizer uses gradients to determine updates. Adam keeps moving averages of gradients and squared gradients for each parameter; these are optimizer states. Ordinary DP would store all 100 update records twice. ZeRO can assign records 1–50 to GPU 0 and the remainder to GPU 4 while both train the same model. 4
Why shard optimizer states first? The original ZeRO paper’s mixed-precision Adam example uses 16 bytes of model state per trainable parameter on each GPU before sharding. 4
| State per parameter | Bytes per GPU before sharding | Share of 16 bytes | First sharded in |
|---|---|---|---|
| FP16 weight for forward/backward passes | 2 | 12.5% | ZeRO-3 |
| FP16 gradient from backpropagation | 2 | 12.5% | ZeRO-2 |
| FP32 master weight for optimizer updates | 4 | 25% | ZeRO-1 |
| Adam first and second moments, both FP32 | 4 + 4 | 50% | ZeRO-1 |
| Total | 16 bytes | 100% |
ZeRO-1 shards the last two items, together 75%. For 100 parameters, both GPUs still store all 100 low-precision weights and gradients, but each holds master weights and moment estimates for only 50. Model state falls from 1,600 to 1,000 bytes per GPU. 4
Those figures exclude activations and temporary buffers. Gradient precision also matters: BLOOM accumulated microbatch gradients in FP32, using four bytes per accumulated value. 42
| DP strategy | What GPUs 0 and 4 share | How they compute or update |
|---|---|---|
| Ordinary DP | Both store all parameters, gradients and optimizer states for the shard | After aggregating gradients, each GPU makes identical local updates |
| ZeRO-1 | Partition optimizer states | Each updates its assigned 50 parameters, then exchanges updates so both have all 100 current values |
| ZeRO-2 | Also partition gradients | Aggregate gradients by owner; each retains only what it needs to update |
| ZeRO-3 | Also partition parameters | Each normally holds 50 weights, gathering what the current layer needs and optionally freeing temporary copies afterward |
What does keeping only your gradients mean with ZeRO-2? Pick A and B from those 100 parameters. GPU 0 owns A and GPU 4 owns B. At computation time both hold A and B starting at 1.0. Each sees different equal-sized samples and computes gradients for both A and B. 4
| Parameter | GPU 0 gradient | GPU 4 gradient | Owner collecting and keeping the mean |
|---|---|---|---|
| A | 2 | 6 | GPU 4 sends 6 to GPU 0; GPU 0 retains (2 + 6) ÷ 2 = 4 |
| B | 8 | 4 | GPU 0 sends 8 to GPU 4; GPU 4 retains (8 + 4) ÷ 2 = 6 |
GPU 4’s contribution of 6 is included in A’s mean. Only GPU 0 needs to keep A’s 4 for its update. Likewise GPU 4 keeps B’s 6. Aggregating by parameter and distributing each result to its owner is reduce-scatter here. Dividing by two averages gradients from equally sized sample batches.
With the same simple gradient descent and learning rate 0.1, GPU 0 updates A to 1.0 − 0.1 × 4 = 0.6; GPU 4 updates B to 1.0 − 0.1 × 6 = 0.4. They exchange the updated A and B. For the next batch both again have identical A and B.
The stages are cumulative. “Complete” here means the 100 parameters this DP pair collectively owns. GPUs 0 and 4 sharding state still read different samples. GPUs 0 and 1 splitting a multiplication compute one layer for the same text. The top row of Figure 3 alone can use TP. Only with the second row is there redundancy across replicas for ZeRO to remove. 42
How can ZeRO-3 compute a layer with only 50 weights per GPU? Split the 100 weights shared by GPUs 0 and 4 in half. Follow one training step, assuming the temporary gathered weights are released after forward computation. 45
sequenceDiagram
participant A as 卡 0(读样本甲)
participant B as 卡 4(读样本乙)
Note over A: 常驻前 50 个权重和更新记录
Note over B: 常驻后 50 个权重和更新记录
A->>B: 前 50 个权重
B->>A: 后 50 个权重
Note over A,B: 前向:各用 100 个权重算自己的样本
Note over A,B: 留下反向要用的中间结果,释放临时权重
A->>B: 反向再发前 50 个权重
B->>A: 反向再发后 50 个权重
Note over A,B: 各自算出样本对这 100 个权重的梯度
B->>A: 样本乙对前 50 个权重的梯度
A->>B: 样本甲对后 50 个权重的梯度
Note over A: 汇总两份贡献,只更新前 50 个
Note over B: 汇总两份贡献,只更新后 50 个
Figure 4. Two GPUs under ZeRO-3. Follow GPU 0: it fetches the second half of weights from GPU 4 for its own samples, and receives gradients for the first half to update its own weights. Arrows indicate transferred data; exchanges can happen simultaneously. 45
The first two exchanges transfer weights, temporarily combining shards on each GPU through all-gather. The final exchange transfers gradients, using reduce-scatter to collect them by owner. Each GPU still persistently stores 50 weights plus the corresponding optimizer states. The next gather fetches their updated values. 4

Figure 5. Five frames from Microsoft Research’s demonstration, annotated in Chinese. Follow GPU 0 at upper left: frame 1 shows the weights it reads, frame 4 shows incoming gradients and frame 5 its shard update. Play the original MP4 · Microsoft Research page 6
After tensor partitioning, how different are ZeRO-2 and ZeRO-3?
Return to GPUs 0 and 4. TP has already selected each local matrix region; these two are DP partners reading different samples. Count state for this region’s 100 parameters at 16 bytes each. Assume equal shares and one microbatch per step. Compare persistent state and the weights exchanged for computation.
| Per GPU | Tensor parallelism + ZeRO-2 | Tensor parallelism + ZeRO-3 |
|---|---|---|
| Sharded model state | 100 half-precision weights plus gradients, master weights and Adam records for 50: 100×2 + 50×14 = 900 bytes | 50 complete states: 50×16 = 800 bytes |
| Weights received per step | Exchange 50 new weights after update: 100 bytes | If freed after forward, fetch 50 in forward and backward: 200 bytes |
| Required by both | Aggregate sample gradients for each parameter at the owner | Same; fetched weights compute local samples |
Stage 3 saves 100 persistent bytes per GPU here while receiving 100 more bytes of weights per step. Both need space for activations, communication buffers and temporary weights. If stage 2 fits, keeping parameters can save time; if replicas consume too much space, stage 3 can help. DeepSpeed may keep small parameters resident and prefetch. Two gathers depend on release policy. 47
DeepSpeed’s _partition_param flattens an individual parameter, pads it to divide evenly and gives each DP process a contiguous segment. The boundary can cross a matrix row. An ordinary linear layer still needs weights for the local multiplication when it runs. TP specifies which rows or columns that multiplication needs. Tiny persistent shards do not eliminate temporary weight and activation memory. Operators too large to run at once can also be tiled sequentially, as in DeepSpeed’s TiledLinear. 7
Fragmentation has a communication cost. Ten messages carrying the same bytes as a 10 MB block can incur nine extra startups. Grouped gathers and prefetch limit this. Finer TP changes local multiply size and activation exchanges; DP group size determines how many redundant states can be shared. Consider memory and communication in both groups. 7
What did BLOOM use? Megatron-DeepSpeed combined Megatron-LM for tensor parallelism inside layers and DeepSpeed for pipeline parallelism, stage scheduling and optimizer-state sharding across DP replicas. The last used ZeRO-1. The paper says, “We used ZeRO stage 1, meaning that only the optimizer states are sharded in this manner.” 32
Why stop at ZeRO-1? Pipeline microbatches reduce idle time. In the ZeRO-2 configuration evaluated at the time, each backward microbatch required an additional reduce-scatter between DP partners, summing corresponding gradients and retaining only the assigned segment. More microbatches per update repeated that communication. BLOOM already split gradients across 12 stages, each storing just its layers’ gradients, reducing the benefit of further gradient sharding. 2
ZeRO-3 would also consume bandwidth gathering weights, stalling layers whose weights had not arrived. The team found ZeRO-1 with three-dimensional parallelism performed best among the configurations tested then. By the 2022 retrospective ZeRO-3 performance had improved and the authors wrote, “perhaps we would have chosen stage 3 instead.” 2
The job script sets ZERO_STAGE=0. Its comment explains: BLOOM used BF16, a 16-bit floating-point format, and its optimizer already implemented equivalent stage-1 sharding, so generic ZeRO was switched off. A flag alone does not tell you which component stores and updates the state. 8
Would BLOOM use the same partitions on different hardware?
BLOOM used 384 80 GB A100s. Imagine the same model, GPU count and compute, but half as much memory per GPU. The weights, gradients, optimizer state and activations of a stage may no longer fit. Compare ZeRO-3, gathering weights at use time, with fewer layers per stage and more stages per model. More memory might instead let adjacent stages merge, eliminating a handoff. Speed depends on compute and waiting across the whole step. 24
Faster compute can change the choice even if memory is sufficient. Suppose four GPUs multiply for eight milliseconds then wait two for results. Doubling compute speed drops ten milliseconds to six, still with two waiting. Try two GPUs per layer: each computes more, but fewer communicate. If memory suffices and communication savings exceed added compute, this can be faster. The figures illustrate compute/interconnect balance. 9
Four GPUs in one or several machines are not equivalent. BLOOM nodes had eight GPUs linked by NVLink; cross-node traffic used Omni-Path. TP exchanges results in many layers, repeatedly paying for a slow link if spread across machines. Megatron-LM’s team measured better throughput keeping frequent TP communication inside nodes and crossing nodes between pipeline stages. Software can choose data, route and timing, but a fixed volume traversing a link is bounded by bandwidth. Model structure and framework alone cannot determine a universally fastest configuration. 29
Workloads also influence chip design. An embedding lookup takes one row from a large table per token, with the next row selected by the next ID. More matrix-multiplication units offer limited benefit for scattered lookups. Google’s TPU v4 provides SparseCore for embedding lookup, aggregation and updates. Faster lookup can shorten a stage while the table still consumes storage. After changing chips, measure each stage’s duration and memory before assigning more blocks to the first or last stage. 102
Which computation warrants dedicated silicon? NVIDIA’s A100 retains CUDA cores for general arithmetic and Tensor Cores for matrix multiply-add. Attention and feed-forward layers both use many matrix products, so the same circuit serves different layers. A100 also supports a narrower case: at least two zeros in each group of four weights along a specified dimension. Software compresses weights and records positions so hardware can skip the corresponding products. The narrower the condition, the more designers must weigh future model coverage and share of step time against area and power. Doubling matrix throughput still does not remove inter-GPU waits. 11
Hardware/software co-design can reveal combinations with little payoff in isolation. If ZeRO-3 waits for next-layer weights, adding memory alone leaves the framework fetching late; prefetching alone may have nowhere to put them. Together, the changes can overlap current computation with fetching into available memory. Actual savings still depend on bandwidth. 49
To maximize training tokens per second within cost and power limits, evaluate memory, interconnects, stage boundaries and transfer timing in one design space using end-to-end throughput. Individually choosing the fastest chip, most memory-efficient partition and least traffic can miss valuable combinations. Joint evaluation can approach the constrained optimum. BLOOM’s measurements establish which evaluated setup worked best at the time. 2
Back to BLOOM’s four GPUs per layer. Even once we choose the group size, does each GPU compute some complete outputs or only part of every output? The next article works through numbers by hand. What do 1D, 2D, 2.5D and 3D mean in tensor parallelism?
Footnotes
-
简枫. (2024, April 1). 深入理解 Megatron-LM(1)基础知识(第 1 节“导读”、第 3.2.3 节“技术组合”). 知乎. 原文 ↩
-
Bekman, S. (2022, July 14). The technology behind BLOOM training(“Pipeline Parallelism”“DP+PP+TP”“ZeRO DP+PP+TP”). Hugging Face. 英文原文 · MatrixYao 中文译本 ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14
-
BigScience Workshop. (2022). BLOOM: A 176B-parameter open-access multilingual language model. arXiv. 第 3.4.1–3.4.2 节、图 6,ZeRO 引文见图后段落 ↩ ↩2 ↩3 ↩4 ↩5
-
Rajbhandari, S., Rasley, J., Ruwase, O., & He, Y. (2019). ZeRO: Memory optimizations toward training trillion parameter models. arXiv. 原始论文;DeepSpeed. (n.d.). Zero Redundancy Optimizer(“ZeRO Overview”). 三个分片阶段 ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13
-
牛犁heart. (2024, August 4). ZeRO:一种去除冗余的数据并行方案. 博客园。“图解”一节的四卡训练过程与动图。图 4 为本文沿用卡 0、卡 4 和 100 个权重算例自绘。 ↩ ↩2
-
DeepSpeed Team, Majumder, R., & Wang, J. (2020, February 13). ZeRO & DeepSpeed: New system optimizations enable training models with over 100 billion parameters. Microsoft Research Blog. 跳到一次训练迭代的演示说明。 ↩
-
DeepSpeed contributors. (2025). ZeRO parameter partitioning (v0.17.1). GitHub.
_aligned_size与_partition_param的分片实现。DeepSpeed documentation. (n.d.). 参数持久化、子模块显存要求与 Memory-Centric Tiling。 ↩ ↩2 ↩3 -
BigScience Workshop. (2022). tr11-176B-ml.slurm [训练作业脚本]. GitHub. BF16 优化器的 ZeRO 配置注释 ↩
-
Narayanan, D., Shoeybi, M., Casper, J., LeGresley, P., Patwary, M., Korthikanti, V., Vainbrand, D., Kashinkunti, P., Bernauer, J., Catanzaro, B., Phanishayee, A., & Zaharia, M. (2021). Efficient large-scale language model training on GPU clusters using Megatron-LM. SC ’21. 第 5.4.1 节,张量并行与流水线并行的组合实验 ↩ ↩2 ↩3
-
Jouppi, N. P., Kurian, G., Li, S., Ma, P., Nagarajan, R., Nai, L., Patil, N., Subramanian, S., Swing, A., Towles, B., Young, C., Zhou, X., Zhou, Z., & Patterson, D. (2023). TPU v4: An optically reconfigurable supercomputer for machine learning with hardware support for embeddings. ISCA ’23. 关于 SparseCore 的设计 ↩
-
NVIDIA. (2020). NVIDIA A100 Tensor Core GPU architecture. 架构白皮书,第 11 页;Busato, F., & Pool, J. (2020, December 8). Exploiting NVIDIA Ampere structured sparsity with cuSPARSELt. NVIDIA Technical Blog. 图 2 与稀疏权重的存储方式 ↩