home
diamond Go Premium
Data Engineering Path  ·  Data & AI

Chapter 9: Inference Optimization

+---------------------------------------------------------------------------------+
|                       WHERE DOES INFERENCE TIME GO?                             |
+---------------------------------------------------------------------------------+
|  Phase 1: Prefill (Prompt Processing) -> Compute-Bound (Processes all tokens)   |
|  Phase 2: Decoding (Token Generation) -> Memory-Bound (Reads weights every step)|
+---------------------------------------------------------------------------------+

The Memory Bandwidth Bottleneck

During the autoregressive decoding phase, an LLM must read every parameter in the model from GPU HBM (High Bandwidth Memory) into the tensor processing cores for each single generated token.

This means token generation speed is bottlenecked by memory bandwidth, not raw compute FLOPs!


Modern Inference Acceleration Techniques

1. KV Caching & PagedAttention (vLLM)

  • The Key-Value (KV) cache stores past token keys and values so attention doesn't recompute history on every step.
  • Traditional KV caches caused huge memory fragmentation.
  • PagedAttention (developed by Woosuk Kwon et al.) divides KV caches into virtual memory pages, enabling 2x to 4x higher concurrency on the same GPU.

2. Quantization (AWQ, GPTQ, INT4)

  • Reduces weight size from 16 bits to 4 bits.
  • Less bytes transferred over memory bus $\implies$ faster token decoding speed.

3. Speculative Decoding

  • A tiny, fast "draft model" (e.g. 1B parameter model) generates 5 candidate tokens speculatively in parallel.
  • The large 70B model verifies all 5 tokens in a single fast forward pass.
  • Yields 2x to 3x speedups with mathematically identical output distributions.
Find this content helpful? ☕ Buy me a coffee

Entity Details

Create New Item

help

Submit Technical Query

Have a question or run into an issue? Describe it below, upload an optional screenshot, and our engineering team will answer it!

image Attach image (optional)

Submit Feedback

build Free Developer Utility Free Tool
gavel

Privacy & Legal Disclaimer

1. Client-Side Browser Processing

All utility tools on DeepEngineerHub (including Image to PDF, Text Formatters, JSON Converters, and Encryptors) execute 100% locally within your client browser using WebAssembly and JavaScript. No uploaded images, text, or documents are transmitted, collected, or stored on remote servers.

2. Limitation of Liability ("As-Is" Provision)

Tools and services are provided free of charge for convenience and educational purposes "as-is" without warranties of any kind. DeepEngineerHub shall not be held liable for any data loss, formatting inconsistencies, or indirect damages resulting from tool usage.

3. Open Source & Third-Party Software

Certain utilities utilize open-source client libraries (such as jsPDF, Mermaid.js, Pyodide) licensed under MIT, Apache, or BSD open licenses. All intellectual property remains with their respective copyright holders.