Learn which inference optimization techniques cut LLM latency and cost per token, from quantization and KV cache paging to continuous batching.

Takeaways
Inference optimization is the work of cutting latency, raising throughput, and lowering cost per token when a trained model serves real traffic, and the right technique depends on whether your bottleneck is prefill, decode, memory, queueing, or the network.
Inference optimization is the practice of improving the latency, throughput, and cost per token of a trained model once it serves production traffic. Training is a one-time bill, inference is the one you pay on every request, and the work happens on three layers: the model (quantization, distillation, pruning), the serving infrastructure (runtime, batching, cache management, placement), and the request path, meaning the queue and the network between your app and the GPU.
Most guides stop at the first two layers. The third is where a model that benchmarks well still times out.
Every request to a large language model runs in two phases, and LLM inference optimization starts with knowing which one you are waiting on:
That makes decode memory-bound. The arithmetic per step is cheap and the data movement is what you wait on, so a faster GPU helps decode less than moving fewer bytes does. Almost every technique in the next section targets decode for that reason, and it is why your machine learning inference bill tracks memory bandwidth more closely than peak compute.
AI inference optimization only works against a baseline. Record these five numbers first, and read TTFT vs end-to-end latency for how they differ in practice:
These metrics pull against each other. Bigger batches raise tokens per second, but every request waits longer to start, so TTFT rises. You pick an operating point under a latency target, and maximum throughput is rarely that point. Watch p99 and end-to-end latency, not averages, if you want to cut inference latency your users notice.
End-to-end latency is the metric to track because the model is only one stop on the path. As one Telnyx engineer puts it:

"There are a lot of very good products in this space, and many teams have done excellent work optimizing models, streaming, turn detection, and prompting. But in production, latency is often less about one slow model and more about the shape of the architecture: where the call enters, where media is anchored, where STT runs, where the LLM runs, where TTS runs, and how many vendor or cloud boundaries the audio crosses along the way." James Whedbee, VP of Engineering at Telnyx |
Compare tokens per second only between models that share a tokenizer. A different tokenizer turns the same text into a different number of tokens, so its tokens per second is a different unit.
Measure open-weight models before you tune them
The Telnyx Inference API serves open-weight models on in-region GPUs behind OpenAI-compatible endpoints, so you can record TTFT and p99 first.
Set your latency tradeoff with one field
Pick a serving tier per request on in-region GPUs, and pay up to 88% less for cached input tokens.
The LLM inference optimization techniques that matter either cut the bytes decode has to move or cut the work each token needs, and every one of them costs you something in accuracy, memory, or latency.
Which optimization fits your bottleneck?
GPU memory holds two things that decide how much traffic you can serve: the weights and the KV cache. In FP16 each parameter takes 2 bytes, so a 7B model needs about 14 GB for weights alone. The KV cache stores keys and values for every token in every layer, so its size per token is 2 x layers x hidden size x bytes per value. For a Llama 2 7B class model with 32 layers and a hidden size of 4,096, that is about 0.5 MB per token, or about 2 GB at 4,096 tokens and batch 1. Batch 2 doubles it, because the cache grows linearly with batch size and sequence length.
Each term has its own fix. Quantization shrinks the weights: weight-only INT8 or INT4 cuts the bytes decode reads on every step, while activations are harder to quantize because of outlier values. Post-training quantization (PTQ) is cheap, and quantization-aware training (QAT) holds accuracy better at the price of a training run. FP8, INT4, AWQ, and GPTQ are the common formats, and each needs an evaluation on your own prompts before it ships. Grouped-query attention (GQA) and paging shrink the cache instead, and Llama 2 70B uses GQA for that reason.
Older servers reserved one contiguous cache slot per request at its maximum length, so a 2,048-token slot for a 50-token answer wastes almost all of it. The PagedAttention paper names three kinds of waste: reserved space, internal fragmentation, and external fragmentation. PagedAttention removes them by storing the cache in fixed-size blocks tracked by a block table, the way an operating system pages memory.
Continuous batching, also called in-flight batching, spends that freed memory. Static batching makes every request wait for the longest one in its batch. Continuous batching evicts finished sequences and admits new ones at every step, so the GPU stays full and tokens per second per GPU rises.

