LLM Inference Optimization: Every Lever That Makes Serving Faster, Measured on Real GPUs
What is LLM inference optimization?
LLM inference optimization means getting more good tokens from every GPU hour without making anyone wait too long, by changing how the model is served rather than what it says. The main levers are continuous batching, a paged KV cache, prefix caching, chunked prefill, quantization, speculative decoding, tensor parallelism and request routing. On a rented RTX 4090, batching alone took Qwen3-8B from 57 tokens a second for one person to 1,161 for 32 people at once. Measure first, because each lever trades one number for another.
Answer last checked
Save your progress and get the AI Engineering cheat sheet PDF
This guide answers 13 questions about LLM inference optimization: where the time goes in a request, and what each lever does to it, from continuous batching and the KV cache to quantization, speculative decoding, tensor parallelism and routing. Every number comes from Hands-On Inference Engineering, measured on rented NVIDIA GPUs, mostly with vLLM; each answer links to the lesson and to our page that explains that lever in full.
13 questions · 3 sections · answers from the course
These answers come from our course Hands-On Inference Engineering: Serve LLMs on GPUs with vLLM and SGLang: 74 lessons ready so far, each one run and measured on a rented NVIDIA GPU. The first lessons are free to read, with no card needed.

The short version
Decode is limited by memory speed and prefill by arithmetic, and the room for the KV cache decides how many people fit. Batching and a paged cache fill the GPU; prefix caching and chunked prefill protect waiting times; quantization buys room; speculative decoding helps at low load; tensor parallelism fits big models; a router spreads work across servers. Pick by the number you need to move, and measure it at your real load.
Readers in India pay in rupees; readers in the US, UK, Singapore, Australia and the Gulf see US dollar prices and can pay by card or PayPal. The pages for your region: India, Singapore, Australia, the Gulf and UK and Europe.
If this helped, the full hands-on course goes much deeper.
In the course you rent NVIDIA GPUs and turn every one of these levers yourself in vLLM, from batching and the KV cache to quantization, speculative decoding, tensor parallelism on two H100s and the llm-d router, measuring each change.
1. What LLM inference optimization means
Inference is running a trained model to answer requests. Optimizing it means more good tokens from every paid GPU hour without making any one person wait too long. Three answers set up the map.
What is LLM inference optimization?
It is the set of changes that make a model server answer faster, answer more people at once, or fit a bigger model on the same GPUs, without changing what the model says. The common levers are continuous batching, a paged KV cache, prefix caching, chunked prefill, quantization, speculative decoding, splitting a model across GPUs, and routing between servers.
Most of them are already built into model servers such as vLLM and SGLang. The engineering work is knowing which lever moves which number, turning the right settings, and measuring the result on your own traffic.
Where does the time go in one LLM request?
Into two halves. Prefill reads the whole prompt in one pass and writes the KV cache, the model's notes on every token. Decode writes the answer one token at a time, and each step reads all of the model's weights from memory again.
On a rented RTX 4090, one short request took 93.6 ms: 35.2 ms to read 25 tokens and 58.4 ms to write 22, about 2.8 ms a token. Reading took about 38% and writing 62%, though the question and answer were about the same length. Decode is usually limited by memory speed, prefill by arithmetic, so the levers differ.
What we measured: One request on an RTX 4090 with llama-server: 93.6 ms in all; prefill 25 tokens in 35.2 ms, decode 22 tokens in 58.4 ms.
Which numbers should I measure before optimizing?
Four: time to the first token (how long a person waits before anything appears), the pause between tokens (how smoothly it streams), tokens a second for one person, and tokens a second for the whole server. Look at the 90th or 99th percentile, not only the middle, because a few long prompts hurt the slow end first.
Most levers trade one of these for another. Batching raises the server's total and lowers each person's speed; a larger chunked-prefill budget helps the first token and hurts the pauses. Decide your promise to users first, such as at least 40 tokens a second for a typical person, then optimize up to it.
Lesson: Batching: serving many people at once, and what each pays
2. The levers on one GPU
These are the levers inside one model server. Each answer gives the effect we measured on a rented GPU and links to the page that explains the lever in full.

