Skip to content

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.

GPU 1: [1, 0, 1, 0]ᵀx · W[:, 1] = 4
GPU 2: [0, 1, 0, 1]ᵀx · W[:, 2] = 6
GPU 3: [1, 1, 0, 0]ᵀx · W[:, 3] = 3
GPU 4: [0, 0, 1, 1]ᵀx · W[:, 4] = 7

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.

slot123456789
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, y=xWy=xW.

If WW is partitioned by output columns, each GPU can receive the same xx and compute a different slice of yy. Those slices concatenate to form the complete output. They are different coordinates, so summing them would be wrong.

If WW is partitioned by input rows, each GPU multiplies the matching slice of xx by its rows of WW. 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.

Switch between column and row partitions to recover the same output from two different sets of partial products.

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.

Time units →
Stage0123456789101112131415
GPU 0allallallall············
GPU 1····allallallall········
GPU 2········allallallall····
GPU 3············allallallall

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.

An ideal forward-only schedule with four equal stages and four units of work. Compare one unsplit batch with four microbatches. Cell occupancy is calculated from the schedule; it is not measured GPU utilization.

If there are PP equally fast stages and MM microbatches, each taking one time unit per stage, a forward pass takes M+P−1M+P-1 units. The idle fraction across that window is

P−1M+P−1.\frac{P-1}{M+P-1}.

With four stages and four microbatches this is 3/73/7, about 43%. Sixteen microbatches reduce it to 3/193/19, 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.

Expert Parallelism — 8 experts across 4 GPUs
1. Dispatch (all-to-all) — tokens fly to the GPU that owns their chosen expert
constructed top-1 routing; one MoE layerGPU 0Expert 0Expert 1home tokensGPU 1Expert 2Expert 3home tokensGPU 2Expert 4Expert 5home tokensGPU 3Expert 6Expert 7home tokens0.00.10.20.31.01.11.21.32.02.12.22.33.03.13.23.3all-to-all collective — 16 / 16 tokens cross GPU boundaries

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.

An illustrative 80-layer layout. Each GPU owns a tensor shard of its stage's layers. The hidden-coordinate ranges illustrate one column-partitioned projection, not the layout of every tensor.

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.

Communication counts for stated layouts across an 80-layer forward pass. Event count is not bytes or time: an all-reduce, a stage handoff, and an expert dispatch have different volumes and algorithms.

For a ring all-reduce over PP ranks and a payload of DD bytes per rank, the standard bandwidth model sends roughly 2(P−1)D/P2(P-1)D/P 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 2

A 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