Tensor Parallelism

Tensor Parallelism is a model-parallel training and inference strategy in which individual weight tensors (typically large matrix multiplications) are partitioned across multiple devices, allowing each device to compute a shard of every layer rather than a disjoint subset of layers. It is foundational to training trillion-parameter models that cannot fit on a single accelerator, and it operates orthogonally to both data parallelism and pipeline parallelism, enabling multi-dimensional parallelism hierarchies. A counterintuitive fact: tensor parallelism deliberately increases total floating-point operations (by requiring all-reduce collectives), yet consistently achieves near-linear throughput scaling because communication and computation can be perfectly overlapped on modern interconnects.

💡 The Core Insight

The key insight is that a matrix multiplication Y=XWY = XW can be split along either the column or row dimension of WW such that each device computes a partial result, and these partial results can be recombined with a single collective communication — meaning the algebraic structure of matrix multiplication naturally tolerates partitioning. The "aha moment" is recognizing that this is not an approximation: the mathematics is exact, and the only overhead is the all-reduce at partition boundaries, not any approximation error. This makes tensor parallelism fundamentally different from model compression — it is exact arithmetic distributed across hardware.

⚠️ Common Misconception

The most common mistake is confusing tensor parallelism with pipeline parallelism: practitioners often assume that splitting a model means assigning different layers to different devices (pipeline parallelism), and then mistakenly describe this as "tensor parallelism." The correct mental model is that in tensor parallelism, every device participates in every layer, each holding a column- or row-shard of every weight matrix, whereas pipeline parallelism assigns disjoint layer ranges to devices. This confusion leads to serious bugs in framework configuration (e.g., setting `tensor_model_parallel_size` vs. `pipeline_model_parallel_size` in Megatron-LM) and to incorrect performance models because pipeline parallelism introduces bubble overhead while tensor parallelism introduces all-reduce latency — two qualitatively different bottlenecks requiring different mitigation strategies.

How It Works

Column-Parallel and Row-Parallel Linear Layers

The fundamental decomposition follows from the block-matrix identity for matrix products. Consider a linear layer with weight W∈Rd×hW \in \mathbb{R}^{d \times h} and input X∈Rb×dX \in \mathbb{R}^{b \times d}, where bb is batch size, dd is input dimension, and hh is output dimension. Partition WW column-wise across PP devices:

1
W=[W1∣W2∣⋯∣WP],Wi∈Rd×(h/P)\quad W = \begin{bmatrix} W_1 \mid W_2 \mid \cdots \mid W_P \end{bmatrix}, \quad W_i \in \mathbb{R}^{d \times (h/P)}

Explanation: Each device ii holds exactly 1/P1/P of the output neurons, enabling all devices to simultaneously compute partial outputs from the full input without any prior communication. Each device ii independently computes:

2
Yi=XWi,Yi∈Rb×(h/P)\quad Y_i = X W_i, \quad Y_i \in \mathbb{R}^{b \times (h/P)}

Explanation: This local computation is embarrassingly parallel — no inter-device communication is needed before the activation function if the activation is elementwise. For a row-parallel layer (e.g., the second linear in an MLP), partition WW row-wise and XX column-wise (the output of the previous column-parallel layer):

