0%
LLM Inference and Serving: GPUs, Batching, and Cost
How Inference Works
Making Inference Fast
Serving Systems
Parallelism Across GPUs
Many models are too large for one GPU, and many that fit run better when spread across several. Splitting a model across GPUs is called model parallelism, and there are several ways to do it, each with different communication patterns, memory savings and effects on latency and throughput. This lesson explains data, tensor, pipeline, expert and context parallelism for inference, how they combine, and how to choose a layout. This first section explains the reasons to split a model at all.
Reason one: the model does not fit
The most common reason is capacity. A 70B model in 16 bit needs about 140 gigabytes for weights alone, more than any single 80 gigabyte GPU holds. A 405B model needs about 810 gigabytes in 16 bit, more than a full server of eight 80 gigabyte GPUs. Large mixture of experts models with hundreds of billions of total parameters need hundreds of gigabytes even in 8 bit. For these models, splitting is not an optimization but a requirement, and the question is only how to split them efficiently.
Capacity includes the KV cache. A model whose weights barely fit on one GPU leaves no room for cache and can serve only a handful of short requests. Splitting it across two GPUs halves the weights per GPU and frees memory for cache on both, which can multiply concurrency by far more than two. So even models that technically fit are often split to make room for a useful batch.
Reason two: latency
Decode is memory bound, so its step time is set by how many bytes each GPU must read. Splitting a model across four GPUs with tensor parallelism means each GPU reads a quarter of the weights per step, so the step can finish in roughly a quarter of the time, minus communication overhead. For latency sensitive products, this is the main tool for reducing time per output token below what one GPU can achieve. A 70B model that decodes at 40 milliseconds per token on two GPUs might decode at 15 to 20 milliseconds on eight.
Reason three: throughput per dollar
Splitting also changes cost. More GPUs per replica means more total memory for cache, so larger batches and higher throughput per replica. Whether throughput per GPU rises or falls depends on the balance between the memory freed for cache and the communication overhead added. For some workloads, two replicas of two GPUs each beat one replica of four GPUs; for others, the reverse. The best layout must be found by estimation and measurement, not assumed.
Data parallelism is not model parallelism
Data parallelism runs complete, independent copies of the model on different GPUs or groups of GPUs, each serving its own requests. It is the simplest way to scale throughput: twice the replicas, about twice the throughput. It does not reduce the memory each replica needs or the latency of individual requests. In serving, data parallelism is usually just called replicas and is handled by a load balancer or router. Model parallelism, by contrast, splits one replica across GPUs. Real deployments combine both: each replica is model parallel across some GPUs, and there are many replicas.
The cost of splitting
Every form of model parallelism adds communication. GPUs holding different parts of a model must exchange activations, partial results or tokens, and that communication sits on the critical path of each step. It also adds complexity: more GPUs per replica means more ways to fail, longer startup as more weights load, and more demanding scheduling, since all GPUs of a replica must be available together. A good layout splits as little as needed to meet capacity and latency goals, and uses the fastest links for the most frequent communication.
The vocabulary of layouts
Layouts are described by the degree of each kind of parallelism. TP4 means tensor parallelism across four GPUs. TP8 PP2 means tensor parallelism across eight GPUs within each of two pipeline stages, sixteen GPUs per replica. EP32 means expert parallelism across 32 GPUs. DP is the number of replicas. Engines accept these as configuration flags, such as tensor parallel size and pipeline parallel size in vLLM, and the product of the degrees gives the number of GPUs per replica.
Training versus inference parallelism
Training uses the same forms of parallelism but with different goals. Training also has to store optimizer state and gradients, is dominated by large batches of long sequences, and runs backward passes. Inference has no gradients, varies batch sizes constantly, and cares about latency per token. As a result, layouts that are optimal for training often differ from those optimal for serving the same model. A model trained with TP8 PP16 across 128 GPUs may be served with TP8 on a single server, or with expert parallelism across a rack, depending on the serving goals.
A worked example of fit
Take a 70B model with 80 layers and 8 key value heads of dimension 128, served in bfloat16 on 80 gigabyte GPUs with a 0.9 utilization setting. On TP2, each GPU holds about 70 gigabytes of weights plus about 3 gigabytes of overhead, already more than the 72 gigabytes allowed, so the replica cannot start with any useful cache. On TP4, each GPU holds about 35 gigabytes of weights, leaving about 34 for cache, 136 gigabytes across the replica. At 320 kibibytes per token, that is about 445,000 tokens, enough for around 100 conversations of 4,000 tokens. On TP8, each GPU holds about 17.5 gigabytes, leaving about 51 for cache, 408 gigabytes in total, about 1.3 million tokens. Doubling the GPUs from four to eight tripled the cache, because the weight share shrank while the overhead stayed fixed.
The same arithmetic in FP8 changes the picture. Weights take 70 gigabytes, so TP2 leaves about 34 gigabytes per GPU for cache, the same as TP4 in bfloat16, using half the GPUs. Precision and parallelism are therefore two levers for the same goal, and the cheapest layout often combines a lower precision with a smaller parallel degree, provided the quality evaluation passes.
What latency splitting can and cannot buy
Splitting reduces the memory part of each decode step but not the fixed parts. Kernel launch overhead, CPU scheduling, sampling and the communication added by splitting all stay the same or grow. On one GPU, a 70B model in FP8 might take 25 milliseconds per step, almost all of it reading weights. On TP8, reading weights takes about 3 milliseconds per GPU, but communication, launches and scheduling might add 5 more, so the step takes about 8 milliseconds rather than the 3 that perfect scaling would predict. The returns from splitting diminish as the fixed costs come to dominate, which is why going beyond TP8 rarely helps latency for dense models.
Splitting and the cost per token
Cost per token is the hourly cost of the replica divided by its goodput. Splitting raises the hourly cost in proportion to the GPUs used, so it lowers cost per token only if goodput rises faster than the GPU count. That happens when the extra memory enables a disproportionately larger batch, as in the TP2 to TP4 example, and stops happening once cache is plentiful. In practice, teams find a sweet spot for each model where cost per token is lowest, then go wider only for latency sensitive traffic, often in a separate pool priced accordingly.
Splitting and startup time
A replica cannot serve until every GPU has loaded its share of the weights. Splitting helps here: each GPU loads a fraction, often in parallel from fast storage. But the replica waits for the slowest GPU, and collective initialization across the group adds seconds. Startup time affects autoscaling, which lesson sixteen covers.
Each form of parallelism trades communication and complexity for capacity or speed. Start from the smallest layout that fits the weights with enough cache and meets the latency objective, then add replicas for throughput.