Co-Designing LLM Inference Infrastructure and Models: Practices and Lessons
This article explores the co-design of large language model inference infrastructure and model architecture. It covers why model iteration forces inference systems to evolve, how to evaluate models and infrastructure within a unified constraint framework, the typical growth path of inference engines from single-model serving to platform-level capabilities, model-side considerations for inference-friendliness, infrastructure requirements around elasticity, isolation, and observability, and how to run realistic load testing and capacity planning. It concludes with a practical engineering checklist and common pitfalls, helping teams balance end-to-end SLOs, resource utilization, and cost.
1. Background: Model Iteration Is Forcing Inference Infrastructure to Evolve
There is a clear two-way constraint between the rapid iteration of LLM capabilities and the construction of inference infrastructure. On one hand, model architecture, context length, output distribution, and deployment patterns directly change the characteristics of inference workloads. On the other hand, the inference engine, scheduling policies, cache management, and elastic scaling capabilities in turn determine whether a model can go live stably at an acceptable cost. Many teams focus only on single-request latency in the early days. Once they reach scale, they discover that what truly determines system availability is the combined balance of throughput, tail latency, GPU memory headroom, cache hit rate, scaling speed, and failure recovery.
In a technical interview, a team reviewed its experience evolving inference infrastructure from an experimental service into a platform-level component. This kind of growth path is rarely driven by a single technical breakthrough. Instead, it iterates continuously under real business pressure: first making a single model servable, then enabling multi-model co-location; first optimizing average latency, then governing tail latency; first chasing peak throughput, then establishing cost and stability baselines. This article abstracts these lessons into a general methodology and discusses the core problems of co-designing models and infrastructure. It should be noted that co-design is not the only answer; different business scenarios should validate and make trade-offs against clearly defined SLOs.
2. The Essence of Co-Design: Putting the Model and Infra in the Same Constraint Table
Co-designing models and infrastructure does not mean having the model team and the infrastructure team optimize independently and then stitching the results together. It means evaluating key constraints in a single table from the earliest design stage. The model side needs to consider the number of layers, hidden width, attention structure, vocabulary size, context length, output length distribution, quantization sensitivity, and the difficulty of parallel sharding. The infrastructure side needs to consider compute density, memory capacity, interconnect bandwidth, cache hierarchy, batching capability, elastic scaling, and observability. Only by placing both sides in the same constraint table can teams avoid the disconnect of “the model performs well but inference cost is unacceptable” or “the inference platform has high throughput but the business experience falls short.”
A practical approach is to build a four-dimensional evaluation matrix of “model–workload–resource–cost.” The model dimension records architectural characteristics and accuracy requirements; the workload dimension records request length distributions, concurrency curves, and peak-to-valley ratios; the resource dimension records per-instance throughput, memory footprint, and scaling granularity; the cost dimension records per-request cost and per-token cost. This matrix does not need to be precise on the first pass, but it should be continuously calibrated with load-testing data. The goal of co-design is not to make every local metric optimal, but to achieve an acceptable balance among end-to-end SLOs, resource utilization, and iteration efficiency.
3. The Inference Engine Growth Path: From Single-Point Serving to Platform Capability
Inference engines in the industry typically grow through several stages. The first stage is single-model, single-instance serving, where the focus is on getting model loading, request parsing, streaming responses, and basic monitoring working. The second stage introduces batching, cache reuse, and concurrent scheduling, and teams begin to care about throughput and memory utilization. The third stage targets multi-model, multi-tenant, and elastic scaling scenarios, emphasizing isolation, quotas, priorities, and failure recovery. The fourth stage moves into cost governance and observability, using a metrics feedback loop to drive scheduling policies and resource planning.
The key insight from this path is that an inference engine should not be treated merely as a “model loader.” It should be regarded as an infrastructure component connecting model capability to business SLOs. It needs a complete pipeline covering request queuing, batch formation, cache block allocation, parallel execution, streaming output, exception retries, and metrics collection. Especially in long-context and streaming scenarios, time to first token (TTFT), inter-token latency, and tail latency often matter more to user experience than average throughput. Therefore, scheduling policies must consider batch size, waiting time, cache hit rate, and memory headroom simultaneously, rather than only chasing peak throughput.
Below is illustrative scheduling pseudocode showing the basic logic of batching and SLO governance:
Input: request queue Q, max batch token budget B, max wait time W, target SLOLoop:Take requests from Q and accumulate the token budgetWhen B is reached or waiting exceeds W, form a batchAllocate cache blocks for the batch, preferring to reuse free blocksRun the forward pass and stream results backRecord TTFT, inter-token latency, cache hit rate, and memory headroomIf p95 latency exceeds the threshold, reduce batch size or trigger scale-outIf the cache hit rate is low, inspect the request length distribution and cache eviction policy
This pseudocode emphasizes one principle: scheduling is not a static set of parameters but a control loop that adjusts dynamically around SLOs. An oversized batch may improve throughput but degrade tail latency; an undersized batch may waste resources. Insufficient cache reuse increases redundant computation, while excessive cache occupancy can squeeze out concurrency. In practice, teams should use load testing to determine parameter ranges for different workload shapes and continuously calibrate them with monitoring and alerting.
4. Model-Side Cooperation: Architecture Choices and Inference-Friendliness
The model side’s impact on inference performance is often underestimated. Longer context significantly increases cache occupancy and memory access pressure; the output length distribution determines the duration of streaming responses and how long concurrency slots are held; the attention structure affects compute density and cache management complexity; vocabulary size affects output-layer computation and sampling overhead. Techniques such as quantization, distillation, sparsification, and speculative decoding can reduce compute and memory pressure, but teams must evaluate accuracy loss, implementation complexity, and workload fit.
A more reasonable approach is to introduce an “inference-friendliness” assessment during model design or selection. For example, analyze the input and output length distributions of real requests and evaluate how long-tail requests affect caching and scheduling; run business-metric regressions for different quantization schemes instead of relying only on general benchmarks; assess the communication overhead of parallel sharding plans to avoid cross-node communication becoming a bottleneck. The model and infrastructure sides should share the same load-testing traffic and SLO metrics to ensure their optimization directions are aligned.
5. Infrastructure Side: Elasticity, Isolation, and Observability
The infrastructure layer must provide elasticity, isolation, and observability for inference workloads. For elasticity, focus on scaling granularity, cold start time, model loading speed, and how quickly traffic can be routed in. For isolation, focus on memory isolation under multi-model co-location, quota limits, priority scheduling, and fault-domain control. For observability, cover request-level, instance-level, and cluster-level metrics, including TTFT, inter-token latency, throughput, error rate, cache hit rate, memory headroom, queue length, and scaling events.
On Baidu AI Cloud, general-purpose capabilities such as the container platform, object storage, log services, and monitoring and alerting can serve as the foundation for building an inference platform; the specific selection should still be validated against SLOs, cost models, and operational complexity. Platform building should avoid simply stacking components and instead establish a metrics feedback loop: monitoring discovers problems, logs locate them, load testing reproduces them, and scheduling policies or resource planning resolve them. For multi-tenant scenarios, quotas, rate limiting, priorities, and degradation policies must be clearly defined so that a single large request cannot drag down the entire service.
6. Evaluation and Load Testing: Use Real Traffic Distributions Instead of a Single Peak
A common mistake in evaluating inference systems is testing only peak throughput or average latency. A more effective approach is to run load tests with real traffic distributions, covering short requests, long requests, long-tail requests, sudden concurrency bursts, and cold-cache scenarios. Load-testing metrics should include at least: TTFT at P50/P95/P99, inter-token latency at P95, end-to-end completion time, throughput per unit time, error rate, peak memory usage, cache hit rate, and scaling response time. For streaming scenarios, output interruption rate and retry cost should also be tracked.
Load-testing results should be converted into capacity-planning parameters, such as safe per-instance concurrency, scale-out thresholds, batch size ranges, and cache quotas. Capacity planning should not aim for a one-time, perfect solution; it should retain safety margins and be reviewed regularly. For cost-sensitive businesses, per-request cost and per-token cost can be computed further to identify waste caused by long-tail requests, duplicate requests, and low cache hit rates.
7. Engineering Checklist and Common Pitfalls
When implementing, teams can refer to the following checklist. First, define business SLOs and cost boundaries to avoid aimless optimization. Second, build the model–workload–resource–cost evaluation matrix. Third, run load tests with real traffic distributions and record P95/P99 metrics. Fourth, design control loops for batching, caching, and scaling. Fifth, establish request-level and instance-level observability. Sixth, define multi-tenant isolation, rate limiting, and degradation policies. Seventh, regularly review cache hit rate, memory headroom, and unit cost.
Common pitfalls include: chasing peak throughput while ignoring tail latency; swapping the inference engine without adjusting model architecture or request distribution; treating cache as an unlimited resource; lacking load-testing baselines so that scaling parameters are set by guesswork; and having multiple teams optimize locally without a unified SLO. The value of co-design lies in using unified metrics and a shared constraint table to reduce local optima, turning model capability into business value in a predictable and governable way. The views in this article are offered for discussion; actual implementation still requires continuous validation in your specific scenario.
