How Tensor Parallelism Works: Splitting Large Models Across GPUs
- Author
- Prathamesh Patil
- Length
- 2577 words
- Read
- 12 min
Key takeaways
Tensor parallelism partitions individual tensors (weights, activations, and often optimizer state) across GPUs, unlike pipeline parallelism which partitions whole layers or stage groups.
Amazon SageMaker's model parallel library applies tensor parallelism at the level of selected
nn.Modules (for examplenn.Linear), and handles the collective communication those shards need.Each data-parallel rank may hold only a partition of the distributed modules, plus the full copy of modules that are not tensor-sharded.
Azure Foundry Local / vLLM-style inference uses the same idea: each GPU processes the same request on its weight shard and workers communicate to combine partial results.
Failure blast radius is local to a tensor-parallel group for shard loss, but a stuck collective (all-reduce / all-gather) stalls the whole group.
Trade-offs: lower per-GPU memory for huge layers, at the cost of interconnect traffic and more complex module partitioning.
Research basis
This article is grounded in public materials.
Documented: Tensor parallelism takes place at the level of
nn.Modules; it partitions specific modules in the model across tensor parallel ranks, in addition to pipeline-parallel module partitions. — sourceDocumented: When a module is partitioned through tensor parallelism, its forward and backward propagation are distributed; the library handles the necessary communication across devices. — source
Documented: Contrary to traditional data parallelism, each data parallel rank does not hold a complete model replica when tensor parallelism is used — it may hold only a partition of the distributed modules. — source
Documented: For a partitioned
nn.Linear, each tensor-parallel rank holds a fraction of the module, collects the relevant parts of data samples from peers in the tensor parallel group, runs the local fraction, then reduce-scatters so each rank gets the final linear output for its own samples. — sourceDocumented: Tensor parallelism splits individual layers, or
nn.Modules, across devices to be run in parallel; the library manages communication across the tensor-distributed model replicas. — sourceDocumented: In contrast to pipeline parallelism (which keeps individual weights intact but partitions the set of layers), tensor parallelism shards specific model weights, gradients, and optimizer states across devices. — source
Documented: In Foundry Local multi-GPU inference, tensor parallelism partitions model weights across GPUs; each GPU processes the same request using its weight shard, and workers communicate to combine partial results. Pipeline parallelism assigns different layer groups to GPUs and passes activations stage to stage. — source
Documented: Required GPUs per replica equals
tensor_parallel_size * pipeline_parallel_size; all GPUs for one replica must sit on the same cluster node. — source
Materials consulted:
How Tensor Parallelism Works - Amazon SageMaker AI
Introduction to Model Parallelism - Amazon SageMaker AI
Tensor parallelism - Amazon SageMaker AI (SMP v2)
Model parallelism concepts - Amazon SageMaker AI
Model parallelism for multi-GPU inference in Foundry Local on Azure Local | Microsoft Learn
Where the sources are silent, claims are labeled as inference or omitted.
Opening problem
A modern transformer layer can contain a single nn.Linear whose weight matrix does not fit in one GPU's memory once you also reserve room for activations, gradients, and optimizer state. Data parallelism alone does not help: every rank still keeps a full replica of that layer. Pipeline parallelism helps for depth (different layers on different devices) but leaves each wide layer intact on one device. Tensor parallelism is the technique public training and inference stacks use when the bottleneck is the width of a layer.
Why data parallelism alone fails for huge layers
Full replica cost: Classic data parallelism keeps a complete copy of every module on each GPU. Memory still scales with the largest layer, not with the number of GPUs.
Optimizer state: Adam-style optimizers roughly double or triple the parameter footprint. Without sharding that state, you hit OOM even when forward weights alone might fit.
Pipeline is a different cut: Pipeline parallelism partitions the set of layers. A single giant
nn.Linearremains whole on one stage GPU.Inference mirrors training: Serving a large model with vLLM-style engines hits the same wall — one request still needs every shard of a wide weight matrix unless you tensor-parallel.
Core insight
Tensor parallelism cuts inside selected modules. SageMaker's library partitions supported nn.Modules across a tensor parallel group (TP_GROUP) nested inside the data parallel group. Peers exchange activations and gradients with collectives (collect samples → run local shard → reduce-scatter / all-gather) so mathematically the layer still computes the same result as a single-GPU module, while memory for that module's weights (and often its gradients and optimizer state) is split.
Module partition topology across tensor parallel ranks
In SageMaker's worked example, a module tree is partitioned so that modules like B and G become B:0 / B:1 and G:0 / G:1 on alternating data-parallel ranks that form a TP_GROUP. Modules that are not selected for tensor parallelism stay whole on every rank in that group. Child modules under a partitioned parent are absorbed into the parent's partitioned execution. Whether a supported module is actually partitioned is a user choice — support does not imply automatic sharding.
A concrete mental model for degree-2 tensor parallelism with data parallelism:
| Rank role | What it stores for a partitioned nn.Linear |
What it stores for an unpartitioned module |
|---|---|---|
dp_rank 0 (tp_rank 0) |
Shard 0 of the linear weights | Full module |
dp_rank 1 (tp_rank 1) |
Shard 1 of the linear weights | Full module |
dp_rank 2 (tp_rank 0) |
Same shard layout as dp_rank 0 (TP pattern repeats) |
Full module |
dp_rank 3 (tp_rank 1) |
Same shard layout as dp_rank 1 |
Full module |
The important systems property: the exact model partition is replicated across matching tensor-parallel slots in different data-parallel groups, so data-parallel gradient sync still has a coherent partner.
Forward and backward path through a partitioned Linear
SageMaker documents the nn.Linear adaptation in two pictures worth internalizing:
Small model, large linear, data-parallel only: the full
nn.Linearis replicated on each tensor-parallel rank — no memory win on that module.Tensor parallelism on a larger model: each
tp_rankholds half the linear module and the entirety of the non-partitioned ops. During the linear, each rank collects the relevant half of all data samples in the TP group, runs its half of the module, then reduce-scatters (summation) so each rank ends with the final linear output for its own samples. The rest of the model continues in ordinary data-parallel fashion.
That collect → local matmul → reduce-scatter loop is the request path of training for a sharded layer. Inference engines that expose tensor_parallel_size run an analogous shard-and-combine path per decode step.
Failure domains and blast radius
Name the parts whose failure changes the outcome:
| Domain | What fails | Blast radius | Reconstructability |
|---|---|---|---|
| Single GPU in a TP group | HBM error, process crash | Whole TP group stalls on the next collective; that replica cannot finish the step | Need restart or elastic recovery of the group; partial shard state alone is not a usable model |
| Interconnect inside the node | NVLink / PCIe fabric congestion or drop | Collectives hang or time out; forward/backward cannot complete | In-flight activations/gradients for the step are lost |
| Data-parallel peer set | One DP replica dies | Other DP groups may continue until global sync; gradient all-reduce across DP fails | Depends on checkpoint cadence — last synced checkpoint is the recovery point |
| Job / library control plane | Scheduler or SMP transform misconfig | Job fails validation or never launches (Foundry Local rejects GPU counts below TP * PP) |
No training progress; fix config and relaunch |
| Checkpoint / decision log | Missing HF-compatible state_dict after SMP transform |
Cannot resume or fine-tune from the transformed checkpoint without SMP save/load APIs | Public docs warn the transformed state dict is incompatible with stock Hugging Face checkpointing unless you use the library helpers |
Inference-specific constraint from Azure Foundry Local: all GPUs for one replica must be on the same cluster node. A multi-node split is a different deployment problem; if the node lacks tensor_parallel_size * pipeline_parallel_size GPUs, the pod stays Pending rather than silently falling back.
Combining tensor and pipeline parallelism
Public stacks treat TP and PP as orthogonal knobs:
Tensor parallelism (TP): partition weights of selected layers across GPUs; same request / same microbatch touches every TP rank; workers communicate to combine partial results.
Pipeline parallelism (PP): assign different layer groups to different GPUs; activations flow stage to stage.
Combined: each pipeline stage owns a tensor-parallel group. GPU count per replica is the product of the two degrees.
SageMaker expresses this with tensor_parallel_degree, pipeline_parallel_degree, and data-parallel degree derived from processes per host. Foundry Local / vLLM preferences use tensor_parallel_size and pipeline_parallel_size with the same product rule for resources.limits.gpu.
Use TP when a single layer is too wide for one GPU and the interconnect can absorb the collectives. Prefer PP when layer-based partitioning fits the hardware better or TP communication is too costly for the model. Combine when the model and topology support both.
Data movement: activations, gradients, and optimizer shards
Data moves pull-style relative to each collective:
Parameter shards live on each tensor-parallel rank for partitioned modules; unpartitioned modules keep full weights and behave like ordinary data parallel replicas.
Activation traffic gathers the pieces of the mini-batch each rank needs before the local shard runs.
Output traffic reduce-scatters (or all-gathers, depending on the op) so each rank holds the outputs it owns for the next unsharded ops.
Gradient traffic mirrors the forward communication pattern in reverse during backward.
Optimizer state for partitioned modules is split with the parameters in SMP-style tensor parallelism, so you do not keep a full Adam copy of a huge linear on every GPU.
There is no global edge cache in this design — the “store” is GPU HBM plus whatever activation checkpointing / offloading the library enables. SageMaker separately documents activation checkpointing and CPU offload as memory levers that recompute or page activations rather than keep every intermediate on device.
Tradeoffs
| Decision | Benefit | Cost |
|---|---|---|
Shard wide nn.Linear / attention projections |
Fits models that exceed one GPU | Collective latency on every sharded forward/backward |
Nested TP_GROUP inside DP_GROUP |
Keeps data-parallel replicas coherent | Partition layout must be understood when debugging OOMs |
| Select only some modules for TP | Tune where memory pressure is worst | Wrong selection leaves the true hotspot unreplicated and still OOM |
| Combine TP with PP | Scales both width and depth | Product GPU count; topology must match the model |
| Same-node TP for inference | NVLink-class bandwidth for combines | Cannot spread one replica across nodes in Foundry Local's documented model |
| Library-managed collectives | Correct distributed math without hand-written NCCL | Transformed checkpoints need library save/load paths |
Data-store tradeoffs inside a TP job are really where activations and optimizer state live: keep them in GPU HBM for speed, checkpoint/recompute them to save HBM, or offload them to host memory (SageMaker activation offloading) at the cost of PCIe traffic. That is the same capacity-vs-latency tension you see in KV vs Durable Objects style edge stores — pick the store that matches the access pattern, not the largest one.
The design favors memory headroom and correct layer math over minimizing interconnect. If your interconnect is weak, public guidance is to lower TP degree or lean on pipeline / sharded data parallelism instead of forcing a huge TP group.
What I would steal from this design
If I were building a training or serving stack tomorrow, I would steal three ideas from the public SageMaker / Foundry Local write-ups — not the product names, the cuts:
Cut width and depth with different knobs. Keep tensor parallelism for layers that do not fit, pipeline parallelism for depth, and do not pretend one axis solves both. The product rule for GPUs per replica makes capacity planning boring in a good way.
Make sharding selective. Only partition modules that need it; leave the rest as ordinary data-parallel replicas. That avoids paying collective cost on every tiny op.
Treat checkpoint format as part of the architecture. Once a transform rewrites
state_dict, stock HF save/load is a footgun. I would design the save path on day one the way SMP documents — not as an afterthought when fine-tuning breaks.
I would not steal “max out TP degree.” Public docs are clear that interconnect quality bounds how far TP is worth pushing; past that, pipeline or sharded data parallelism is the better lever.
FAQ
Is tensor parallelism the same as model parallelism?
Model parallelism is the umbrella. Tensor parallelism is the intra-layer form; pipeline parallelism is the inter-layer form. SageMaker and Azure docs treat them as complementary.
Does SageMaker shard every module automatically?
No. The library supports tensor parallelism for certain nn.Modules, but whether a module is partitioned depends on user configuration. Unsupported or unselected modules stay whole and run in ordinary data-parallel fashion.
What happens to child modules under a partitioned parent?
In the SageMaker example, children of a partitioned parent are no longer separate modules in the tree — their work runs inside the partitioned parent.
How many GPUs do I need for TP=2 and PP=2?
Four GPUs per replica (2 * 2), and for Foundry Local those four must be schedulable on one node.
Can I fine-tune from an SMP-transformed Hugging Face checkpoint with stock APIs?
Not directly — SMP changes the state_dict. Use the library's checkpoint APIs / torch.sagemaker.transform load path documented for fine-tuning.
Performance posture (what public docs actually say)
Public write-ups emphasize qualitative levers, not a single universal latency number:
High-bandwidth interconnects such as NVLink reduce TP communication overhead (Azure Foundry Local).
Combining TP with PP changes latency and throughput in a workload-dependent way — model, interconnect, and batching dominate.
SageMaker points to SMDDP collectives (for example improved AllGather on A100-class instances) when pairing sharded data parallelism with other techniques; treat exact speedups as hardware- and version-specific, not portable SLOs.
Activation checkpointing / offload trade compute or host memory for GPU HBM; they are orthogonal knobs to TP.
Avoid treating marketing throughput figures as architecture invariants. Measure collectives and memory on your instance type.
Sources
Image credits
- Cover: AI-generated illustration