Archive | Inference from Transformer Models

jonny-gios-FRc6Wz2tAjk-unsplash

KV Cache Memory Management

Every active sequence keeps keys and values from earlier tokens so decode can attend to them without recomputing the whole prompt. This KV cache grows with the retained sequence length. A serving engine must place it, share it when safe, and reclaim it promptly. Attention Variants and Memory Efficiency calculated the cache required by different […]

Continue Reading
taylor-floyd-mews-5CY9gTo0rJk-unsplash

Anatomy of an LLM Serving Engine

Calling model.generate() is enough for one local prompt. A service also has to accept requests, decide when they may run, retain state while they run, stream results, and release resources when they finish. Those tasks continue even when the model and decoding algorithm stay the same. This post follows one request through a serving engine. […]

Continue Reading
mike-erskine-FBzCVmJcVoY-unsplash

Long-Context Inference

A model may accept a long context without serving it efficiently or using it reliably. Long prompts increase prefill work, KV cache memory, and time to first token. They can also delay short requests that share the same accelerator. Long-context inference first requires a model that supports the intended sequence length. Positional encodings and the […]

Continue Reading
k-mitch-hodge-plDqAUdS-68-unsplash

Prefix Caching and Prompt Reuse

Many requests begin with the same tokens. They may share a system prompt, tool definitions, a long document, few-shot examples, or an earlier conversation. Running prefill over that prefix every time repeats the same work. Prefix caching stores the KV cache produced for a token prefix and reuses it when a later request begins with […]

Continue Reading
ann-maree-hannon-3iICWN_Nmhs-unsplash

Speculative Decoding

Autoregressive decoding normally asks the target model for one token at a time. This is inefficient when each step reads a large set of weights but performs little parallel work. Speculative decoding uses a cheaper process to propose several tokens, then asks the target model to verify them together. Verification is the essential step. Greedy […]

Continue Reading
robert-bye-ymX6FQ6dAZI-unsplash

Decoding Policies in a Serving Engine

Decoding Strategies and Output Control explained how greedy decoding, sampling, beam search, stopping rules, and output constraints select tokens. This post focuses on what those choices cost in an inference engine. A decoding policy can add work after every model call, create several live sequences for one request, keep KV cache blocks alive for longer, […]

Continue Reading
kutan-ural-MZPwImQUDM0-unsplash

Model Compression Beyond Quantization

Quantization changes how model values are represented. Other compression methods reduce the number of values or the size of model structures. Pruning removes weights or structures, while knowledge distillation trains a smaller student to reproduce a teacher’s behavior. Serving a smaller model is often an effective inference optimization. It reads fewer weights and may use […]

Continue Reading
bruno-martins-DrhYt-kAe9s-unsplash

Activation and Floating-Point Quantization

Weight-Only Quantization focused on weights, which are fixed after training and can be quantized once before deployment. This post turns to tensors created during inference. Activations depend on the input token, sequence position, and previous layers. Their ranges can change from request to request, and a few channels may contain persistent outliers. This makes activation […]

Continue Reading
connor-wang-r89Sdde8W3o-unsplash

Weight-Only Quantization

During autoregressive decoding, a transformer reads its weights for every new token. At small batch sizes, moving these weights can take more time than computation. Quantization reduces this cost by storing weights with fewer bits. For example, an INT8 weight uses half the raw storage of an FP16 or BF16 weight. Quantization can also make […]

Continue Reading

Machine Learning Mastery is part of Guiding Tech Media, a leading digital media publisher focused on helping people figure out technology. Visit our corporate website to learn more about our mission and team.