# Tensor vs Pipeline Parallelism

> How tensor and pipeline parallelism split one large model across GPUs, and which one to use where, for your AI interview.

**In short:** Tensor parallelism splits each layer across GPUs that must swap results after every layer, so it needs a fast link and works best inside one server. Pipeline parallelism gives each GPU a block of whole layers, so it can run across servers, but GPUs wait in turn.

AI and LLM interview question Q329, Inference, performance and cost. Advanced, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/tensor-vs-pipeline-parallelism

## Say it in 30 seconds

Tensor parallelism cuts every layer of the model into slices, one per GPU, so all the GPUs work on each token together. They swap results after every layer, so they need a very fast link and work best inside one server. Pipeline parallelism gives each GPU a run of whole layers. It can cross servers, but one stage works while the others wait. NVIDIA's and vLLM's guides both suggest tensor inside each server and pipeline between servers.

## Say it in 2 minutes

Start with the problem. A large language model is too big for one GPU's memory, so we spread it over several. The two most common ways to cut it up are tensor and pipeline parallelism. Tensor parallelism cuts each layer into slices, and every GPU holds one slice of every layer. Pipeline parallelism cuts the stack of layers into blocks, and each GPU holds one block of whole layers.

Tensor parallelism is fast but chatty. After each layer, the GPUs must combine their partial results before the next layer can start, so they need a very fast link. That is why it works best inside one server, where the GPUs share a fast interconnect. Pipeline parallelism is quieter. Only the output of one stage travels to the next, so it can cross slower links between servers. The cost is idle time: while one stage works, the others wait.

For a real setup, say a claims assistant on a model that won't fit on one 8-GPU server, I would use tensor parallelism inside each server and pipeline parallelism between the two servers. Then I would measure. The right split depends on the link speed, the batch size and the latency target, so I check each of them on real traffic.

## What are tensor and pipeline parallelism, in plain words?

A large language model is a long stack of layers, and each layer holds big tables of numbers called weights. When the weights are too big for one GPU, you split the model across several GPUs. Tensor and pipeline parallelism are the two most common ways to cut the model itself, and they differ in what gets split.

Picture a claims office handling one large insurance file. In the first setup, every clerk works on a slice of every page and passes notes after each page. In the second, each clerk owns one stage, such as intake, review or payout, and the file moves down the line. The first needs the clerks in one room. The second copes with a team spread over several buildings.

Now the real case. A made-up insurer runs a claims assistant on its own model. The model needs more GPU memory than one 8-GPU server holds, so the team has to split it across two servers.

- **Layer:** One step of the network's stack. A large model has many, run one after another.
- **Shard:** One slice of a layer's weights, held by one GPU.
- **Stage:** A run of whole layers, served by one GPU or one group of GPUs.
- **Node:** One server box with several GPUs inside it.
- **Interconnect:** The link GPUs use to pass results, such as NVLink inside a box or InfiniBand between boxes.

## How does tensor parallelism split one layer?

Tensor parallelism cuts each layer's weights into shards, one per GPU. NVIDIA's training guide defines it as a partitioning method that spreads one layer's parameter tensor across GPUs. vLLM, a serving engine, uses Megatron-LM's tensor parallel algorithm for the same job.

1. **Shard the weights:** Each layer's big weight tables are cut into equal pieces, one per GPU.
2. **Compute together:** Every GPU works on its piece of the same token at the same moment.
3. **Combine the results:** The partial answers are added together, so each GPU holds the full result for the layer.
4. **Repeat for every layer:** The GPUs swap results again at every layer, so the link speed matters a lot.

The payoff is speed for one reply, because all the GPUs work on the same token together. The cost is the chatter. Smaller slices also mean smaller jobs on each GPU, and NVIDIA's guide notes that this adds overhead on the CPU.

> **Tip:** Asked why it needs fast links, answer with the swap: after every layer, the GPUs must combine results before the next layer can start.

