Performance tuning for AI inference, or AI inference optimization, means profiling and optimising the deployed serving path before considering a new model. You profile where latency and cost actually go, adjust the lever that owns that cost, and keep the change only if measurements improve. The dominant levers (batching, caching, routing, quantisation, kernel work, serving configuration and runtime choice) all sit below the model layer, and each can be tuned on its own.
Sequencing matters more than any single technique. Tuning that starts from a profiled bottleneck works on the layer that actually costs the latency. Tuning that starts from a guess can optimise a layer that was never the constraint, and avoiding that is the purpose of an inference cost audit that finds the real bottleneck before you replace the model.
AI inference optimization covers the serving stack, not only the model
Inference is the phase where a trained model is applied to new data. Unlike training, it runs in user-facing environments, where performance under load (response time, throughput and availability) decides whether the system is usable. The latency and throughput of a large language model depend on the hardware, on how well the software framework uses that hardware, and on the model architecture, so improvements can come from any of the three. Pham and Gedikli’s 2026 serving study states the gap plainly: research attention goes to architectures and benchmark accuracy, but strong predictive performance is not enough if the model cannot be served reliably, efficiently and at scale.
Some of the cost is not in the model at all. The PyTorch/Serve optimisation checklist tells engineers to look beyond model inference, because pre- and post-processing can cut end-to-end throughput as much as the model does. The same checklist warns that a transformer trained with padding to a constant length, and deployed with that same padding, can run orders of magnitude slower than necessary on short sequences. Fixing either problem changes no weights.
Where should you start before changing anything?
Start by measuring. The classic tuning loop has six steps:
- Set numeric values for acceptable behaviour.
- Measure the system before changing it.
- Find the bottleneck.
- Change that part.
- Measure again.
- Revert the change if performance got worse.
The bottleneck is the part of the system running at capacity while other parts wait for it, and you should prove it exists by measurement before acting to remove it. The PyTorch/Serve checklist applies this to inference. First collect system-level activity logs (even nvidia-smi and htop help). Then go after the target with the highest impact, and turn to model-level optimisation only after the low-hanging fruit has been checked.
The level of detail you measure at matters too. The lm-Meter authors (2025) argue that profiling by phase (embedding, prefill, decode, softmax, sampling) pinpoints the bottleneck and avoids the misleading conclusions that end-to-end averages invite. Their on-device measurements found prefill to be the main throughput bottleneck on mobile hardware. That is the opposite of the decode-bound picture typical of server GPUs. The method for getting those numbers, and how to read them, is covered in profiling AI inference and what the numbers mean.
Our position is that best-practice rules only make sense in the context a profile gives them. “Always quantise” or “always max out the batch” is a hypothesis until the trace shows the targeted layer is the constraint.
Prefill or decode: the dominant phase picks the lever
LLM inference has two phases with different hardware demands. Prefill processes the prompt in parallel and is limited by processor throughput. Decode generates one token at a time and is limited by memory bandwidth. Which phase dominates depends on input and output lengths. In a December 2025 GPU study of Qwen2.5-7B producing 128 output tokens, decode took most of the latency at short inputs, and prefill overtook it beyond a crossover of around 2k input tokens.
Prefix caching only shortens prefill, so it gives no gain when most of the time goes into generating long answers, or when new requests share no prefix with earlier ones. In the Llama-3.1 quantisation study, weight-only quantisation mainly speeds up decode by cutting memory traffic, while quantising both weights and activations mainly helps prefill compute, so the right scheme depends on the ratio of prefill tokens to decode tokens. Decode-heavy services are the textbook case of memory bandwidth as the bottleneck: the bandwidth a system actually achieves predicts token-generation speed better than its peak compute does.
How do batching and request routing raise throughput without changing the model?
Batching raises throughput by generating tokens for many requests in one forward pass. Routing raises it by sending each request where it wastes the least work. Both levers sit below the model layer.
Static, dynamic and continuous batching
Databricks’ engineering team describes three batching modes:
- Static batching: the client packs several prompts into one request and gets the responses back when every sequence has finished.
- Dynamic batching: the server groups prompts on the fly.
- Continuous batching: sequences are grouped at each generation step. By the team’s account this can give 10x to 20x the throughput of dynamic batching.
Continuous batching does not always win. The same team notes that dynamic batching can beat it at low request rates, and that static batching avoids overhead for offline batch jobs. Static batching wastes capacity because hardware has to wait for the longest request in a batch to finish. A multi-bin batching study, revised with real inference runs on llama.cpp, grouped requests by estimated output length. On the Dolly workload, estimated-length binning at k=8 raised throughput 150.1% over static batching, but stayed 43.0% below native continuous batching. For batch processing on mixed-length sequences, PyTorch/Serve suggests sequence bucketing (sorting inputs by length before batching), which it says could improve throughput 2X by cutting padding.
Batch size trades latency for throughput, and the gain levels off
Grouping queries raises throughput, but each query takes longer to complete. Databricks reports that on one NVIDIA A100, raising the batch size to 64 increased throughput 14x and latency 4x. NVIDIA’s Triton Inference Server documentation gives a tuning procedure:
- Start from the default dynamic batcher.
- Measure it with Performance Analyzer.
- If latency is within budget, raise the maximum batch size or set a non-zero
max_queue_delay_microseconds, and keep going until the latency budget is exceeded.
In Triton’s optimisation guide, the dynamic batcher reaches 272 inferences per second with eight concurrent requests, with no added latency compared with running unbatched.
Gains from larger batches plateau. A GPU-level study of large-batch inference in vLLM found that OPT-2.7B throughput rose only about 33.8x between batch size 1 and 256. Attention stayed memory-bound and saturated DRAM bandwidth. In that study, a batch size of 96 chosen by profiling gave OPT-1.3B 83.13% of its maximum-batch throughput while using 16.32% of the KV cache. The bin count in multi-bin batching is also a tuning parameter that depends on the workload: more bins suit high-load, throughput-oriented settings, and fewer suit latency-sensitive ones.
Routing by request length and by cache locality
Routing decides which replica or pool serves a request, and for LLM fleets it is a lever in its own right, because a routing decision tuned for one workload and pool layout can be a poor fit for another. The vLLM Semantic Router project (2026) reports that sending requests to short-context or long-context pools, based on estimated token budget, cut GPU instances by 17–39% on production traces.
Cache-blind load balancers spread requests that share a prefix across different pods, which destroys cache locality; llm-d benchmarked this on 8 vLLM pods (16 H100 GPUs) with a multi-tenant workload of 6,000-token contexts. Precise prefix-cache-aware scheduling achieved a P90 time to first token of 0.542 seconds, against more than 31 seconds for approximate scheduling. It also produced 8,730 output tokens per second, more than double the cache-blind configurations. The workload’s shared prefixes needed about 73% of the cluster’s KV-cache capacity, roughly six times what any single pod held. A fleet with little prefix sharing should expect much less from this lever.
Prompt and prefix caching only pays when prefixes repeat
Prefix caching stores the attention key and value tensors computed for a prompt prefix, so a later request with the same prefix skips that computation. In vLLM you switch it on with enable_prefix_caching=True. It suits a long document queried many times and multi-round conversations. OpenAI’s prompt caching needs an exact repeated prefix in prompts of at least 1,024 tokens.
The gain grows with prompt length. In OpenAI’s Prompt Caching 201 runs, cached requests were 7% faster to first token at 1,024-token prompts and 67% faster at 150k tokens and above. In the pricing llm-d cites, cached tokens cost a tenth as much as uncached ones ($0.30 against $3.00 per million).
The key idea is to keep prefixes stable. Any change to the prefix breaks the cache. One study cited in the vLLM Semantic Router paper found that placing cache blocks strategically, with volatile tool results excluded, cut API cost by 41–80% and improved time to first token by 13–31% compared with naively caching the full context.
How much does quantisation save, and what does it cost in accuracy?
Quantisation cuts latency and cost by storing weights, and often activations, in fewer bits, so less data moves through memory. Its impact varies with architecture and model size, and the best format is task and algorithm specific.
Which format. A large study of quantised Llama-3.1 models, covering more than 500,000 evaluations, found that INT4 weight-only quantisation (W4A16-INT) held up about as well as the 8-bit formats.
What it saves. W8A8 formats gave the highest throughput in asynchronous deployments. Quantising the KV cache is a separate lever. vLLM’s first FP8 KV-cache support reported 1.49x throughput on A100, at the cost of up to 2.4% accuracy on HumanEval-Python.
Why savings vary. Memory saved is not latency saved: memory bandwidth, hardware limits and the overhead of quantising and dequantising all sit between a smaller model and a faster one. A survey of quantisation methods notes that 4-bit integers could in principle cut memory footprint and latency 16x, but 4x to 8x is what is often achieved in practice. The speedup depends on on-chip memory, bandwidth and cache hierarchy.
PTQ or QAT. Post-training quantisation (PTQ) calibrates a trained model on a small data subset, with negligible overhead. It often loses more accuracy than quantisation-aware training (QAT), especially at low precision. QAT gets accuracy back by retraining, which can take hundreds of epochs. It is worth that cost mainly for a model that will be deployed for a long time, where both efficiency and accuracy matter.
FP16 should always be explored for GPU inference. PyTorch/Serve says it will most likely more than double speed on newer GPUs with tensor cores, with negligible accuracy loss. Beyond that, Databricks warns that naive quantisation can substantially degrade model quality, and that the effect varies by architecture and size. LynxBenchAI’s treatment of precision as an economic lever in inference systems works through quantised results in terms of cost and throughput.
Runtime choice, serving configuration and kernel work
The runtime is a lever because optimised engines provide operator fusion as well as quantisation. PyTorch/Serve lists ONNX Runtime, TensorRT, LightSeq and CTranslate2 among them. NVIDIA’s Triton documentation reports that applying TensorRT to an ONNX model doubled throughput and halved latency in its example, though the benefit varies by model. In Pham and Gedikli’s study, FP16 ONNX gave the lowest per-sample latency, with accuracy and F1 identical across variants. In the same study, even the optimised FP32 PyTorch variant more than doubled baseline throughput, just by dropping a convenience library that added overhead.
Serving configuration is a lever too. In Triton’s example, running two model instances instead of one raised throughput from about 73 to about 110 inferences per second, because memory transfers could overlap with compute. Moving to a different runtime or accelerator altogether is covered in porting AI inference across runtimes and hardware.
Kernel tuning covers operator fusion for kernels limited by execution, fused attention such as FlashAttention to cut memory traffic, and weight-only quantisation for memory-bound feed-forward layers.
Matching the profiled symptom to the first lever
| Profiled symptom | Likely constraint | Lever to try first | Watch for |
|---|---|---|---|
| GPU idle between requests, low utilisation at small batch | Batches not filling the device | Dynamic or continuous batching within the latency budget | Per-request latency rises with batch size |
| Throughput flat as batch size grows | DRAM bandwidth saturated in attention | Stop growing the batch; use the freed memory for model replicas | Replica gains were measured only on small OPT models |
| High time to first token on long, repeated prompts | Prefill recomputed for shared prefixes | Prefix caching plus cache-aware routing | No gain if prefixes differ or decode dominates |
| Slow token generation at small batch | Decode limited by memory bandwidth | Weight-only quantisation | Accuracy loss varies by model and task |
| Short and long requests sharing one pool | Mixed request lengths | Route or bin requests by length | Needs a usable length estimate |
| Model compute small relative to end-to-end time | Pre- and post-processing, padding or framework overhead | Fix tokeniser padding; leaner serving code; an optimised runtime | Measure end to end, not model-only |
Serving path or model: how to tell which one to change
Our position is that production features under cost or latency pressure rarely need a new model; usually the deployed serving path needs profiling and optimising. Replacing the model is the most expensive lever, and it often leaves the workload’s economics unchanged.
That does not mean model replacement is never right. Databricks’ model bandwidth utilisation metric (achieved memory bandwidth divided by peak) is one way to check: values near 100% mean the system is already using the bandwidth it has. Our breakdown of where inference spend lands across model, serving and overhead covers where that cost sits. Whether a given gain is worth the engineering time is a separate question, worked through in when inference cost optimisation justifies the engineering spend.
How do I know an optimisation actually helped in production?
An optimisation helped if the numeric target you set before the change improved when measured again. If the change made performance worse, revert it. For LLM serving, Databricks’ team tracks four key metrics:
- Time to first token (TTFT): includes queuing, prefill and network time.
- Inter-token latency (ITL), also called time per output token: describes decode.
- End-to-end latency: the full time to the last token.
- System throughput: tokens per second across all requests.
Report tail percentiles rather than averages, because the slow requests are the ones users notice. Pham and Gedikli’s evaluation, for example, collects latency percentiles and throughput under steady, bursty and high-intensity traffic.
The harder part is making sure a before-and-after comparison measures the server and not the harness. Before trusting a result, check these:
- Metric definitions are the same in both runs. GenAI-Perf leaves TTFT out of its ITL average, while LLMPerf includes it.
- The load generator is not the bottleneck. In a May 2026 study at 1,000 queries per second, single-process benchmarking tools added between 8 milliseconds and 58 seconds of artificial delay. A multi-process generator added 0.63 milliseconds.
- Sampling settings match. The same study measured a 21% throughput difference on identical hardware from temperature alone: 6,767 tokens per second at temperature 0 against 5,573 at 0.7.
- Cache hit ratio is reported. Prefix caching makes TTFT depend on request order, so the hit ratio has to be stated for every run.
- Output lengths are controlled. Set
ignore_eosso each run generates the intended number of tokens. - Concurrency is swept, not sampled once. Sweep from 1 to just above the maximum batch size. Throughput levels off there while latency keeps rising.
- The test runs on the deployment target. Databricks saw a 2x latency difference between 8xA100 servers from two cloud providers.
Cost per request ties these numbers together. Building that number is covered in cost per request as the production optimisation target.
Who can tune our inference serving path, or should we do it in-house?
Outside help pays off more where several services, runtimes or hardware targets interact and nobody owns the end-to-end trace. TechnoLynx’s Inference Cost-Cut Pack audit profiles the deployed serving path against a baseline and ranks which tuning levers to pull first (batching, caching, routing, quantisation or runtime) before any model replacement is recommended. How the audit runs is covered separately. Whoever does the work, ask to see the baseline and the measurement method before accepting any recommendation.
The audit looks at the serving path. If the open question is which hardware to buy, published benchmark results are a better starting point than a serving audit.
FAQ
Is performance tuning the same as fine-tuning a model?
No. Fine-tuning continues training a model on new data to change what it outputs. Inference performance tuning changes how the deployed model is served, so the same outputs arrive faster or more cheaply.