Skip to content
ContentLora

    Tip: press / anywhere to search.

    Explainer

    How AI inference works: KV cache, batching, quantization and more

    Inference is running a trained model to produce an answer. Language models generate one token at a time, and decoding K tokens takes K runs of the model one after another,[1] so serving systems batch many requests together and manage the memory each one needs, the KV cache.[2] Quantization shrinks models to fewer bits per weight,[3] and speculative decoding speeds up generation without changing the output.[4]

    Editor reviewedUpdated Explainer9 claims · 0% primaryFrontier AI, Artificial intelligence, Computing
    Reading level: 4 passages differ; the rest is the same for everyone.

    This page is part of the Frontier AI course. Read test-time-compute first, on why reasoning models spend more computing power per answer. Next is mixture of experts, then state-space models. For how inference costs turn into prices, see how AI model pricing works.

    Inference means running a trained model to produce outputs, which for a language model means generating text token by token.[1] This page covers four ideas from the research behind AI serving systems: serial decoding, the KV cache and batching, quantization, and speculative decoding.

    One token at a time

    A language model writes its answer one token (a word or piece of a word) at a time. To produce the next token it runs the whole model again, so a 1,000-token answer needs 1,000 runs in a row.[1]

    Autoregressive decoding is inherently serial: decoding K tokens takes K sequential forward passes.[1] Very large models may not even fit on one machine: the Llama 3 report says its 405-billion-parameter model does not fit in the memory of a single eight-GPU H100 server, so Meta served it in BF16 across 16 GPUs on two machines, with tensor parallelism inside each machine and pipeline parallelism between them.[5]

    The KV cache and batching

    To avoid redoing work, the model remembers intermediate results for every token it has already seen, in a store called the key-value (KV) cache. Serving many users at once, called batching, uses the chips more efficiently, but every request’s cache takes memory, and that memory limits how many requests fit at once.[2]

    The vLLM paper (SOSP 2023) frames serving as a memory-management problem: throughput requires large batches, but each request’s KV cache is huge and changes size dynamically, so fragmentation and duplication waste memory and cap the batch size.[2] Its PagedAttention algorithm borrows virtual-memory paging from operating systems, and the authors reported near-zero KV-cache waste and 2 to 4 times higher throughput than earlier systems at the same latency.[6]

    Quantization: fewer bits per number

    Quantization stores a model’s numbers with fewer bits, such as 8 or 4 instead of 16, so the model needs less memory and can run on fewer chips. Done carefully, accuracy barely changes.[7][3]

    The LLM.int8() paper (NeurIPS 2022) reports halving inference memory with 8-bit matrix multiplication and no loss of performance for models up to 175 billion parameters.[7] Its key finding was systematic outlier features: the method keeps those dimensions in 16-bit while more than 99.9% of values are multiplied in 8-bit.[8] GPTQ (ICLR 2023) reports going to 3 or 4 bits per weight for 175-billion-parameter models in about four GPU hours with negligible accuracy loss, fitting such a model on a single GPU, and reported speed-ups over FP16 of about 3.25 times on A100 GPUs.[3]

    Speculative decoding

    A small, fast model guesses the next few tokens, and the big model checks all the guesses at once. When the guesses are right, several tokens are produced for the price of one big-model run. The final text is exactly what the big model would have written anyway.[4]

    Speculative decoding (ICML 2023) runs the large model in parallel on the outputs of a cheaper approximation model, with a sampling scheme that leaves the output distribution unchanged. The authors reported a 2 to 3 times speed-up on T5-XXL with identical outputs and no retraining or architecture changes.[4]

    What is known and what is open

    Known: the techniques above are published in peer-reviewed venues, with measured gains on the models their authors tested.[6][3][4] Inference cost is also shaping architecture research: NVIDIA’s Nemotron-H report links its hybrid design to the growing cost of inference-time reasoning.[9]

    Open questions this page does not settle: how much each technique saves on a given commercial service, since the gains above were measured by the papers’ authors on the models and hardware they tested.

    Next in the crash course

    More in Frontier AI

    Questions readers ask

    What is AI inference?

    Running a trained model to get outputs. For language models that means generating text one token at a time, and decoding K tokens takes K serial runs of the model.[1]

    What is the KV cache?

    Memory a serving system keeps for each request, holding the attention keys and values of earlier tokens. The vLLM paper notes it is huge, grows and shrinks as text is generated, and limits how many requests can be batched.[2]

    What does quantization do?

    It stores a model's weights with fewer bits. The GPTQ paper reports reducing 175-billion-parameter models to 3 or 4 bits per weight with negligible accuracy loss, and the LLM.int8() paper reports halving inference memory with 8-bit arithmetic.[3][7]

    Does speculative decoding change the answer?

    No. The method samples from the large model's own distribution; its authors reported 2 to 3 times faster decoding on T5-XXL with identical outputs.[4]

    Sources

    · 9 claims from 6 publishers

    Each numbered claim is a statement we checked against the sources listed with it. Tap a number in the text to see its sources in place.

    1. [1]

      The 2023 speculative decoding paper (ICML) notes that inference from large autoregressive models like transformers is slow because decoding K tokens takes K serial runs of the model. reportedas of 2026-11-22

    2. [2]

      The vLLM paper (SOSP 2023) says high-throughput LLM serving requires batching many requests at once, but the key-value (KV) cache memory for each request is huge and grows and shrinks dynamically, so wasted memory limits the batch size. reportedas of 2026-11-22

    3. [3]

      The GPTQ paper (ICLR 2023) reported quantizing 175-billion-parameter GPT models to 3 or 4 bits per weight in about four GPU hours with negligible accuracy loss, enough to run such a model on a single GPU, with inference speed-ups over FP16 of about 3.25 times on NVIDIA A100 GPUs. reportedas of 2026-11-22

    4. [4]

      Speculative decoding uses a smaller, faster approximation model to propose tokens that the large model checks in parallel; the ICML 2023 paper reported a 2 to 3 times speed-up on T5-XXL with identical outputs and no retraining. reportedas of 2026-11-22

    5. [5]

      The Llama 3 report says the 405-billion-parameter model does not fit in the GPU memory of one machine with eight H100 GPUs, so Meta ran inference in BF16 across 16 GPUs on two machines, using tensor parallelism within each machine and pipeline parallelism across them. reportedas of 2026-11-22

    6. [6]

      The vLLM paper introduced PagedAttention, modelled on virtual memory and paging in operating systems, and reported near-zero KV cache waste and 2 to 4 times higher throughput than earlier systems at the same latency. reportedas of 2026-11-22

    7. [7]

      The LLM.int8() paper (NeurIPS 2022) reported 8-bit matrix multiplication for transformer layers that halved the memory needed for inference while keeping full-precision performance, for models of up to 175 billion parameters. reportedas of 2026-11-22

    8. [8]

      The LLM.int8() authors found systematic outlier features in large transformers and handled them by keeping those dimensions in 16-bit arithmetic while more than 99.9% of values were multiplied in 8-bit. reportedas of 2026-11-22

    9. [9]

      NVIDIA's Nemotron-H report links the interest in efficient architectures to inference-time scaling for reasoning, saying it is increasingly important to build models that are efficient to run. reportedas of 2026-11-22

    Revision history (1)
    1. Page created.

    Created Nov 22, 2026. Last reviewed by an editor on Nov 22, 2026. Next scheduled review: Jun 28, 2027.

    Cite this page

    "How AI inference works: KV cache, batching, quantization and more." ContentLora, updated Nov 22, 2026. https://contentlora.com/explain/how-ai-inference-works

    Spotted an error? Suggest a correction or emailcorrections@contentlora.com.