Notes on Inference Engineering by Philip Kiely
Chapter 0: Inference
Since the launch of ChatGPT November 2022, AI models have been getting more and more competent for a wide variety of use-cases, both from closed source providers like Anthropic and OpenAI and open source providers like Deepseek, Qwen, Meta and more.
Until December 2024, there was a meaningful gap in intelligence between closed and open models. When DeepSeek V3 and R1 were released, that gap disappeared.
As of today, open models by Xiaomi, Zai, Qwen and Kimi are very comparable to their closed source counterparts like Opus 5 and ChatGPT 6 Sol.
And a new generation of blended research and engineering teams – World Labs, Writer, Mirage, and dozens of others – are building enormous businesses by training and productizing their own foundation models.
Look into
We’ve got training (process of learning model weights from data) and then we’ve got inference (serving these generative ai models in production).
Inference for classic ML models is relatively straightforward. In the early days of Baseten, we ran inference for models built with tools like XGBoost on lightweight CPUs with a simple software stack.
Look into
You can’t just grab some gpus and have production grade inference. Inference done well requires three layers:
- Runtime: Optimizing performance of single model on single gpu
- Infrastructure: Scaling across clusters, regions and clouds while maintaining availability and reliability
- Tooling: Providing engineers working on inference with the right level of abstraction

Model Performance techniques on the runtime layer:
Look into
- Batching: Run incoming requests in parallel, weaving them together token by token to increase throughput.
- Caching: Re-use the KV cache between requests that share prefixes
- Quantization: Lower precision to access more compute and reduce memory burden
- Speculation: Generate and validate draft tokens to produce more than one token per forward pass during decode.
- Parallelism: Efficiently leverage more than one gpu
- Disaggregation: Separate the two phases of inference, prefill and decode onto independently scaling workers.
Internalize
The final level of scale in infrastructure is a global system that treats all available resources as a single unified pool of compute.
Chapter 1: Prerequisites
Many performance improvements come from making tradeoffs among latency, throughput, and quality. Different things may matter for your usecase. We want to find the right balance for our usecase.
What you should know about your product before thinking of inference:
- Model requirements: Which model to run inference on?
- Application interface: Input and output expectations?
- Latency budget: How fast does your product need to respond to the user?
- Unit economics: What does it make sense to spend on?
- Usage patterns: Concurrent user count? Variability across different time periods?
2 ways to integrate AI models into your product:
- Shared Inference: enterprise APIs, openrouter
- Dedicated Deployments: set up your own gpus or rent gpus in the cloud

When does it makes sense to use dedicated inference?
- Scale: ur too big and paying for gpu is cheaper
- Specialization: model is specialized to ur usecase
- Orchestration: ur model relies on multiple models and you need to minimize network latency (look into)

Tradeoff #1: Latency vs Throughput
Some things run online: user is waiting on line for a response quick we need to optimize for latency Some things run offline: User isn’t waiting and can take more time so we can optimize for throughput

Consumer: optimize marginal cost and flexibility and keep latency and availability at a decent standard B2B: Higher margins and stable usage but require higher guarantees of availability and consistent low latency. Inference engineers building for businesses must favor latency and uptime, though cost and scale are important secondary concerns.
Compliance plays a major role. One should consider:
- Data sovereignty: where are the gpus?
- User privacy: are my inputs and outputs private and secure?
- Regulatory compliance: am I meeting hipaa and soc2 kind of standards if they apply to me?
Use pay per token apis before finding product market fit in most cases. When it’s time to scale figure out the smallest easiest to run model to fulfill the task at hand.
Model Evals: Whereas benchmarks tests the general intelligence of the model at a wide variety of tasks evals test it’s fit to your specific tasks.
Unlike standard intelligence benchmarks, which measure model capabilities against common tasks like MMLU or SWE-bench, evals are tailored to specific products, domains, and tasks.
Fine tuning vs Distillation (look into)
Measuring Latency and Throughput
The most common performance metrics for LLMs:
- Time to first token (TTFT)
- Tokens per second (TPS)
| Time to first token (TTFT) | Tokens per second (TPS) |
|---|---|
| With streaming output, how long does it take for a user to see the first output token? | How many tokens each second does the user receive after the first token is generated? |
| Based on compute-bound prefill | Based on bandwidth-bound decode |
| Lower TTFT == better latency | Higher TPS == better latency |
More specific terms for TPS:
- Perceived TPS: The observed tokens per second per user after the first token (latency).
- Total TPS: The total number of tokens generated each second by the inference service (throughput).
- Inter-token latency (ITL): The time between subsequent tokens. An ITL of 10 milliseconds equates to 100 tokens per second per user.
Internalize
The naive approach is to simply look at an average (mean) TTFT or TPS. However, this does not tell the whole story. LLM total response time is generally a right-skewed distribution, where most times concentrate around a mode, but outliers can take significantly longer.

End to end metrics (look into)