Distributed Inference
How it works
The model and computation are partitioned along one or more dimensions. In tensor parallelism, a layer's weight matrices are sharded across GPUs and results are combined with an AllReduce/AllGather within the layer. In pipeline parallelism, consecutive layers are assigned to separate stages (devices) and activations are sent point-to-point between stages; micro-batching reduces pipeline bubbles. Data/replica parallelism replicates the model and distributes requests for higher throughput. In MoE models the analogue is expert parallelism, routing tokens via an All-to-All operation. When memory is insufficient, weight/state sharding and offloading to CPU/NVMe (ZeRO-Inference) are used. A distributed KV cache and fast interconnects (NVLink/InfiniBand) minimize the communication cost that dominates the decoding phase.
Problem solved
A single accelerator has limited memory and compute, so the largest models (tens to hundreds of billions of parameters) do not fit on one GPU or run too slowly. Distributed inference addresses the memory and throughput limits by splitting the model and its computation across multiple devices.
Components
Weight matrices (e.g., attention and MLP projections) are split column-/row-wise; results are combined via AllReduce/AllGather within the layer.
The model is split into stages assigned to different devices; activations are passed point-to-point; micro-batching reduces pipeline bubbles.
Official
Official
Implemented by libraries such as NCCL; the dominant communication cost of distributed inference.
Official
Implementation
Collective operations (AllReduce/All-to-All) dominate time when inter-device/inter-node links are slow.
Device idle time at pipeline fill/drain reduces efficiency.
Uneven weight or token (MoE) partitioning stalls faster devices.
Evolution
GPipe introduces pipeline parallelism with micro-batching for giant networks.
Megatron-LM popularizes tensor parallelism for Transformer layers.
A dedicated distributed Transformer inference system combining TP, PP and offload (ZeRO-Inference).
Alpa automates inter- and intra-operator parallelism for distributed training and inference.
vLLM introduces PagedAttention and distributed serving with KV-cache management, an industry standard for LLM inference.
Hyperparameters (configurable axes)
Number of devices splitting a single layer.
Number of pipeline stages (layer groups) on separate devices.
Number of model replicas serving requests in parallel.
Micro-batch size that reduces pipeline bubbles.
Computational complexity
Space complexity: O(P / N) na urządzenie.
Parallelism
Tensor parallelism is fully parallel within a layer, but pipelining introduces sequential dependencies between stages; the decoding phase is communication-bound.
Hardware requirements
Requires multiple GPUs with fast interconnects (NVLink/InfiniBand) for collective operations.
TPU pods with ICI interconnects support model and pipeline parallelism well.