The throughput-vs-latency rule: Doubling the batch roughly doubles tokens per second per GPU until memory runs out, but every request now waits for the batch to form, so TTFT rises. Set the batch size from your latency target, then buy throughput with more replicas or a different serving tier.
Speculative decoding runs a small draft model that proposes several tokens, and the target model verifies them in one parallel pass. When the draft guesses right, you get several tokens for the price of one decode step. Three things decide whether it pays off:
Prefix caching skips work you already did. It keeps the KV cache for a shared system prompt, tool schema, or conversation history and reuses it on the next request, so prefill runs only on the new tokens. For e-commerce AI agents and other agents that resend the same system prompt and tools on every call, that repeated prefill is a large share of the input bill.
Tensor and pipeline parallelism come in when the model does not fit one GPU. Both split it across devices to cut per-device memory, both add interconnect cost, and pipeline parallelism leaves idle bubbles while stages wait on each other. Find your bottleneck in the table and read across.
LLM inference optimization techniques by bottleneck and cost
| Technique | Phase or bottleneck it fixes | What it costs you |
|---|---|---|
| Quantization (INT8, INT4, FP8) | Decode memory traffic, weight footprint | Possible accuracy loss, needs evaluation |
| MQA or GQA | KV cache size | Needs training or uptraining |
| PagedAttention | KV cache fragmentation, batch size | Runtime support (vLLM) |
| Continuous batching | GPU utilization, throughput | Per-request TTFT rises as the batch fills |
| Speculative decoding | Decode latency at low batch | A draft model to run, gains fall at high batch |
| Prefix caching | Repeated prefill of shared prompts | Cache memory, cache-aware routing |
| Tensor or pipeline parallelism | Model does not fit one GPU | Interconnect cost, pipeline bubbles |
Apply them in order: record a baseline, quantize the weights, page the KV cache, batch continuously, then pick a serving tier or add replicas. Each step changes one number you can check against the last.
vLLM and llama.cpp are the two engines most teams run, and they apply these techniques for different workloads.
vLLM is built around PagedAttention and continuous batching, so the first win is on by default. It also supports tensor parallelism across GPUs. Our guide to vLLM inference explained covers the engine itself.
What you still tune are the operating-point levers: the share of GPU memory given to the KV cache, the maximum batched tokens and concurrent sequences, the quantization format of your checkpoint, prefix caching, and speculative decoding. Every one trades latency for throughput. More cache memory allows bigger batches, and bigger batches raise TTFT. The exact flag for each lever is in the vLLM documentation, which tracks the current release.

