Scaling LLM Inference Deployment: From Chip Selection to Scheduling Optimization
This article examines the engineering challenges of deploying LLM inference at scale, including latency and cost constraints, end-to-end bottleneck analysis, parallelism and deployment topology, continuous batching and request scheduling, KV cache management, operator and communication optimization, serving concerns, observability, capacity planning, and common pitfalls. It emphasizes measuring real workloads, validating cache and scheduling strategies against production traffic, and balancing latency, throughput, and cost rather than optimizing a single metric.
1. Why Inference Deployment Is Difficult to Engineer
Training jobs can usually be scheduled offline, and their input lengths and batch sizes are relatively controllable. Inference services, by contrast, face online traffic directly. Request input lengths, output lengths, arrival times, and concurrency levels are all unstable. For the same model, short question answering and long document summarization may differ by several times in resource consumption.
An online service must also satisfy latency and cost constraints at the same time. Excessive latency harms user experience, while low resource utilization raises the cost per request. The core task of an inference framework is to find a sustainable balance between these two constraints.
Therefore, inference deployment cannot focus only on the model’s capabilities. It must also consider how the model performs under real workloads. The following metrics are the most commonly used basic concepts when discussing inference performance:
- Time to First Token (TTFT): the time from request arrival to the output of the first token. This directly affects the response speed perceived by users.
- Time Per Output Token (TPOT): the average time required to generate each token during the output phase. This determines the fluency of long responses.
- Throughput: the number of tokens or requests processed by the system per unit of time. This reflects the resource output capacity.
- Queueing time: the time a request waits before entering computation. This is often the main reason for degraded experience during peak periods.
2. End-to-End Performance Is Determined by Multiple Stages
Inference performance is not a problem that can be solved by making a single operator run fast. Operator computation, inter-device communication, request scheduling, and memory and cache management all affect one another. A bottleneck in any one of these areas will slow down the overall result.
For analysis, a request can be divided into several phases. The input phase needs to process the full prompt and involves a large amount of computation, so it is usually limited by compute capacity. The output phase generates tokens one by one, and each step reads a large amount of historical cache, so it is usually limited by memory bandwidth. The bottlenecks in these two phases are different, and so are the optimization methods. If both are adjusted together under the same set of parameters, trade-offs often go in the wrong direction.
Deployment conditions are equally critical. Chip type, per-GPU memory capacity, inter-GPU interconnect bandwidth, and network topology between machines all constrain the available parallelism methods. Optimization parameters discussed without considering hardware conditions are difficult to reuse.
3. Parallelism Methods and Deployment Topology
When the model size exceeds single-GPU memory, the model must be partitioned across multiple GPUs. Common partitioning methods include:
- Tensor parallelism: split the weight matrices of a single layer and distribute them across multiple GPUs for simultaneous computation. This requires high inter-GPU bandwidth and is usually used for multi-GPU scenarios within the same machine.
- Pipeline parallelism: split the model into several segments by layer and place different segments on different devices. This reduces per-GPU memory pressure but introduces pipeline bubbles and lowers device utilization.
- Expert parallelism: for mixture-of-experts architectures, distribute different experts across different devices. This requires well-designed routing and communication; otherwise, load imbalance is likely.
When choosing a method, first measure the model’s memory usage and communication overhead on the target hardware, and then decide the partitioning dimension. More partitions are not always better. Excessive communication synchronization may offset the computational gains.
The deployment topology also needs to be determined according to business characteristics. For latency-sensitive interactive scenarios, headroom usually needs to be reserved for time to first token. For offline batch tasks, higher queueing time can be accepted in exchange for larger batches and higher throughput. Mixing these two types of traffic on the same set of instances can easily cause interference, so separate pools by workload type can be considered.
4. Request Scheduling and Dynamic Batching
The scheduler determines which requests are included in each computation step. Traditional static batching waits for a batch of requests to accumulate before executing them together. As a result, earlier requests are forced to wait, and resources sit idle because long and short requests finish at different times.
Continuous batching is a commonly used approach today. It adjusts the batch at the token-step level: when a request finishes, a new request immediately fills the vacated position. This can maintain high computational utilization continuously.
Scheduling must consider the following constraints at the same time:
- Requests already in the decoding phase should be retained first to avoid interrupting output that users have already seen.
- Before a new request enters the batch, check whether the available cache space is sufficient to hold its input.
- The total number of tokens computed in a single step must have an upper limit to prevent an overly large single computation from causing other requests to time out.
- Requests with different priorities should have clear queueing rules to prevent low-priority tasks from occupying resources for a long time.
The following is a simplified scheduling illustration to explain the above ideas. It is not an implementation of a specific system:
def schedule_step(waiting, running, kv_pool, max_batch_tokens):batch = []budget = max_batch_tokens# Prioritize requests currently decodingfor req in running:if kv_pool.can_extend(req):batch.append(req)budget -= 1# Admit new requests by priority and waiting timefor req in sorted(waiting, key=lambda r: (r.priority, r.arrival_time)):need = req.prompt_lenif need <= budget and kv_pool.can_allocate(req):batch.append(req)budget -= needreturn batch
The key point in the example is that the budget constraint and the cache check are parallel gates. If either one is not satisfied, the request remains in the waiting queue instead of being forced into the batch and causing memory overflow.
5. KV Cache Management
During autoregressive generation, the model needs to store the key and value vectors of every historical token. This data is called the KV cache. Its size is proportional to context length, batch size, and number of layers. When long contexts and high concurrency occur at the same time, the KV cache often becomes the main consumer of GPU memory.
Common management approaches include the following:
- Paged management: divide the cache into fixed-size blocks and allocate them on demand, reducing waste caused by reserving an entire segment of space.
- Prefix reuse: identical system prompts or document prefixes can share already computed cache, reducing repeated computation.
- Eviction strategies: when space is insufficient, release cache according to recency of use or request priority, while considering the recomputation cost of evicted requests.
- Offloading and restoration: move inactive cache to host memory or other storage tiers and load it back when needed, at the cost of increased access latency.
Cache strategies need to be validated against business data. The benefit of prefix reuse depends on the degree of repetition across requests. If business prompts differ greatly, the reuse rate may be very low, and the additional management overhead may not be worthwhile.
6. Operator and Communication Optimization
Common operator-level optimizations include operator fusion, quantization, and specialized kernels. Operator fusion merges multiple small operators to reduce the number of reads and writes of intermediate results. Quantization reduces weights or cache from high precision to low precision, lowering memory usage and bandwidth pressure, but it is necessary to evaluate whether the accuracy loss is acceptable for the business.
At the communication level, the focus is to overlap computation and transfer as much as possible. In multi-GPU inference, results often need to be synchronized after each layer’s computation. If the synchronization phase completely blocks computation, devices will sit idle. By splitting communication into several small chunks and interleaving them with subsequent computation, part of the latency can be hidden.
Optimization must be based on measurement. After each change, compare changes in time to first token, time per output token, and throughput, and check whether tail latency has worsened. Looking only at averages can easily mask timeout problems in individual requests.
7. Serving and Output Components
Inference capabilities are ultimately provided externally as a service, so the serving layer also affects experience. Streaming output allows users to see results progressively during generation, improving perceived latency. Structured output, such as data returned in a fixed format, requires constraints during decoding to avoid generating invalid content and then repairing it in post-processing.
The API layer also needs to handle timeouts, cancellation, and retries. After a user actively disconnects, the server should release the corresponding compute resources promptly; otherwise, resources will be wasted. Retry strategies should avoid amplifying traffic under high load. Exponential backoff with a maximum retry count can be used.
8. Observability and Capacity Planning
Optimization without metric support is difficult to sustain over time. It is recommended to cover at least the following categories of data:
- Request layer: success rate, proportion of each error code, and percentiles of time to first token and time per output token.
- Scheduling layer: queueing time, batch size distribution, and number of tokens computed per step.
- Resource layer: memory usage, cache hit rate, device utilization, and inter-GPU communication time.
- Business layer: performance across different input length ranges, and traffic curves during peak periods.
Capacity planning can be carried out in the following steps. First, use representative data for stress testing to find the maximum load per instance that meets the latency target. Then, calculate the required number of instances based on peak business traffic and redundancy requirements. Before launch, traffic should be increased gradually through canary releases, with automatic rollback conditions configured, such as stopping scaling when tail latency exceeds a threshold.
Cost accounting should also be organized around unit requests. Amortize device costs, power, and operations and maintenance investment over every thousand tokens or every request to compare the economics of different deployment options.
9. Practical Recommendations and Common Pitfalls
First, establish a baseline before optimization and confirm whether the bottleneck lies in computation, communication, scheduling, or cache.
Second, adjust parameters one item at a time. Avoid changing multiple variables simultaneously, which makes it impossible to determine the source of the effect.
Third, do not pursue throughput alone. The larger the batch, the longer the waiting and computation time for a single request may be, and user experience will decline.
Fourth, pay attention to long-tail requests. A small number of extremely long inputs may occupy a large amount of cache. An input length limit should be set, or separate resources should be allocated for them.
Fifth, keep the test environment consistent with the production environment. Differences in hardware models, driver versions, and load distribution will distort stress-test results.
Overall, LLM inference deployment is a systems engineering task. It requires developers to understand model structure, hardware characteristics, and service governance at the same time. Only by clearly explaining the metrics, constraints, and trade-offs of each stage can stable and predictable services be provided continuously under limited resources.