## How does pipeline parallelism split the layers?

Pipeline parallelism gives each GPU a run of consecutive layers. A token moves through stage one, then stage two, and so on. The GPipe paper described it as pipelining sub-sequences of layers on separate accelerators. vLLM says it splits the model along layers and supports uneven splits, so the stages do not need equal sizes.

The weak point is idle time. A single request passes through the stages one after another, so with four stages only one GPU works at any moment, and the other three wait. The idle gap has a name, the pipeline bubble. NVIDIA's training guide shrinks it by dividing each GPU's work into several smaller subsets of layers.

The idle cost depends on the load. With one request in flight, most GPUs sit idle. With many requests in flight, each stage can work on a different request, so the GPUs stay busy. That is why pipeline parallelism suits high-throughput serving, while a single reply rarely gets faster.

Across servers, pipeline parallelism is the friendlier choice. NVIDIA's training guide says it can work across nodes, but it needs careful batch size tuning.

> **Tip:** Asked about the bubble, say it in one line: the GPUs wait for each other, and more requests in flight keep them busy.

## Which one should you pick, and when?

- **Tensor: Inside one server.** Every layer is shared by the GPUs in one box, on a fast link. It can make one reply faster.
- **Pipeline: Across servers.** Only each stage's output moves from server to server, so slower links work. GPUs wait in turn, so a single reply gets no faster.
- **Both: Big model, several servers.** Tensor inside each server, pipeline between them. vLLM's guide recommends it when the model is too large for a single node.

vLLM's guide gives the same recipe. Set the tensor size to the GPUs per node, and the pipeline size to the number of nodes. It also gives a short list, one case per model size.

- **No split needed:** If the model fits on one GPU, skip distributed serving. vLLM says it is probably unnecessary.
- **Too big for one GPU, fits one node:** Use tensor parallelism inside the node. vLLM's example: tensor_parallel_size=4 on a 4-GPU node.
- **Combine when one node is small:** Tensor size is GPUs per node, pipeline size is the number of nodes.
- **No NVLink, use pipeline:** vLLM says pipeline gives higher throughput and lower communication overhead there.

*Diagram, Two ways to cut the model: Tensor parallelism cuts every layer, and pipeline parallelism cuts the stack into stages. Tensor's swaps need a fast link, so they stay inside one server. Pipeline's handoffs can cross slower links, but the GPUs wait in turn.*
1. The first path cuts every layer into slices.
2. The second path hands out whole layers, stage by stage.
3. Every layer then needs the GPUs to swap results.
4. Each stage waits for the one before it.
5. Keep the swaps inside one server, on the fast link.
6. Let the stage handoffs cross servers, on the slower link.

> "Tensor parallelism works best within a single node (high bandwidth)" (NVIDIA, training guide)
>
> "Efficient tensor parallelism requires fast internode communication, preferably through high-speed network adapters such as InfiniBand." (vLLM, serving guide)
>
> "devices spending significant time waiting on other devices to make progress" (Megatron-LM team, training paper)

## What does a two-server setup look like?

Take the made-up insurer again. Its model is split over two servers with 8 GPUs each. Server one holds the first half of the layers, and tensor parallelism spreads those layers across its 8 GPUs. Server two holds the second half, split the same way. Only the handoff between the servers crosses the network.

*Diagram, Two servers, one model: Each server runs tensor parallelism inside its box, on the fast link. The single pipeline handoff between the servers is the only traffic on the slower network.*
1. The one handoff crosses the slower network between the two servers.
2. Server 2 finishes the layers and sends the reply back.

The numbers that matter are the link speed, the size of the handoff and the idle time at the handoff. Measure those on real traffic before you commit to a split.

### How would you split a model across a new 16-GPU cluster?

