Last year, I picked up an engineering book after a long time. It was AI Engineering by Chip Huyen. The book covers the core concepts of AI engineering, from training and evaluating models to prompt engineering and agents. While a lot of things in the AI world get the limelight and fade away quickly, the core concepts and technology remain mostly the same.
One of the most interesting chapters for me was about inference optimization. It is a small chapter towards the end of the book. It probably wasn't the hottest topic when the book was written, but it seems to have entered the hype cycle recently. And for good reason.
What is Inference?
In simple terms, there are two major phases in the lifecycle of an AI model. The first is training, where a huge amount of data is processed to teach the model new knowledge, patterns, and capabilities. The output of this stage is a set of model weights. Think of it as a giant collection of numbers, sometimes taking up tens of GBs of storage.
The second phase is inference. This is when the trained model is deployed in the real world, where it processes user prompts and generates responses. The model weights are loaded onto hardware like GPUs, which perform a lot of matrix multiplications needed to generate an answer. While this sounds fairly simple, it turns out to be a very complex engineering problem.
Why is Inference Important?
Training a model is a massive but one-time expense. Inference, on the other hand, is a recurring cost that grows with every user, every query, and every AI agent. It also directly affects the user experience. Nobody wants to wait 30 seconds for a chatbot to respond. With the rise of AI agents and longer-running tasks, the demand for inference is growing rapidly. The advancement of open models has pushed this further, with more organizations choosing to run models on their own infrastructure or through specialized inference providers.
To put things into perspective, DeepSeek reported that training DeepSeek-V3 required around 2.8 million H800 GPU-hours. Later, its reported serving costs for V3/R1 implied roughly 43,000 H800 GPU-hours every day. At that rate, just over two months of inference would consume as many GPU-hours as the original V3 training run. That's how quickly inference costs can add up.
Why is Inference So Complex?
There are two major stages during inference, apart from routing, batching, and other infrastructure operations. These stages are important because they create two very different bottlenecks.
1. Prefill — Compute Heavy
When we send a prompt, the model first processes all the input tokens together. It figures out how different tokens relate to each other through a series of mathematical operations, mostly matrix multiplications. GPUs are quite good at this because they can perform a lot of calculations in parallel. The model weights are read from GPU memory (HBM) and reused across the prompt tokens, keeping the GPU's computing cores busy.
As the model processes the prompt, it also builds something called a KV cache, which acts like temporary notes stored in GPU memory. This helps the model avoid processing the entire prompt again for every new token. At the end of prefill, the model is ready to generate its first token. One important metric here is Time to First Token (TTFT), which measures how long a user waits before the response starts appearing.
2. Decode — Memory Heavy
Once the first token is generated, the model starts producing the rest of the answer one token at a time. Every new token depends on the previous ones, so the work cannot be parallelized in the same way as prefill. At each step, the model uses its weights and the KV cache to predict the next token, adds new information to the cache, and repeats until the response is complete.
Here, the problem is different. For a single request, the GPU does relatively little computation per token but still needs to move a large amount of data from HBM to its computing cores. This means the GPU can spend more time waiting for data than doing calculations. Memory bandwidth becomes the bottleneck, rather than raw computing power. Memory capacity is another limitation, as the KV cache keeps growing with longer conversations and larger contexts. Batching multiple requests helps, but it introduces its own trade-offs.
How Are We Solving These Problems?
Now that we know the two major challenges — prefill is compute-heavy and decode is memory-heavy — the interesting question is how to solve them. Most of the innovations happening in inference today broadly fall into two approaches.
1. Accept the Limitations and Work Around Them
The first approach is to accept the limitations of current models and hardware and find smarter ways to use them. This involves a lot of systems engineering and infrastructure optimization. Techniques like continuous batching, disaggregated serving, prefix caching, and cache-aware routing help improve GPU utilization, avoid repeated calculations, and reduce memory overhead.
For example, continuous batching allows new requests to join while other requests are being processed, instead of waiting for an entire batch to finish. Prefix caching lets the model reuse computations from prompts it has already processed. Open-source inference engines like vLLM and SGLang, along with specialized inference platforms, are doing a lot of work in this area.
2. Attack the Cause of the Limitation
The second approach is more fundamental. Instead of working around the bottlenecks, why not change the model, the mathematics, or the hardware itself? For example, speculative decoding uses a smaller model to predict multiple tokens, which are then verified together by a larger model. multi-token prediction trains models to predict multiple future tokens rather than just one. Techniques like quantization and more efficient attention mechanisms reduce the amount of data that needs to be stored and moved around.
Another interesting area is specialized inference hardware. Companies like Groq and Cerebras are building processors with different approaches to memory and computation, aiming to reduce the limitations of traditional GPU architectures. These innovations are trying to make inference fundamentally faster and more efficient rather than just managing existing constraints.
Where Is the Next Pot of Gold?
A large part of the AI race has been about building bigger and smarter models. But as AI becomes part of everyday products, the economics of running these models will become just as important. Even a small reduction in inference cost can translate into millions of dollars in savings when you're serving billions of tokens every day.
I think this is where a new generation of companies will emerge. Some will build better inference infrastructure that makes GPUs more efficient. Others will develop new model architectures, faster decoding techniques, or specialized hardware. There's also an interesting opportunity in intelligent orchestration — figuring out which model to use for which task, when to reuse previous computations, and how to get the same work done with fewer tokens.
Conclusion
Two companies running exactly the same model on the same hardware can have vastly different inference costs, depending on how intelligently they manage requests, memory, and GPU resources.
Tokens are the new oil powering AI machines. Whoever figures out how to generate them faster and cheaper will make intelligence more affordable, faster, and more accessible to everyone.