Sub topic 12
Scaling Across GPUs with Tensor Parallelism
Assume you know basic Python and command-line use, understand GPU memory, and have already run a vLLM server on one GPU. This chapter explains how to split one model across several GPUs when the model or its KV cache does not fit on a single device.
What tensor parallelism does
Tensor parallelism splits the tensors inside a model across multiple GPUs. A tensor is a multi-dimensional array of numbers, such as a layer's weight matrix. Each GPU stores and computes part of that matrix. The GPUs then exchange intermediate results through collective communication, usually provided by NVIDIA Collective Communications Library (NCCL).
For example, with four-way tensor parallelism, vLLM divides supported model computations across four GPUs:
vllm serve Qwen/Qwen2.5-32B-Instruct \
--tensor-parallel-size 4 \
--max-model-len 8192 \
--enable-prefix-cachingThe --tensor-parallel-size 4 option tells vLLM to use four GPUs for one model replica. It does not create four independent servers. A request uses all four GPUs together.
When to choose it
Tensor parallelism is useful when the model weights and runtime memory exceed one GPU's capacity. It can also increase the memory available for longer prompts, larger batches, or larger KV caches.
The main trade-off is communication. Every generated token may require GPUs to synchronize. Fast links such as NVLink reduce this cost. GPUs connected only through slower PCIe links can spend more time communicating, especially during decode, when generation processes one token at a time.
| Situation | Likely choice |
|---|---|
| Model fits on one GPU and latency is acceptable | Use one GPU |
| Model does not fit on one GPU | Use tensor parallelism or quantization |
| Several GPUs have fast peer-to-peer links | Tensor parallelism is attractive |
| GPUs are in separate machines | Consider a distributed design and network bandwidth carefully |
Practical requirements and failures
All participating GPUs should have compatible capabilities and enough free memory. The tensor-parallel size normally must divide the model's attention and feed-forward dimensions as required by that model architecture. vLLM reports an error when a model cannot be partitioned with the requested size.
Check these conditions before starting:
CUDA_VISIBLE_DEVICESexposes the intended GPUs.- The GPUs can communicate through the expected peer-to-peer path.
- The host has enough shared memory and NCCL can initialize.
- The model's total memory, including KV cache, fits across the selected GPUs.
Tensor parallelism does not automatically solve every memory problem. A long --max-model-len can still reserve too much KV-cache space, and a large batch can exhaust memory after the server starts. Reduce the context length or concurrency limit when necessary. Quantization can reduce weight memory, while tensor parallelism distributes the remaining memory and computation.
Exercise
A 32B model does not fit on one 24 GB GPU, but four identical GPUs are available in one host. Which vLLM option should you try first, and what cost should you measure?
Show answer
Try --tensor-parallel-size 4. Measure end-to-end latency and throughput because cross-GPU communication can reduce the benefit, especially for token-by-token decode.