Home / Learn / AI Infrastructure / Distributed Inference Explained
On this page
Why inference is distributedScaling by replicationSplitting the modelSeparating the stages of a requestThe communication costManaging stateOrchestrationMeasures of performanceInfrastructure requirementsInference at the edgeCommon questionsRelated guidesDistributed Inference Explained
Distributed inference spreads the work of serving an AI model across multiple accelerators or machines. It is used when a model is too large for one accelerator, when a single accelerator cannot answer fast enough, or when demand exceeds what one machine can handle. The work can be divided in several ways: by splitting the model, by running many copies of it, or by separating the stages of a request. In each case, the connections between the parts become critical to performance.
Why inference is distributed
The model does not fit. Large language models have so many parameters that their weights, plus the working memory needed to run them, exceed one accelerator’s memory.
One accelerator is too slow. Even when a model fits, sharing the work across several can shorten response time.
Demand is too high. A popular service receives far more requests than one machine can process.
Availability. Running on several machines means a failure does not take the service down.
Cost. Different parts of the workload may run more economically on different hardware.
Scaling by replication
The simplest form is to run many identical copies of the model, each on its own accelerator or server. A load balancer sends each request to one of them.
Each request is handled entirely by a single replica. The replicas do not need to talk to each other. This scales throughput almost linearly and is easy to operate.
It does not help when the model is too big for one accelerator, and it does not make any individual request faster.
Splitting the model
When a model is too large, it is divided across several accelerators that cooperate on each request. There are two main ways.
Splitting by layer. The model’s layers are divided into groups, each assigned to a different accelerator. Data flows through them in sequence, passing from one accelerator to the next. This reduces the memory needed on each. It does not speed up a single request much, since the stages run one after another, though several requests can be in progress at once.
Splitting within layers. The large matrices inside each layer are divided across accelerators, which compute their parts simultaneously and combine the results. This speeds up each request and requires the accelerators to exchange data at every layer. It depends on a very fast interconnect.
| Replication | Split by layer | Split within layers | |
|---|---|---|---|
| Solves model too large | No | Yes | Yes |
| Speeds up one request | No | Slightly | Yes |
| Raises throughput | Yes | Yes | Yes |
| Communication between accelerators | None | Moderate | Heavy |
| Interconnect demand | Low | Moderate | Very high |
Large deployments combine these: the model is split across the accelerators of one server or rack, and that whole unit is replicated many times.
Separating the stages of a request
Language model inference has two phases with different characteristics. Prefill processes the prompt. Decode generates the response token by token. They can be run on separate pools of hardware, with the intermediate state passed between them.
More broadly, an AI application is often a pipeline. A request may pass through retrieval of documents, several model calls and post-processing. Each stage can run on resources suited to it.
The communication cost
Distributing work is never free. Whenever accelerators cooperate on a request, data has to move between them.
- Within a server, accelerators are joined by fast local links.
- Within a rack, a dedicated scale-up interconnect is used.
- Across racks, traffic goes over the data center’s high-performance network.
Each step outward adds delay. When a model is split within its layers, communication happens many times per generated token. A slow link directly slows the response.
This is why very large models are served on tightly integrated systems, where many accelerators share an extremely fast interconnect. and What Is a Scale-Up Fabric?.
Managing state
Language models keep a cache of intermediate results for each conversation, called the KV cache. It is large, and it lives on whichever accelerators processed the conversation.
This complicates distribution.
- Routing. A follow-up message is handled most efficiently by the machine that already holds its cache. Sending it elsewhere means recomputing.
- Balancing. Spreading load evenly conflicts with keeping conversations on the same machine.
- Sharing. If caches are kept in shared memory or storage, any machine can pick up any conversation, at the cost of transferring the cache.
Modern inference systems use routing that takes cache location into account.
Orchestration
A distributed inference system needs a control layer.
- Request routing to an appropriate replica or pool.
- Batching. Grouping requests to use accelerators efficiently, balanced against response time.
- Autoscaling. Adding and removing capacity as demand changes.
- Placement. Deciding which models run where, especially when many different models are served.
- Health monitoring and failover.
- Admission control. Limiting load to protect response times.
Measures of performance
- Time to first token. How long before the response begins.
- Time between tokens. How steadily it continues.
- Throughput. Total tokens or requests per second.
- Tail latency. The response time of the slowest requests.
- Cost per token.
- Utilization of the accelerators.
These trade against each other. Larger batches raise throughput and lengthen waits. Operators set targets for response time and maximize throughput within them.
Infrastructure requirements
- Fast interconnect among accelerators that share a model.
- A high-performance network between servers, with consistent latency.
- Fast paths to storage and memory tiers for loading models and moving cached state.
- Efficient handling of network and storage traffic, so the CPUs are not consumed by it.
- Isolation where several tenants share the system.
As with training, the limit on a distributed inference system is frequently the movement of data, not arithmetic.
Inference at the edge
Distribution also happens geographically. Models can be served from many locations close to users to reduce delay, or split so that a small model on a device handles simple requests and a large model in a data center handles the rest.
Common questions
Why can a large model not run on one GPU?
Its weights and working memory exceed the memory of a single accelerator. It has to be divided across several.
Does distributing a model make it faster?
It depends on how it is split. Dividing the work within each layer can speed up a request if the interconnect is fast. Running replicas increases total throughput without making any single request faster.
What is the main difficulty in distributed inference?
Communication and state. Accelerators that share a model must exchange data quickly, and each conversation’s cached state has to be in the right place.