1. **Check the fit first:** Load the weights and see whether one GPU holds them. If one GPU is enough, stop there.
2. **Fill each server first:** Set the tensor size to the GPUs in one server. Tensor needs the fast link, so it stays inside.
3. **Add pipeline across servers:** Set the pipeline size to the number of servers. Each extra stage adds a handoff and possible idle time.
4. **Measure, then tune:** Watch latency, GPU use and idle time under real load, and change one setting at a time.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Tensor splits each layer. Pipeline splits the stack of layers into stages.
- [ ] Tensor needs a very fast link, so it stays inside one server.
- [ ] Pipeline crosses servers, but its stages wait in turn: the bubble.
- [ ] Big models often use both: tensor inside, pipeline across.
- [ ] The right split depends on the links, batch size and latency target.
- [ ] Measured numbers from your own hardware and traffic.

**Common traps**

- Trap: "Tensor parallelism is always faster, so use it everywhere." Better: It is fastest on a fast link. On a slow link its swaps cost more than the pipeline handoffs.
- Trap: "More pipeline stages always mean a faster model." Better: Each stage adds a handoff and idle gaps. More stages help only when the model needs the memory.
- Trap: "Add GPUs across the slowest link and it gets faster." Better: Extra GPUs on a slow link add swaps. Choose the split the links can carry.

## Can you spot the right setup?

**Pick the setup:** A made-up team has two 8-GPU servers joined by plain Ethernet, and one model that needs both. Which setup suits it?

A. Tensor 16 across both servers, over the Ethernet link
B. Tensor 8 inside each server, pipeline 2 across the servers
C. Pipeline 16 with one GPU per stage, all over the Ethernet link
D. Two copies of the model, one per server

**Answer:** B. Tensor's swap after every layer stays on the fast link inside each server. Only one pipeline handoff crosses the Ethernet per step. Tensor across Ethernet swaps constantly. Sixteen one-GPU stages put every hop on Ethernet, including hops inside a server, and leave most GPUs waiting. Two full copies do not fit the model in the first place.

**Quick check:** Your server's GPUs have no NVLink, so the cards talk over a slower link. Which split do you lean on?

A. Tensor parallel across all GPUs, because it is always the faster split
B. Pipeline parallel across the GPUs, to cut communication overhead
C. Tensor parallel across two servers over Ethernet
D. No split, since a single GPU always holds the model

**Answer:** B. vLLM's guide says that without NVLink, pipeline parallelism gives higher throughput and lower communication overhead than tensor parallelism. The other options put constant swaps on the slow link or assume the model fits on one GPU.

## Can you answer these from memory?

**Flash cards**

- **What does tensor parallelism split?** Each layer's weights, so every GPU holds a slice of every layer.
- **What does pipeline parallelism split?** The stack of layers, so each GPU holds a block of whole layers.
- **Where does tensor parallelism belong?** Inside one server, where the GPUs share a very fast link.
- **Where does pipeline parallelism belong?** Across servers, where the link is slower and one handoff moves.
- **What is the pipeline bubble?** Idle time, when the stages wait for each other.
- **What is the usual big-model setup?** Tensor inside each server, pipeline across the servers.

## Likely follow-up questions

- Q317 The latency vs throughput trade-off? https://designervenkat.online/interview/ai/the-latency-vs-throughput-trade-off
- Q319 What is PagedAttention / vLLM? https://designervenkat.online/interview/ai/what-is-pagedattention-vllm
- Q320 Serving engines (vLLM, SGLang, TensorRT-LLM, llama.cpp)? https://designervenkat.online/interview/ai/serving-engines-vllm-sglang-tensorrt-llm-llama-cpp
- Q327 GPU basics: why does memory bandwidth limit decoding? https://designervenkat.online/interview/ai/gpu-basics-why-does-memory-bandwidth-limit-decoding
- Q328 Does a 70B model fit on one 80GB GPU? https://designervenkat.online/interview/ai/does-a-70b-model-fit-on-one-80gb-gpu
