Inside LLMs #1 — The Anatomy of an LLM Response
Summary
This article details the internal process of Large Language Model (LLM) inference, dissecting the journey from prompt submission to response generation. It introduces two key metrics: Time To First Token (TTFT), covering initial processing, and Time Per Output Token (TPOT), measuring subsequent token generation speed. The process begins with network and authentication overhead, typically 80-150 ms, followed by queuing. The core inference involves "prefill," a compute-bound stage where the entire prompt is processed in parallel to create a KV cache, directly impacting TTFT. Subsequently, "decode" is a memory-bandwidth-bound stage where tokens are generated sequentially, one at a time, relying on the KV cache. GPUs excel at prefill's parallel compute but struggle with decode's memory-intensive, sequential nature. The article notes that network RTT, security checks, and decode's inherent sequentiality are fundamental, unoptimizable limitations.
Key takeaway
For AI Engineers optimizing LLM inference, understanding the distinct prefill and decode stages is crucial. You should focus on compute optimization for Time To First Token (TTFT) during prefill, and memory bandwidth optimization for Time Per Output Token (TPOT) during decode. Recognize that network latency and decode's sequential nature are fundamental limits, guiding your efforts towards areas like KV cache and FlashAttention for tangible gains.
Key insights
LLM inference involves compute-bound prefill for TTFT and memory-bandwidth-bound, sequential decode for TPOT, each with distinct bottlenecks.
Principles
- Prefill is compute-bound, maximizing parallel throughput.
- Decode is memory-bandwidth-bound and sequential.
- TTFT equals queue time plus prefill time.
Topics
- LLM Inference
- Time To First Token
- Time Per Output Token
- Prefill Stage
- Decode Stage
- KV Cache
- GPU Bottlenecks
Best for: Machine Learning Engineer, AI Engineer, AI Architect
Related on AIssential
See Counsel's argued verdicts on the open AI decisions leaders are weighing →
Editorial summary, takeaway, and curation by AIssential. Original article published by Artificial Intelligence on Medium.