LLM Tensor Parallelism: Split Large Models Across GPUs

LLM Tensor Parallelism: Split Large Models Across GPUs

What happens when a language model is simply too big to fit on one graphics card? That is not a hypothetical question anymore. Modern large language models can carry hundreds of billions of parameters, and no single GPU has enough memory to hold them. The answer most engineering teams reach for is tensor parallelism, a technique that slices individual weight matrices across several GPUs so they work together on the same layer. It sounds elegant on paper. In practice, it is a careful trade between memory, speed, and network bandwidth. This article explains how it works, where it helps, where it hurts, and what teams commonly get wrong when they deploy it.

What tensor parallelism actually means

Tensor parallelism is a model-parallel strategy that divides a single tensor, such as a weight matrix inside a neural network layer, into pieces that live on different devices. Each device computes part of the operation, and the results are combined so the final output matches what a single large device would have produced.

This is different from data parallelism, where every GPU holds a full copy of the model and processes a different batch of data. It is also different from pipeline parallelism, where different layers of the model sit on different devices and data flows through them in stages. Tensor parallelism cuts horizontally through a layer. Pipeline parallelism cuts vertically between layers.

The distinction matters because each approach stresses the hardware differently. Data parallelism needs fast gradient synchronization but keeps computation local. Pipeline parallelism reduces memory per device but introduces idle time, often called pipeline bubbles. Tensor parallelism reduces memory per device but requires frequent communication inside every layer, which makes interconnect speed the deciding factor.

The Megatron-LM design that started it all

The Megatron-LM design that started it all

The scheme most teams use today traces back to a 2019 paper from NVIDIA researchers, “Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism,” which laid out a clean way to split Transformer layers with minimal communication. You can read the original Megatron-LM tensor parallelism paper on arXiv for the full derivation.

The core insight is clever. In a Transformer’s multi-layer perceptron block, the first weight matrix is split column-wise across GPUs, and the second is split row-wise. Because of that arrangement, each GPU can compute its portion independently, and only a single all-reduce is needed to combine the partial results. The same trick applies to the self-attention block, where the query, key, and value projections are split by attention head.

The payoff is that a Transformer layer needs just two all-reduce operations per pass, one in the forward direction and one in the backward direction. That is remarkably efficient for how much memory it saves. The cost is that those all-reduces sit right in the middle of the hot path, so they happen constantly during training and inference.

Why the network becomes the bottleneck

Every all-reduce forces GPUs to exchange data and wait for each other. If that exchange is slow, the GPUs sit idle, and adding more of them makes things worse rather than better. This is why tensor parallelism is typically kept inside a single server, where GPUs talk over high-speed links like NVLink rather than across a slower network between machines.

Treat that as a strong rule of thumb rather than an absolute law. Some setups do run tensor parallelism across nodes, but the performance penalty is usually severe unless the interconnect is unusually fast. The practical guidance is straightforward: scale tensor parallelism up to the number of GPUs in one node, then reach for other techniques to go further.

This is also where a lot of real-world frustration comes from. A team buys eight GPUs, sets tensor parallelism to eight, and expects a smooth speedup. Instead they find that communication overhead eats a chunk of the gain, especially at small batch sizes where there is less computation to hide the latency behind. The fix is rarely more GPUs. It is usually a better balance across parallelism dimensions.

Combining tensor, pipeline, and data parallelism

No single technique scales to the largest models alone. The standard approach stacks them into what the field calls 3D parallelism. Tensor parallelism handles intra-layer splitting within a node, pipeline parallelism spreads layers across nodes, and data parallelism replicates the whole arrangement to process more training examples at once.

NVIDIA’s 2021 follow-up work, “Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LM,” described this combination and reported training models up to one trillion parameters. The Megatron-LM 3D parallelism study is worth reading if you want to see how the dimensions interact and why the balance point shifts with model size and cluster shape.

A simple way to think about the division of labor:

Technique What it splits Main cost Best fit
Data parallelism The batch Gradient sync Small to medium models
Pipeline parallelism Layers across devices Idle bubbles Deep models across nodes
Tensor parallelism Weight matrices within a layer All-reduce traffic Large layers within a node

Getting the mix right is more art than formula. A model with very wide layers benefits more from tensor parallelism. A model with many layers but narrow ones may prefer pipeline parallelism. Teams that ignore this and default to one dimension often leave significant performance on the table.

The memory problem tensor parallelism does not solve

Here is a subtle trap. Tensor parallelism shrinks the weight matrices on each GPU, but it does not automatically shrink activation memory, the intermediate tensors saved during the forward pass for use in the backward pass. In some configurations, activations can dominate memory use, which means splitting weights alone will not free enough room.

Sequence parallelism addresses this by sharding the activations along the sequence dimension in the regions outside the tensor-parallel compute. The 2022 paper “Reducing Activation Recomputation in Large Transformer Models” documented how this cuts activation memory and reduces the need to recompute activations to save space. The sequence parallelism activation memory research explains the technique in detail and is a useful companion to any tensor-parallel implementation.

In practice, teams that skip this step often hit out-of-memory errors even after splitting weights across many GPUs. They then assume tensor parallelism is broken, when the real issue is that activations were never sharded at all. Checking activation memory before blaming the parallel strategy saves hours of debugging.

Tensor parallelism for inference and training

