Skip to content
Global sound
Learn AI in Bits

Learn AI in Bits

081 - How Does AI Inference Work?

· 8 min · Season 1 Episode 81

Show notes

When you type a question into an AI assistant and watch the answer appear word by word, what's happening underneath is inference: the process of running a trained model to produce that answer. This episode follows one request through the full inference path, from tokenization to the KV cache to production serving.

A prompt is first assembled with any system instructions, conversation history, and context, then converted by a tokenizer into token IDs. The model processes that token sequence through its transformer layers, including attention, producing logits, which are scores for every possible next token. A decoding step turns those scores into a choice, whether through greedy decoding, which picks the top score, or sampling methods shaped by settings like top-k, top-p, and temperature. The model generates output one token at a time this way, rather than retrieving a complete answer from a database.

The episode explains the prefill and decode split: prefill processes the input prompt and builds attention state, while decode generates output tokens one at a time, reusing that state through the key-value cache, or KV cache, so the model doesn't have to recompute previous context on every step. It distinguishes time to first token from inter-token latency, and explains how the KV cache becomes a major memory consideration as conversations and concurrent requests grow, which is why serving systems manage cache allocation, batching, and sometimes prefix reuse across requests.

Zooming out to production, the episode covers how inference engines schedule and batch requests across accelerators, how quantization trades precision for memory and speed, and why practical performance is measured in latency, throughput, memory use, and cost per token rather than benchmark scores alone. It also distinguishes the model's inference step from the rest of an application's pipeline, including retrieval, safety filters, and multimodal input encoding, and closes with a key clarification: running inference on a deployed model doesn't mean it's learning from your conversation as it happens, since that depends entirely on the service's own data and training policies.

Sources & References
NVIDIA TensorRT Model Connect: Inference Fundamentals — https://github.com/NVIDIA/TensorRT-Model-Connect/blob/main/website/docs/getting-started/inference-fundamentals.md
vLLM: Inside vLLM: Anatomy of a High-Throughput LLM Inference System — https://vllm.ai/blog/2025-09-05-anatomy-of-vllm
vLLM Documentation: Disaggregated Prefilling (experimental) — https://docs.vllm.ai/en/latest/features/disagg_prefill/
NVIDIA Technical Blog: Optimizing Inference for Long Context and Large Batch Sizes with NVFP4 KV Cache — https://developer.nvidia.com/blog/optimizing-inference-for-long-context-and-large-batch-sizes-with-nvfp4-kv-cache

Voice narration is AI-generated.

Website: podcasters.spotify.com

Live, last hour: 2,773 songs on 7,706 stations in 142 countries

Discover the world through radio

More ways to discover (9)

Heard something good? Save it, or open it straight away in Spotify.

Radio 538 luisteren - Live!Popular right now