Track 08 · Specialisation
Inference Optimization & GPU Programming
Make models fast and cheap: the roofline model, KV caches, batching, speculative decoding, quantisation, FlashAttention, CUDA and Triton kernels, serving engines — and running models on-device.
- Last updated
- Total effort
- 800 h · ≈ 80 weeks
Overview
Inference engineering is about one question: how do you get the most useful tokens per second per dollar out of a model without hurting quality? It joins systems thinking and hardware. You learn why LLM decoding is limited by memory bandwidth rather than FLOPs, how the KV cache dominates memory, how serving engines like vLLM batch thousands of requests, how quantisation and speculative decoding cut cost, and eventually how to write GPU kernels in Triton and CUDA yourself. The same principles, applied to tight memory and power budgets, drive on-device AI on phones and laptops.
Why it matters heading into 2027
To be honest about the evidence: aggregate hiring data for inference and GPU-kernel roles is thin, and most openings are senior (individual postings ask for CUDA, CUTLASS and Triton experience). It is still worth a place in this set. Serving is where AI spend goes: the CNCF reports that 66% of organisations hosting generative-AI models use Kubernetes for inference, and every cost and latency target lands on the serving stack. It is also the natural deepening of the user's interest in efficient training and inference. Treat it as a specialisation you grow into after the Deep Learning Advanced stage, not a first job target.
- 66% of organisations hosting generative-AI models use Kubernetes for inference. — CNCF Annual Cloud Native Survey (Jan 2026)
- 38% of organisations set usage limits on AI — cost per token is now a business constraint. — Stack Overflow Developer Survey 2026
Prerequisites
- Deep Learning Intermediate stage: you have written a GPT and understand attention and the KV cache.
- Comfortable Python and PyTorch; basic C or C++ helps for the CUDA stages.
- Computer-architecture basics: memory hierarchy, caches, threads (the Software Engineering fundamentals).
- Access to an NVIDIA GPU (Colab, Kaggle or a rented cloud GPU) from the Intermediate stage onward.
Learning path
How the stages build on each other, and where this track hands off to others.
flowchart TB
P["Prereqs: GPT from scratch · PyTorch · C basics"] --> B
subgraph B["1 · Beginner — measure first"]
direction LR
B1["GPU memory hierarchy"] --> B2["roofline model"] --> B3["profile a model"]
end
subgraph I["2 · Intermediate — serving LLMs"]
direction LR
I1["KV cache"] --> I2["continuous batching"] --> I3["vLLM / SGLang"] --> I4["quantisation"]
end
subgraph A["3 · Advanced — kernels"]
direction LR
A1["Triton kernels"] --> A2["CUDA matmul"] --> A3["fused attention"] --> A4["speculative decoding"]
end
subgraph E["4 · Expert — systems & edge"]
direction LR
E1["disaggregated serving"] --> E2["FP8 & co-design"] --> E3["on-device: ExecuTorch · MLX · llama.cpp"]
end
B --> I --> A --> E
I -.-> CLOUD["Cloud: GPU autoscaling"]
A -.-> DL["Deep Learning: FlashAttention in training"]
E -.-> AIE["AI Engineering: latency & cost budgets"]
Stages
Tick items as you go — progress is saved in this browser only. Times are focused hours (reading + building); the week estimates follow the study time you pick above.
01Beginner100 h · ≈ 10 weeksBuild the mental model before optimising anything: how GPUs work, why memory bandwidth matters, and how to measure where time goes.
Key concepts
Build these
Ready for the next stage when…
02Intermediate160 h · ≈ 16 weeksServe LLMs efficiently: KV-cache management, batching, serving engines and post-training quantisation, measured under realistic load.
Key concepts
Build these
Ready for the next stage when…
03Advanced240 h · ≈ 24 weeksWrite and optimise kernels: Triton first, then CUDA, then fused attention and speculative decoding.
Key concepts
Build these
Ready for the next stage when…
04Expert300 h · ≈ 30 weeksDesign inference systems at scale and on the edge: disaggregated serving, hardware–model co-design, and running models on phones and laptops.
Key concepts
Build these
Ready for the next stage when…
Field guide
The ideas behind the checklist, with diagrams and the math where it helps.
Where inference time goes
An LLM request has two phases with very different performance:
flowchart TB
subgraph PRE["Prefill — process the whole prompt at once"]
direction LR
P1["prompt tokens"] --> P2["big matmuls<br/>compute-bound"] --> P3["write KV cache"]
end
subgraph DEC["Decode — one token at a time"]
direction LR
D1["read all weights<br/>+ KV cache"] --> D2["tiny matmuls<br/>memory-bound"] --> D3["next token"]
end
PRE -- "time to first token" --> DEC
D3 -- "repeat until done" --> D1
Prefill processes many tokens in parallel, so it keeps the tensor cores busy. Decode generates one token per step but must stream every weight (and the KV cache) from memory each time. Most serving tricks attack decode’s memory problem: batching more sequences together, shrinking the weights (quantisation), shrinking the KV cache (GQA, MLA, paging), or producing several tokens per weight-read (speculative decoding).
The roofline model
The arithmetic intensity of an operation is the work done per byte moved:
A GPU has a peak compute (FLOP/s) and a memory bandwidth (bytes/s). Achievable performance is
The crossover point is the ridge point. For a modern data-centre GPU with roughly bf16 FLOP/s and about bytes/s of HBM bandwidth, FLOPs per byte. A matrix–vector product at batch size 1 has , so it uses well under 1% of the compute. That’s why batching helps so much: a batch of sequences reuses each weight times and raises intensity roughly -fold.
The KV cache is the memory budget
During decoding each layer stores a key and a value vector for every previous token. Its size is
Example: a Llama-3-8B-style model has 32 layers, 8 KV heads (thanks to GQA) and . In bf16 that’s bytes ≈ 128 KiB per token. A batch of 16 sequences at 8k tokens needs about 16 GiB, the same order as the 16 GB of weights. Without GQA (32 KV heads) it would be four times larger. This is why PagedAttention (no wasted, fragmented cache memory) and prefix caching (share the cache for common system prompts) give such large throughput gains.
A quick upper bound on decode speed
At small batch sizes, each decode step reads all the weights once, so
An 8B-parameter model in bf16 is about 16 GB; with about 3 TB/s of bandwidth that’s at most roughly 190 tokens/s for a single sequence, whatever the FLOPs. Quantising to 4-bit cuts the bytes about 4×, which is why int4 models feel so much faster on the same hardware. The same formula explains on-device speeds: a laptop with 100–400 GB/s of memory bandwidth running a 4 GB model tops out around 25–100 tokens/s.
Kernels: from Triton to CUDA
Start in Triton: you write block-level Python and the compiler handles threads and shared memory. Fused kernels such as softmax and RMSNorm give big wins because they cut round-trips to HBM. Move to CUDA when you need full control. Work through a matmul from naive to tiled to register-blocked, and learn coalescing, shared-memory tiling and occupancy along the way. FlashAttention is the capstone: it uses the same tiling ideas plus an online softmax that lets attention run block by block without ever storing the full score matrix.
On-device and edge AI
Running models on phones and laptops is the same discipline under tighter limits: a few GB of memory, a power budget, and an NPU or GPU that’s shared with the rest of the device.
| Lever | What it does | Tools |
|---|---|---|
| Smaller architecture | deep-and-thin sub-1B models | MobileLLM, Gemma 3n |
| Distillation | small model learns from a big one | Hinton et al. 2015 |
| Low-bit quantisation | 4-bit or lower weights | GGUF (llama.cpp), MLX, ExecuTorch |
| Runtime | uses the device’s NPU/GPU | ExecuTorch, LiteRT, Core ML, ONNX Runtime |
| Platform models | OS-provided on-device LLMs | Apple Foundation Models framework, Gemini Nano |
The hybrid pattern is becoming standard: a small on-device model handles private, low-latency tasks and routes hard requests to the cloud. Designing that routing (latency, privacy, cost) is where the inference and AI Engineering tracks meet.
How this track connects
- Deep LearningTraining choices (GQA, MoE, context length, precision) set serving cost; FlashAttention and kernels speed up training too.
- Cloud & IAMGPU node pools, autoscaling, networking for tensor parallelism and secure model storage are cloud engineering.
- AI Eng.Latency and cost budgets shape every product decision: model choice, prompt length, caching and streaming.
- ML Eng.Model servers, canaries and monitoring from MLOps are how optimised models reach users safely.
- FoundationsLinear algebra (matmul shapes) and numerics (floating-point precision) explain quantisation and kernel behaviour.
References
Original sources first: arXiv, official docs, university courses and lab blogs. Every link was checked on 7 Nov 2026.
Foundational & seminal papers(24)
- Roofline: An Insightful Visual Performance Model for Multicore Architectures
Williams, Waterman & Patterson · 2009 · doi.org
The model you'll use for every performance question: compute- vs memory-bound.
- Distilling the Knowledge in a Neural Network
Hinton, Vinyals & Dean · 2015 · arxiv.org
Knowledge distillation — how small, fast models learn from big ones.
- Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman Coding
Han, Mao & Dally · 2015 · arxiv.org
Pruning, quantisation and coding: the origin of model-compression thinking.
- MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
Howard et al. · 2017 · arxiv.org
Architecture design for mobile constraints.
- Orca: A Distributed Serving System for Transformer-Based Generative Models
Yu et al. · 2022 · usenix.org
Introduced iteration-level (continuous) batching.
- LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale
Dettmers et al. · 2022 · arxiv.org
Why outlier features break naive int8, and how to handle them.
- GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers
Frantar et al. · 2022 · arxiv.org
Second-order post-training weight quantisation to 3–4 bits.
- SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models
Xiao et al. · 2022 · arxiv.org
Moves quantisation difficulty from activations to weights for W8A8.
- Efficiently Scaling Transformer Inference
Pope et al. · 2022 · arxiv.org
The partitioning and memory maths of large-model inference.
- Fast Inference from Transformers via Speculative Decoding
Leviathan et al. · 2022 · arxiv.org
Draft-then-verify decoding with identical outputs.
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
Dao et al. · 2022 · arxiv.org
IO-aware attention; the canonical example of kernel thinking.
- Accelerating Large Language Model Decoding with Speculative Sampling
Chen et al. · 2023 · arxiv.org
DeepMind's independent speculative-sampling formulation.
- AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration
Lin et al. · 2023 · arxiv.org
Protect the salient weights; widely used 4-bit method.
- FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
Dao · 2023 · arxiv.org
Better work partitioning across warps and blocks.
- Efficient Memory Management for Large Language Model Serving with PagedAttention
Kwon et al. · 2023 · arxiv.org
vLLM: virtual-memory-style paging for the KV cache.
- SGLang: Efficient Execution of Structured Language Model Programs
Zheng et al. · 2023 · arxiv.org
RadixAttention for automatic KV-cache reuse across requests.
- Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads
Cai et al. · 2024 · arxiv.org
Speculative decoding without a separate draft model.
- DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving
Zhong et al. · 2024 · arxiv.org
Why prefill and decode belong on different GPUs.
- MobileLLM: Optimizing Sub-billion Parameter Language Models for On-Device Use Cases
Liu et al., Meta · 2024 · arxiv.org
Deep-and-thin architectures for sub-1B on-device models.
- Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving
Qin et al. · 2024 · arxiv.org
Serving designed around storing and moving the KV cache.
- FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision
Shah et al. · 2024 · arxiv.org
Hopper-specific asynchrony and FP8.
- DeepSeek-V3 Technical Report
DeepSeek-AI · 2024 · arxiv.org
MLA, MoE and FP8: architecture co-designed with inference cost.
- EAGLE-3: Scaling up Inference Acceleration of Large Language Models via Training-Time Test
Li et al. · 2025 · arxiv.org
A state-of-the-art speculative decoding method.
- Apple Intelligence Foundation Language Models: Tech Report 2025
Apple · 2025 · arxiv.org
How a production on-device model stack is designed.
Courses & videos(2)
- GPU MODE lectures
GPU MODE community · github.com
The best community course on writing and profiling GPU kernels.
- MIT 6.5940: TinyML and Efficient Deep Learning Computing
Song Han, MIT · 2024 · hanlab.mit.edu
Quantisation, pruning, distillation and efficient LLM inference.
Books(3)
- Programming Massively Parallel Processors (4th ed.)
Hwu, Kirk & El Hajj · 2022 · shop.elsevier.com
The CUDA textbook.
- How to Scale Your Model
Google DeepMind (Austin et al.) · 2025 · jax-ml.github.io
Rooflines and the arithmetic of serving at scale.
- TinyML
Pete Warden & Daniel Situnayake · 2019 · oreilly.com
ML on microcontrollers: the extreme end of on-device.
Articles, blogs & official docs(15)
- Making Deep Learning Go Brrrr From First Principles
Horace He · horace.io
Compute, memory and overhead — the essay to read first.
- How to Optimize a CUDA Matmul Kernel for cuBLAS-like Performance
Simon Boehm · 2022 · siboehm.com
A step-by-step kernel worklog to follow and reproduce.
- GPU Glossary
Modal · modal.com
Plain-language definitions of GPU hardware and software terms.
- CUDA Programming Guide
NVIDIA · docs.nvidia.com
The official reference for the CUDA programming model.
- Triton tutorials
Triton · triton-lang.org
Write GPU kernels in Python: vector add → fused softmax → matmul.
- vLLM documentation
vLLM project · docs.vllm.ai
The most widely used open LLM serving engine.
- SGLang documentation
SGLang project · docs.sglang.io
Fast serving with prefix caching and structured generation.
- TensorRT-LLM documentation
NVIDIA · nvidia.github.io
NVIDIA's optimised inference library.
- llama.cpp
ggml-org · github.com
CPU and edge inference with GGUF quantisation.
- ExecuTorch documentation
PyTorch · docs.pytorch.org
PyTorch's on-device runtime for phones and embedded.
- LiteRT
Google AI Edge · ai.google.dev
The successor to TensorFlow Lite for on-device inference.
- MLX documentation
Apple ml-explore · ml-explore.github.io
Array framework for Apple silicon; great for local LLMs.
- Core ML
Apple · developer.apple.com
Deploy models in Apple apps.
- ONNX Runtime documentation
Microsoft · onnxruntime.ai
Cross-platform inference runtime.
- KernelBench
Stanford Scaling Intelligence Lab · github.com
Can LLMs write fast GPU kernels? A benchmark to watch.