Tensor Parallelism (TP)

Definition

Tensor parallelism (Megatron-LM, Shoeybi et al., arXiv:1909.08053) is intra-layer model parallelism: it partitions the weight matrix of a single GEMM across GPUs so each holds a slice, computes a partial result, and the group combines them with one all-reduce per block. Unlike ZeRO/FSDP (which shard state but every GPU runs the same compute), TP splits the computation itself — putting a collective on the critical path inside each layer.

Key math / How it works

For with , two ways to split:

  • Column-parallel: , each GPU computes (owns output columns; replicated; no comms to produce ).
  • Row-parallel: with input split to match; each GPU computes a partial sum , and → all-reduce.

The column→row pairing (the key trick). The MLP block makes column-parallel, row-parallel. The column-split first GEMM leaves the intermediate sharded along the dimension — exactly the layout the row-parallel second GEMM consumes. GeLU is elementwise, so commutes with the sharding and applies locally with no comms. Only the final output is a partial sum → one all-reduce. Swapping the order (row-first) would force an all-reduce before the nonlinearity (to form the correct pre-activation) plus one after — two collectives.

Megatron formalizes this with conjugate operators: (identity fwd / all-reduce bwd) and (all-reduce fwd / identity bwd). Per transformer layer: 2 all-reduces forward + 2 backward (one per block, MLP and attention).

Attention is parallel over heads. Q/K/V projections are column-parallel (each GPU gets whole heads), per-head attention+softmax runs locally (FlashAttention composes cleanly), the output projection is row-parallel closing with the all-reduce. Constraints: num_attention_heads and hidden_size must be divisible by .

Comms cost. Each all-reduce is over a activation tensor. Per layer (bf16, ring all-reduce, 4 collectives):

This is exposed on every layer’s critical path with no compute to hide it, and roughly independent of for large . Example (, , ): ~896 MB/GPU/layer → ~1.0 ms over NVLink (900 GB/s) but ~18 ms over IB (50 GB/s).

TP does not scale across nodes. Keep (one NVLink island). Crossing the node boundary onto ~18×-slower InfiniBand tanks throughput.

Why it matters

TP shards both parameter and activation memory and keeps GEMMs large, but its bandwidth appetite pins it inside a node. It is the innermost, chattiest axis of N-D parallelism, almost always paired with sequence parallelism for free activation savings. Notably DeepSeek-V3 dropped TP entirely on bandwidth-limited H800 NVLink, leaning on EP+PP+FP8 instead.

Taught in

See also