3
Y=∑i=1PXiWi(row),where Xi∈Rb×(h/P), Wi(row)∈R(h/P)×h′\quad Y = \sum_{i=1}^{P} X_i W_i^{(\text{row})}, \quad \text{where } X_i \in \mathbb{R}^{b \times (h/P)},\ W_i^{(\text{row})} \in \mathbb{R}^{(h/P) \times h'}

Explanation: The full output Y∈Rb×h′Y \in \mathbb{R}^{b \times h'} is the sum of PP rank-(h/P)(h/P) outer products, recovered exactly by an all-reduce collective Y=AllReduce({Yi})Y = \text{AllReduce}(\{Y_i\}).

Communication Complexity

For a tensor-parallel degree PP, a forward pass through one transformer block requires exactly 2 all-reduce operations (one after the attention projection and one after the second MLP linear). The communication volume per all-reduce is:

4
Call-reduce=2⋅P−1P⋅b⋅s⋅h⋅sizeof(dtype)\quad \mathcal{C}_{\text{all-reduce}} = 2 \cdot \frac{P-1}{P} \cdot b \cdot s \cdot h \cdot \text{sizeof}(\text{dtype})

Explanation: The factor 2(P−1)/P2(P-1)/P arises from the ring-all-reduce algorithm, which requires 2(P−1)2(P-1) point-to-point messages each of size bsh/Pbsh/P, converging to 2bsh2bsh bytes asymptotically for large PP — independent of PP in the large-PP limit. Here ss is sequence length and hh is hidden dimension.

Attention Head Parallelism

Multi-head attention with HH heads decomposes naturally: assign H/PH/P heads per device. The per-device query, key, and value projections are:

5
Qi=XWQ(i),Ki=XWK(i),Vi=XWV(i),i=1,…,P\quad Q_i = X W_Q^{(i)},\quad K_i = X W_K^{(i)},\quad V_i = X W_V^{(i)}, \quad i=1,\ldots,P

Explanation: Because each attention head operates independently before the output projection, the multi-head split is a special case of column parallelism where HH must be divisible by PP, and the output projection becomes a row-parallel layer requiring a single all-reduce.

Backward Pass

The gradient flow is dual: the backward pass through a column-parallel layer requires an all-gather (to reconstruct the full gradient w.r.t. XX), and the backward pass through a row-parallel layer requires a reduce-scatter. In practice, these collapse to the same all-reduce pattern as the forward pass when combined in the standard column–row layout, so the total collective count per transformer block is 4 (2 forward + 2 backward).

researcher · Shoeybi, Mohammad | b. ~1985 | Megatron-LM Tensor Parallelism

Mohammad Shoeybi is a principal research scientist at NVIDIA whose work on large-scale language model training systems has shaped the infrastructure behind many of the largest models in existence. In the landmark 2019 paper Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism, Shoeybi and colleagues formalized the column-parallel/row-parallel decomposition described here and demonstrated 8-way tensor parallelism on 72 GPUs with 76% scaling efficiency for an 8.3B parameter GPT-2 variant. A surprising historical detail: the Megatron-LM codebase was initially an internal NVIDIA project and was released open-source almost as an afterthought, yet it became the de facto reference implementation that most academic and industrial large-model efforts forked from.

Figure
Tensor Parallelism: Column-Parallel and Row-Parallel Layer Decomposition
Tensor Parallelism: Column-Parallel → Row-Parallel (2-device example) X b × d Input W₁ d×h/P W₂ d×h/P Column-∥ Y₁ b×h/P Y₂ b×h/P σ(Yᵢ) local V₁ h/P×h' V₂ h/P×h' Row-∥ All- Reduce ΣZᵢ 1 collective Y b × h' Output GPU 0 holds W₁,V₁ — GPU 1 holds W₂,V₂ (each computes full fwd/bwd pass on its shard) Weight shard Activation / tensor Collective communication 2 all-reduces / transformer block (fwd) · 2 all-reduces (bwd) · O(bsh) bytes each
Figure
Megatron-Style Transformer Block with Tensor Parallelism
Megatron-LM Transformer Block — Tensor Parallel (P devices) Input X LayerNorm QKV Col-∥ H/P heads per device Attn Local softmax over H/P heads Out Row-∥ W_O shard row-wise AllReduce① LayerNorm FC₁ Col-∥ 4h/P neurons per device GeLU(·) FC₂ Row-∥ h×4h/P shard row-wise AllReduce② Output + Res. Partitioned weight (Col or Row) AllReduce collective Total: 4 collectives/block (fwd+bwd)

Intuition

🧠 The Mental Model

Imagine a very long arithmetic exam with 1000 problems. One approach (pipeline parallelism) is to divide the exam booklet into sections and assign different sections to different students — student A does problems 1–250, student B does 251–500, etc. But tensor parallelism is different: every student works on every problem simultaneously, except each student only computes a fraction of each answer. For a multiplication like 1234×56781234 \times 5678, you could assign each student a subset of the partial products (the columns of the long multiplication grid), and then everyone shouts out their partial sums at the end, which a coordinator adds up in one step. The coordinator step is the all-reduce — fast, exact, and required only once per problem. The insight is that matrix multiplication is naturally decomposable this way: the column structure of the weight matrix means each shard is completely self-contained until the very last addition. This is why modern interconnects like NVLink (with 900 GB/s bandwidth) make tensor parallelism so efficient: the "shouting" step is extremely fast relative to the computation itself, especially for the large batch sizes and hidden dimensions characteristic of large language models.

Historical Development

⏳ History
1988
Systolic array literature (Kung & Leiserson) establishes that matrix operations decompose naturally across processing elements — the theoretical foundation for distributed tensor computation.
2014
Jeff Dean et al. (DistBelief, Google) demonstrates parameter-server-based model parallelism for neural networks, though with a centralized bottleneck rather than collective communication.
2016
Mesh-TensorFlow (Shazeer et al., 2018, but prototyped internally ~2016) begins exploring named-dimension parallelism in TPU pods, treating any tensor axis as a parallelism axis.
2018
Mesh-TensorFlow (Shazeer et al., NeurIPS 2018) formalizes the concept of SPMD-style tensor parallelism, introducing the idea that any tensor dimension can be sharded across a device mesh.
2019
Shoeybi et al. (Megatron-LM, arXiv:1909.08053) introduce the practical column-parallel/row-parallel formulation for transformer blocks with NVIDIA collective communication, achieving 8-way tensor parallelism with 76% efficiency on 8.3B parameter models.
2021
Narayanan et al. (Efficient Large-Scale Language Model Training, SC'21) combine tensor, pipeline, and data parallelism (3D parallelism) in Megatron-LM v2, training 530B parameter models (Megatron-Turing NLG) on 2240 A100 GPUs.
2022
Alpa (Zheng et al., OSDI 2022) automates the search over intra-operator (tensor) and inter-operator (pipeline) parallelism strategies, demonstrating that manual sharding decisions can be replaced by an ILP-based compiler pass.
2023
FlexFlow Serve and tensor-parallel inference frameworks (e.g., vLLM with TP, TensorRT-LLM) bring tensor parallelism to production inference, where it is used to reduce per