Inside LLMs #1 — The Anatomy of an LLM Response

· Source: Artificial Intelligence on Medium · Field: Technology & Digital — Artificial Intelligence & Machine Learning · Depth: Intermediate, medium

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

Topics

Best for: Machine Learning Engineer, AI Engineer, AI Architect

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by Artificial Intelligence on Medium.