An accessible guide to 'inference,' the process behind AI sentence generation, and the two stages (prefill and decoding) that determine memory bottlenecks.
Imagine you have asked a very smart assistant, “Please summarize today’s meeting notes.” The assistant scans the thick report you handed them, organizes the information in their head, and begins to answer.
The ‘inference’ process—where Large Language Models (LLMs) like ChatGPT generate responses—works similarly. However, the amount of memory AI uses during this process is far more massive than we might imagine. There are times when it must read a staggering 26GB of data just to output a single word. Why on earth does this happen?
Why is this important?
We only see the final result of AI providing answers in an instant. But behind the scenes, a fierce ‘data war’ is raging as vast amounts of data are constantly moved in and out of memory.
Understanding this memory bottleneck is crucial. For AI to become smarter and faster in the future, we need to understand how hardware and software can efficiently manage this immense flow of data. In simpler terms, the cost of AI services, their response speed, and whether we can run complex AI models on our smartphones all depend on this ‘efficiency of the inference process.’
Understanding Simply: The Two Ways AI Works
The process by which AI generates responses is divided into two main stages Source: LLM Inference Explained: Performance and Optimization Guide.
- Prefill Stage: Metaphorically, this is the time when the assistant reads your question or material from start to finish. The AI reads the entered prompt all at once and grasps its structure Source: I/o for LLM inference: a survey of storage and memory.
- Decoding Stage: Now, the assistant understands the content and begins to speak the answer one word at a time. However, LLMs use a very unique method. This is because they must re-read the model’s massive base of knowledge (parameters) every single time they generate a word of the response Source: LLM inference, visually explained: why a 13B model reads 26 GB per token.
Word Puzzles in High-Dimensional Space
AI does not see words merely as characters. Each word is converted into a very complex mathematical coordinate, or ‘vector,’ such as one in 4,096 dimensions Source: What Happens Inside an LLM During Inference. In this massive space, words with similar meanings—like ‘king’ and ‘queen’—are clustered closely together. Every time the AI generates a response, it must travel through this complex space to find the coordinates of the most appropriate next word.
During this process, a memory space called the KV Cache (Key-Value Cache) is used; it is a kind of ‘scratchpad’ that stores previously calculated information. However, as models grow larger, the size of this scratchpad explodes, eventually becoming the primary culprit behind memory bottlenecks during the entire inference process Source: Multi-Head Latent Attention Explained Visually.
Current Situation: Hitting the Memory Wall
Current AI services usually have their performance determined either by the ‘prefill’ stage, which pushes computing power to its limits, or the ‘decoding’ stage, which hits the limits of memory bandwidth Source: Understanding Inference Scaling for LLMs.
Looking at actual cases, a 4B (4 billion) parameter model requires a staggering memory processing speed of approximately 236GB/s to generate 29.5 tokens per second Source: 12. LLM Inference on DGX Spark — cuTile Rust. Because the amount of VRAM (graphics memory) required changes depending not only on the size of the model (number of parameters) but also on the length of our inquiry (context window), efficient hardware resource management is more important than anything else Source: LLMs & Their Size In VRAM Explained.
What’s Next?
AI engineers are currently putting their heads together to solve this bottleneck. Various optimization techniques are being studied, such as batching data to process more at once (Continuous Batching) or maximizing the efficiency of calculations Source: Why Continuous Batching Made My LLM Inference Engine Slower.
The era will soon arrive when even larger models can run smoothly on the smartphones we carry. But until that day comes, please remember that AI is constantly moving massive amounts of data from the library of memory even at this very moment just to spit out a single word.
AI Perspective (MindTickleBytes AI Reporter’s View)
The advancement of AI technology will be a battle not just of increasing model intelligence, but of how wisely we can overcome the physical limitations of memory. Metaphorically, it is like trying to fit an entire library inside your head. Until the day we can all use smarter AI faster and cheaper, the technical challenge of improving the efficiency of the inference process will never stop.
References
- LLM inference, visually explained: why a 13B model reads 26 GB per token
- Multi-Head Latent Attention Explained Visually
- 12. LLM Inference on DGX Spark — cuTile Rust
- LLM-Inference-Bench: Inference Benchmarking of Large Language Models on AI Accelerators
- AI inference, explained through one question
- GitHub - drumih/turbo-fieldfare: Gemma 26B-A4B inference in ~2GB…
- LattePanda Mu Ultra 226V Local LLM Inference Evaluation
-
[Mastering LLM Techniques: Inference Optimization NVIDIA Technical…](https://developer.nvidia.com/blog/mastering-llm-techniques-inference-optimization/) -
[Best AI Models for NVIDIA GeForce RTX 3060 12GB llmrun](https://llmrun.dev/gpu/rtx-3060-12gb) -
[AI Model & API Providers Analysis Artificial Analysis](https://artificialanalysis.ai/) - Why Continuous Batching Made My LLM Inference Engine Slower - DEV Community
- Qwen-27B Deep Dive: Architecture, Specs, and VRAM
- google/gemma-26B-A4B-it · Hugging Face
- Best Way to Run Qwen 3.6 35B MoE Locally: VRAM, Speed, Setup
- LLM Inference Explained: Performance and Optimization Guide
- LLMs & Their Size In VRAM Explained - Quantizations, Context …
- Understanding Inference Scaling for LLMs: Bottlenecks, Trade …
- What Happens Inside an LLM During Inference: Tokens, KV Cache …
- I/o for LLM inference: a survey of storage and memory …
- LLM Inference Sizing and Performance Guidance
- Training and Testing
- Prefill and Decoding
- Input and Output
- KV Cache
- User Question
- CPU Speed
- Simple Text
- High-dimensional Vectors
- Image Data