How much does batching help LLM inference?
A great deal, because one read of the weights can write the next token for everyone in the batch. On an RTX 4090 with Qwen3-8B, one person at a time got 57 tokens a second; 32 people at once got 1,161 in total, 20.2 times as much, and each kept 69% of their own speed.
Past the KV cache's limit it stops paying: at 64 people the total rose only 16%, each person wrote at about half speed and the 99th percentile wait for the first word was 8.69 seconds. Continuous batching, which lets a finished request leave and a new one join at every step, finished the same 48 answers in 16.83 s instead of 24.33 s in fixed batches. Our continuous batching page goes through it in full.
What we measured: Qwen3-8B, RTX 4090: 57 tokens a second for one person, 1,161 for 32; 48 answers in 24.33 s with fixed batches, 16.83 s with continuous batching (354 against 511 tokens a second).
Lesson: Batching: serving many people at once, and what each pays
How do PagedAttention and the KV cache limit how many users fit?
Every conversation needs room for its KV cache, and that room, not the arithmetic, decides how many people one GPU serves. PagedAttention stores the cache in pages of 16 tokens taken only as a conversation grows, so nothing is reserved for a length a conversation never reaches.
On the RTX 4090, vLLM had 2,076 pages, 33,216 tokens of room, after loading Qwen3-8B. 64 conversations of about 340 tokens filled 66.8% of it. Our KV cache size page works out the room per model, and the PagedAttention page shows how the pages work.
What we measured: vLLM 0.33, Qwen3-8B, RTX 4090: 2,076 pages of 16 tokens, 33,216 tokens; 64 conversations filled 66.8%.
How much does prefix caching save?
When many requests start with the same tokens, such as a long system prompt or a shared document, the server can keep that start's KV cache and skip reading it again. With eight questions behind the same handbook of about 2,970 tokens, vLLM found 87% of the prompt tokens in its cache: the first question's first word came after 391 ms and the other seven after 44 to 47 ms.
It only works for an exactly matching start, so one changing line at the top, such as a timestamp, breaks it. Our prompt caching page has the full rules for OpenAI, Claude and vLLM.
What we measured: vLLM 0.33, Qwen3-8B, RTX 4090: 87% of prompt tokens found in the cache; first word 391 ms for question 1, 44 to 47 ms for questions 2 to 8.
What does chunked prefill fix?
A long prompt read in one step freezes everyone else's answer, because a step cannot be interrupted. In our run, eight people were getting a word every 18 ms when someone pasted a 12,563-token handbook. With a step budget of 16,384 tokens, nobody got a word for 1,499 ms.
Chunked prefill reads a long prompt in slices and keeps writing for the others between slices. vLLM's default budget of 2,048 tokens cut the longest pause to 300 ms, and 512 to 209 ms. A smaller budget smooths the pauses; a larger one gives long prompts their first word sooner.
What we measured: Qwen3-8B, RTX 4090, 12,563-token prompt among 8 streaming answers: longest pause 1,499 ms at a budget of 16,384, 300 ms at 2,048, 209 ms at 512; usual pause 18 ms.
Lesson: Chunked prefill: one long prompt without freezing everyone
Does quantization make LLM inference faster?
It frees memory first and speed second. Storing Qwen3-8B's weights in 8 bits (FP8) raised the room for conversations on the RTX 4090 from 33,216 tokens to 78,880, and 4-bit weights (W4A16) to 104,960. For one person the 4-bit copies wrote about 2.56 times as fast, because there are fewer bytes to read each step; with 64 people the lead shrank to about 1.75 times.
The KV cache can be stored in 8 bits too: that gave 59,856 tokens against 38,000, 1.58 times as many. Quality must be checked separately, because these runs measured room and speed, not answers. Our quantization questions page goes deeper.
What we measured: Qwen3-8B, RTX 4090: KV cache room 33,216 tokens (16-bit), 78,880 (FP8), 104,960 (W4A16); 4-bit about 2.56x for one person, 1.75x at 64; fp8 KV cache 59,856 against 38,000 tokens.
When does speculative decoding speed up an LLM?
When the GPU is waiting on memory, which is the case with few people. A cheap guesser proposes several tokens and the model checks them in one pass, so accepted guesses come almost free and the answer is unchanged. In vLLM, n-gram guessing made an answer that copied its question 3.57 times as fast, and EAGLE-3 made every answer about two to two and a half times as fast.
With many people a step is already busy, so guesses stop being free. At 64 people, EAGLE-3 still gave 40% more tokens a second, but a small draft model lost 31% and n-gram lost 49%. Measure at your real load; our speculative decoding page explains why.
What we measured: vLLM 0.33, Qwen3-8B, RTX 4090: n-gram 3.57x on a copying answer; EAGLE-3 about 2 to 2.5x for one person; at 64 people EAGLE-3 +40%, draft model -31%, n-gram -49%.
Lesson: Speculative decoding in vLLM: n-gram, a draft model, EAGLE-3
If this helped, the full hands-on course goes much deeper.
In the course you rent NVIDIA GPUs and turn every one of these levers yourself in vLLM, from batching and the KV cache to quantization, speculative decoding, tensor parallelism on two H100s and the llm-d router, measuring each change.
3. The levers across many GPUs
When one GPU is not enough, the choice is between splitting one copy of the model across GPUs and running several copies behind a router.
What is tensor parallelism, and how much does it help?
Tensor parallelism splits every layer of the model across GPUs, so each holds a slice of every layer and half the KV cache, and the GPUs exchange results twice in every layer. It is how a model too big or too tight for one GPU is served as one copy.
On two H100s joined by NVLink, Qwen3-32B went from 27,936 tokens of room on one card to 310,400 on two, 11.1 times, because one card had barely fitted the weights. Speed grew less than the GPU count: 1.79 times for one person and 1.69 times at 64 people. For Qwen3-8B, which fits one card easily, room grew 2.28 times and speed 1.54 and 1.35 times.
What we measured: Two H100s with NVLink, vLLM: Qwen3-32B room 27,936 -> 310,400 tokens, speed 1.79x (one person) and 1.69x (64); Qwen3-8B room 2.28x, speed 1.54x and 1.35x.
Should I split a model across GPUs or run several copies?
Split it when it does not fit one GPU with enough room for conversations; that is where tensor parallelism pays most, as the 11.1 times more room for Qwen3-32B showed. If the model fits one GPU with room to spare, separate copies usually give more total tokens, because they never wait for each other, and the gain from splitting a small model was only 1.35 times at 64 people.
Our GPU memory page works out, per model, how much memory one card needs.
How does routing help when I run several model servers?
A plain load balancer picks a server at random and never sees a request's size, a server's queue or what it has cached. An inference-aware router chooses for each request. On four simulated servers with uneven traffic, the llm-d router cut the 90th percentile wait for a short question's first word from 2,688 ms through a Kubernetes Service to 674 ms.
Those servers were a simulator: where each request went is measured, the times come from a formula built on our RTX 4090 recordings. Our llm-d page explains how that router decides.
Which inference optimization should I try first?
Start with what the server already does for free: run vLLM or SGLang, which have continuous batching, a paged KV cache, prefix caching and chunked prefill on by default, and put the fixed part of every prompt first so prefix caching can work. Then measure your four numbers at your real load.
If you run out of room for conversations, quantize the weights or the KV cache. If one person's speed is the problem at low load, try speculative decoding. If the model does not fit, split it with tensor parallelism. When you have several servers, route by cache and load. Our SGLang vs vLLM and tokens per second pages compare engines and per-person speed.
Where to go next
If this helped, the full hands-on course goes much deeper.
In the course you rent NVIDIA GPUs and turn every one of these levers yourself in vLLM, from batching and the KV cache to quantization, speculative decoding, tensor parallelism on two H100s and the llm-d router, measuring each change.
Every number on this page comes from Hands-On Inference Engineering: Serve LLMs on GPUs with vLLM and SGLang, where you rent the GPU yourself, run each command and compare your numbers with ours. Start with the free introduction and the free lessons on prefill and decode and the KV cache. If you are also preparing for interviews, the two big courses together and the Inference Engineering interview pack are below.
These questions are a start. The interview asks more.
Get all 120 questions in the Inference Engineering pack
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (141 diagrams in all). A PDF you keep, junior to staff level.
Pay by UPI, cards or netbanking through Razorpay. Pay by card or PayPal, in US dollars. Download at once from My packs.