Change what you measured first: Giving the KV cache more memory raises throughput and TTFT together. If your complaint is p99 timeouts, look at queueing and batch limits before you quantize anything.
llama.cpp runs quantized weights on CPUs, Apple silicon, and single consumer GPUs. llama.cpp inference optimization is mostly two choices, the quantization level of the weight file and how many layers you offload to the GPU, plus context length and thread count. The names for each are in the llama.cpp repository README. It suits edge inference, local tools, and low-concurrency work where the model has to fit a small device. Side by side, the two engines split like this:
TensorRT-LLM, SGLang, and other engines make different tradeoffs again, and we cover them in inference engines compared.
Self-hosting pays while your GPUs stay busy and your team has time to maintain the stack. Three signals tell you it has stopped:
If two of them show up over a month, compare the same open-weight model behind an OpenAI-compatible managed endpoint, where autoscaling from zero takes the idle-GPU problem off your books.
The best platform for AI inference optimization lets you choose your latency-vs-throughput operating point per request instead of re-tuning a cluster, and Telnyx Inference is built that way. It serves a curated library of open-weight models, including models from z.ai, DeepSeek, and Minimax, as serverless inference on GPUs Telnyx owns, with OpenAI-compatible chat completions, so you change the base URL instead of rewriting code.
It costs up to 75% less than proprietary alternatives, with no GPU rental fees or minimums, and it supports structured output through JSON mode. The hosted model list shows the current lineup.
The choice comes down to who should own the inference infrastructure, and a short rule settles it:
On Telnyx, the same hosted model and context window run on different serving capacity, so the only things that change between tiers are latency and price. You choose with the service_tier field on each request:
That turns the batch-size tradeoff into a request field. Test interactive traffic on Priority, and compare providers on Default so the numbers match published benchmarks. Cached input is up to 88% off, which puts a price on prefix caching, and our guide to inference cost optimization shows how it adds up alongside the rates on inference API pricing.
"We often obsess over LLM inference speeds, but in Voice AI, the network is often the silent killer." Ian Reither, COO at Telnyx |
The request path is the layer most optimization work skips. Telnyx Inference runs in-region across the Americas, Europe, MENA, and APAC, with LATAM coming soon, so your data stays where your users are, with zero data retention and no training on your data. There are no inter-provider hops between your request and the model, and the service autoscales from zero to thousands of requests per second with no cold starts. Read more on running GPUs on the network.
This is an OpenAI-compatible chat completion sent to the Telnyx endpoint with a model name and one message. To choose a serving tier, add the service_tier field to the request body.
The model in the example is covered in Kimi K3 on Telnyx, and the AI gateway docs show how to route existing OpenAI SDK code to the same endpoint. From here you can name your bottleneck and pick your fix: tune it yourself in vLLM or llama.cpp, or change one field on a Telnyx request.
Inference optimization FAQ
How much can moving from a closed frontier model to an open-weight model cut our inference cost?
It depends on the model pair and your token mix, but the gap is large. Telnyx Inference lists open-weight models at up to 75% less than proprietary alternatives, and cached input at up to 88% off. Agents that resend the same system prompt on every call gain the most, because that repeated input is the part cached pricing discounts.
Why does the same open-weight model time out or run slower on one provider than another?
The weights are the same, but the serving stack is not. Providers choose different batch sizes, cache memory, quantization formats, and capacity, and requests cross different networks to reach the GPU. Bigger batches raise throughput and TTFT together, so a provider tuned for throughput can show p99 spikes your timeout catches. Compare providers on p99 and end-to-end latency, not average tokens per second.
Are open-weight models good enough to replace a closed model for production AI agents?
For many agent workloads, yes, but test it on your own traffic before you switch. Run your real prompts, tool calls, and output formats through the open-weight model, check accuracy, schema adherence, and latency against your current model, and move traffic in stages. Structured output features such as JSON mode help keep tool calls and formats consistent.
What is inference optimization?
Inference optimization is the work of cutting latency, raising throughput, and lowering cost per token when a trained model serves production traffic. It covers the model (quantization, distillation, pruning), the serving stack (batching, cache management, parallelism), and the request path between your app and the GPU. The right technique depends on which of those is your bottleneck.
Is inference optimization still worth doing, or will faster GPUs make it irrelevant?
It stays worth doing. Decode is limited by how fast memory moves bytes, and that improves more slowly than compute, so a faster GPU helps less than quantization or cache paging. Models and context windows also keep growing, which raises memory demand. And no GPU removes queueing delay or a network hop, so the request path still needs work.
Find your bottleneck, then tune it yourself or change the base URL and one field on a Telnyx request. OpenAI-compatible, in-region GPUs, up to 75% less than proprietary alternatives.
Start buildingRelated articles
GLM 5.3 Flash benchmark: Telnyx vs Modal

Real-time voice inference: where every millisecond goes on a live call

Edge inference: where to run AI models for low latency

What is call control? Direct, programmable control over every call

The best Vapi alternatives for low latency voice AI in 2026
What Is VoIP and How Does It Work