Most discussion of tensor parallelism focuses on training, but it matters just as much for serving models. A model that trains fine on a cluster still has to answer user requests, and inference has different constraints. Latency matters more than throughput in many cases, and batch sizes are often small.

Serving frameworks expose tensor parallelism as a configuration option. For example, vLLM lets operators set a tensor-parallel size so a single model is spread across multiple GPUs during serving. The vLLM distributed serving documentation walks through how to configure it and what to expect.

A few practical notes from common deployment experience:

  • Match the tensor-parallel size to the number of GPUs within one node, not beyond it, unless you have verified fast inter-node links.

  • Test with realistic batch sizes, because small batches expose communication latency that large batches hide.

  • Watch for load imbalance when the number of attention heads does not divide evenly across GPUs.

  • Measure end-to-end latency in addition to tokens per second, since users feel the former.

That last point trips up a lot of teams. A configuration can post impressive aggregate throughput while individual requests feel sluggish, because the all-reduce waits add up per token.

Where the field is heading

The tooling around tensor parallelism is maturing quickly. PyTorch now offers DTensor, a first-class API for expressing sharded tensors, which lets developers describe how a tensor is split and let the runtime handle the communication. The PyTorch DTensor documentation covers the API and how it fits into distributed training.

This matters because hand-rolled tensor parallelism is error-prone. Getting the sharding right, keeping the collective operations in sync, and handling edge cases takes real effort. Framework-level abstractions lower that barrier and make it easier to change strategies as models and hardware evolve.

At the same time, hardware is shifting the calculus. Faster interconnects and larger memory per GPU change where the balance point sits. Techniques that were impractical a few years ago become routine. Teams that track these shifts, and revisit their parallelism settings periodically, tend to get more out of the same hardware budget.

For readers following the broader infrastructure conversation, the cloud section on 9481.org covers related topics in distributed computing and deployment, and the news category tracks developments across the AI infrastructure landscape.

Common mistakes and what actually works

A few patterns show up again and again when teams first adopt tensor parallelism.

The first is over-splitting. More GPUs does not automatically mean faster. Past a certain point, communication overhead dominates and adding devices slows things down. The right number is the one where computation still outweighs communication, and that number is often smaller than people expect.

The second is ignoring the interconnect. Tensor parallelism lives or dies on how fast GPUs can exchange data. A cluster with slow links between nodes will struggle no matter how the software is configured. Checking the actual bandwidth before planning a deployment is basic due diligence that gets skipped surprisingly often.

The third is forgetting activations. As noted earlier, splitting weights without addressing activation memory leads to out-of-memory failures that look mysterious. Sequence parallelism and activation checkpointing are the usual remedies.

The fourth is not measuring. Teams sometimes deploy a configuration based on a blog post or a default setting and never benchmark it against alternatives. A short experiment comparing two or three configurations on the actual workload usually reveals a meaningfully better option. (Blog)

What works in practice is a methodical approach: start with the smallest tensor-parallel size that fits the model, measure, then increase only if the numbers justify it. Combine with pipeline and data parallelism as needed. Keep an eye on activation memory throughout. And revisit the setup as models and hardware change, because yesterday’s optimal configuration is not necessarily today’s.

Conclusion

Tensor parallelism is one of the foundational techniques that makes large language models practical. By splitting weight matrices across GPUs and combining results with all-reduce operations, it lets models grow far beyond the memory of any single device. The Megatron-LM lineage showed how to do this with minimal communication, and later work on 3D parallelism and sequence parallelism extended it to trillion-parameter training runs.

But it is not a free lunch. The communication cost inside every layer means tensor parallelism works best within a single node, where GPUs talk over fast links. It pairs with pipeline and data parallelism rather than replacing them. And it does not solve activation memory on its own, which is why sequence parallelism exists.

For teams deploying large models, the practical takeaway is simple. Understand the trade-offs, measure real workloads, and resist the urge to split across more GPUs than the interconnect can support. Done well, tensor parallelism turns an impossible model into a working system. Done carelessly, it turns a fast cluster into an expensive waiting room.

FAQ

What is tensor parallelism in simple terms?

Tensor parallelism is a way to split a large model’s weight matrices across multiple GPUs so they share the work of a single layer. Each GPU computes part of the math, and the results are combined so the output matches what one big GPU would have produced.

Is tensor parallelism the same as data parallelism?

No. Data parallelism gives every GPU a full copy of the model and a different batch of data. Tensor parallelism splits the model itself, so each GPU holds only a slice of the weights. They are often used together in large training setups.

Why is tensor parallelism usually kept within one node?

Because it requires frequent all-reduce communication inside every layer. When GPUs sit in the same server, they can exchange data over fast links like NVLink. Across nodes, slower connections make the communication overhead dominate, so performance drops.

Does tensor parallelism reduce memory enough on its own?

Not always. It shrinks weight matrices but does not automatically shrink activation memory, the intermediate tensors saved during training. Techniques like sequence parallelism are often needed to shard activations and avoid out-of-memory errors.

Can tensor parallelism be used for inference?

Yes. Serving frameworks let operators set a tensor-parallel size so a model spreads across several GPUs during inference. The trade-offs differ from training, since latency and small batch sizes expose communication overhead more sharply.

How do I choose a tensor-parallel size?

Start with the smallest size that fits the model in memory, then benchmark real workloads. Increase only if measurements show a gain. Match the size to GPUs within one node, and check that attention heads divide evenly to avoid load imbalance.

Latest articles

Scroll to Top