Tensor, Pipeline, and Expert Parallelism
Scroll horizontally to inspect the diagram.
Using more GPUs can make a model fit, reduce the work each GPU performs, or serve more independent requests. Those goals lead to different layouts. Splitting a model also adds communication, so a layout that saves memory can make a single request slower.
The memory budget gives the first constraint. A rounded 70B model has about 140 GB of raw 16-bit weights or 35 GB of raw four-bit weights. The latter can leave substantial capacity on an 80 GB device, although metadata, workspace, and KV cache still need room. Parameter count alone does not tell you how many GPUs to use.
Tensor parallelism: split one operation
Each GPU gets the same input x = [1, 2, 3, 4] and one column of this toy weight matrix.
Outputs stay on their ranks. A later operation may consume these shards without gathering them.
This is a column split. A row split instead produces partial sums that need a reduction.
Pipeline parallelism: split the layers
Four equally timed stages process six micro-batches. Each cell is one forward computation; this example omits communication and backward passes.
| slot | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| GPU 1 | μ1 | μ2 | μ3 | μ4 | μ5 | μ6 | · | · | · |
| GPU 2 | · | μ1 | μ2 | μ3 | μ4 | μ5 | μ6 | · | · |
| GPU 3 | · | · | μ1 | μ2 | μ3 | μ4 | μ5 | μ6 | · |
| GPU 4 | · | · | · | μ1 | μ2 | μ3 | μ4 | μ5 | μ6 |
4 of 4 GPUs busy in this slot. The whole schedule uses 24 of 36 stage-slots (66.7%).
μ1–μ6 are micro-batches. Empty cells show pipeline fill and drain. These diagrams compare partitioning, not speed.
Tensor parallelism splits a matrix operation; pipeline parallelism distributes layers and overlaps independent microbatches. The schedules do not compare measured speed.
Tensor parallelism: distinguish columns from rows
Write a linear layer using row-vector convention, .
If is partitioned by output columns, each GPU can receive the same and compute a different slice of . Those slices concatenate to form the complete output. They are different coordinates, so summing them would be wrong.
If is partitioned by input rows, each GPU multiplies the matching slice of by its rows of . These results are contributions to the same output coordinates, so they must be summed, often with an all-reduce.
x = [2, 3]; W = [[1, 2, 3, 4], [5, 6, 7, 8]]
GPU 0
Replicated x × output columns 0–1
[17, 22]
GPU 1
Replicated x × output columns 2–3
[27, 32]
All-gather / concatenate the distinct coordinates
y = [17, 22, 27, 32]
An all-gather makes the full vector available on each rank if the next operation needs it. A compatible next layer can instead consume the sharded output.
A common Megatron-style feedforward layout pairs a column-parallel expansion with a row-parallel contraction. The intermediate activation remains sharded, avoiding a gather between them. There is a reduction after the contraction. A similarly arranged attention block adds another reduction after its output projection: typically two forward collectives per full transformer block in this layout, not one for every matrix.
Implementations can use different collective combinations, sequence parallelism, or fused communication. Some tensors remain replicated. KV heads can also be replicated when the tensor-parallel degree exceeds the model's KV-head count.
Pipeline parallelism: different layers, overlapping work
Pipeline parallelism places consecutive layer groups on different devices. Activations move from one stage to the next, while each stage keeps the KV cache for its own attention layers.
One request traversing four stages leaves three stages idle while the current stage works. Independent microbatches can overlap: stage 0 handles B while stage 1 handles A. A later generated token from the same sequence still depends on sampling the previous token after the final stage; it cannot be treated as an independent microbatch.
Assumed linear stage time: the whole batch takes four time units per stage; each quarter takes one. Both schedules perform 16 stage-time units of work.
| Stage | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GPU 0 | all | all | all | all | · | · | · | · | · | · | · | · | · | · | · | · |
| GPU 1 | · | · | · | · | all | all | all | all | · | · | · | · | · | · | · | · |
| GPU 2 | · | · | · | · | · | · | · | · | all | all | all | all | · | · | · | · |
| GPU 3 | · | · | · | · | · | · | · | · | · | · | · | · | all | all | all | all |
Makespan: 16 units · busy slots: 16/64 (25.0%) · idle slots: 48
Forward-only, equal stages, no communication cost. Microbatches contain independent work; this does not remove dependencies between successive generated tokens of one sequence.
If there are equally fast stages and microbatches, each taking one time unit per stage, a forward pass takes units. The idle fraction across that window is
With four stages and four microbatches this is , about 43%. Sixteen microbatches reduce it to , about 16%, under the same assumptions. Communication, unequal layers, changing batch shapes, and autoregressive feedback complicate a real inference schedule.
Expert parallelism: send activations to the chosen experts
In a mixture-of-experts model, a router chooses a subset of expert networks for each token. Expert parallelism places those networks on different GPUs. Tokens' hidden states are dispatched to their selected experts, then the expert outputs return for combination.
Scroll horizontally to inspect the diagram.
A constructed top-1 routing example: four GPUs, two experts each, and sixteen token activations. Select dispatch, compute, or return. A top-k router can send multiple copies and requires weighted combination.
Dispatch and return commonly use all-to-all communication. If routing is uneven, one GPU may receive much more work than another. Expert replication and placement can help balance execution while preserving the model's calculation; changing routing decisions or dropping tokens changes the computation and needs separate justification.
An expert need not occupy an entire GPU. A GPU can hold several experts, and a large expert can itself use tensor parallelism.
Combine axes around the hardware
A TP=4, PP=2 layout uses eight GPUs: two pipeline stages, each containing a four-GPU tensor-parallel group. Tensor-parallel communication stays within each group; pipeline activations cross between stages.
70B-shaped example: TP 4 × PP 2 = 8 GPUs
Pipeline stage 0: layers 0–39
GPU 0
TP rank 0
Example output columns 0–2047
GPU 1
TP rank 1
Example output columns 2048–4095
GPU 2
TP rank 2
Example output columns 4096–6143
GPU 3
TP rank 3
Example output columns 6144–8191
↓ Activations pass to stage 1; communication stays within each TP group during a stage.
Pipeline stage 1: layers 40–79
GPU 4
TP rank 0
Example output columns 0–2047
GPU 5
TP rank 1
Example output columns 2048–4095
GPU 6
TP rank 2
Example output columns 4096–6143
GPU 7
TP rank 3
Example output columns 6144–8191
Column ranges describe one projection with 8,192 output coordinates. Other projections use different dimensions or row partitions; some tensors remain replicated.
For an assumed 140 GB raw weight payload, ideal eight-way sharding averages 17.5 GB per GPU. Actual stage footprints require the checkpoint and runtime allocation plan.
For 140 GB of raw 16-bit weights, perfect eight-way sharding would average 17.5 GB per GPU. Real placement also includes replicated tensors, stage imbalance, communication buffers, and KV entries. An eight-GPU capacity sum alone cannot prove that every individual GPU fits.
Fast intra-node links often make tensor parallelism attractive within a node. Pipeline parallelism communicates at fewer boundaries and can be useful across nodes, depending on message size, latency, topology, batch size, and overlap. H100's advertised 900 GB/s NVLink figure is aggregate bidirectional bandwidth, not an effective one-way rate for every collective.
Tensor parallel: 160 events
Two forward all-reduces per block in the stated Megatron-style layout.
Pipeline parallel: 3 events
Four stages; one activation handoff after layers 20, 40, and 60.
Expert parallel: 80 events
Every other block is MoE, starting with the first: dispatch and return.
Common bar scale: 0–160 events. These are alternative communication patterns, not equal-sized messages. No bytes, duration, or bottleneck ranking is implied. Pipeline feedback of the next sampled token is additional.
For a ring all-reduce over ranks and a payload of bytes per rank, the standard bandwidth model sends roughly bytes per rank. Expert dispatch volume also depends on top-k and how many assignments stay local.
Serving replicas are another option
If a model fits on one GPU and one-request latency is acceptable, several independent replicas can increase aggregate throughput without model-parallel communication between them. This is serving data parallelism: replicas process different requests and do not synchronize gradients.
A larger tensor-parallel group is not equivalent to more replicas. It spends more devices on each model execution. Benchmark both layouts under the intended request distribution before choosing.
A concrete launch shape
The following are alternative vLLM server launches for the same checkpoint. They require compatible GPUs with enough memory, access to the model, and an installed vLLM version supporting the selected architecture and backend.
# Four tensor-parallel ranks in one pipeline stage.
vllm serve meta-llama/Llama-3.1-70B-Instruct \
--tensor-parallel-size 4 --pipeline-parallel-size 1
# Alternative: two stages, with two tensor-parallel ranks per stage.
# Stop the first server before launching this configuration.
vllm serve meta-llama/Llama-3.1-70B-Instruct \
--tensor-parallel-size 2 --pipeline-parallel-size 2A multi-node deployment also needs a configured distributed executor, networking, and model availability on its workers.
The next post connects those choices to the throughput and latency tradeoff.
Additional reading
- Megatron-LM, Shoeybi et al. Column/row tensor partitions and communication placement.
- GPipe, Huang et al. Pipeline microbatching; its training schedule should not be confused with the forward-only illustration here.
- vLLM distributed serving. Tensor and pipeline launch configuration.
- NVIDIA NCCL collective operations. All-reduce, all-gather, and related operations.
- NVIDIA H100 specifications. Hardware bandwidth definitions.