Skip to content
Sajith JeewanthaSoftware Engineer

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
Your progress

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.

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:

I=FLOPsbytes movedI = \frac{\text{FLOPs}}{\text{bytes moved}}

A GPU has a peak compute PP (FLOP/s) and a memory bandwidth BB (bytes/s). Achievable performance is

performance=min⁡(P, I⋅B)\text{performance} = \min\left(P,\ I \cdot B\right)

The crossover point I⋆=P/BI^\star = P / B is the ridge point. For a modern data-centre GPU with roughly 101510^{15} bf16 FLOP/s and about 3×10123 \times 10^{12} bytes/s of HBM bandwidth, I⋆≈300I^\star \approx 300 FLOPs per byte. A matrix–vector product at batch size 1 has I≈1I \approx 1, so it uses well under 1% of the compute. That’s why batching helps so much: a batch of bb sequences reuses each weight bb times and raises intensity roughly bb-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

KV bytes=2⋅nlayers⋅nkv heads⋅dhead⋅Lseq⋅b⋅bytes per element\text{KV bytes} = 2 \cdot n_{\text{layers}} \cdot n_{\text{kv heads}} \cdot d_{\text{head}} \cdot L_{\text{seq}} \cdot b \cdot \text{bytes per element}

Example: a Llama-3-8B-style model has 32 layers, 8 KV heads (thanks to GQA) and dhead=128d_{\text{head}} = 128. In bf16 that’s 2⋅32⋅8⋅128⋅2=131,0722 \cdot 32 \cdot 8 \cdot 128 \cdot 2 = 131{,}072 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

tokens/s≲Bbytes of weights\text{tokens/s} \lesssim \frac{B}{\text{bytes of weights}}

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 T×TT \times T 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.

LeverWhat it doesTools
Smaller architecturedeep-and-thin sub-1B modelsMobileLLM, Gemma 3n
Distillationsmall model learns from a big oneHinton et al. 2015
Low-bit quantisation4-bit or lower weightsGGUF (llama.cpp), MLX, ExecuTorch
Runtimeuses the device’s NPU/GPUExecuTorch, LiteRT, Core ML, ONNX Runtime
Platform modelsOS-provided on-device LLMsApple 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

References

Original sources first: arXiv, official docs, university courses and lab blogs. Every link was checked on 7 Nov 2026.

Foundational & seminal papers(24)

  1. 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.

  2. Distilling the Knowledge in a Neural Network

    Hinton, Vinyals & Dean · 2015 · arxiv.org

    Knowledge distillation — how small, fast models learn from big ones.

  3. 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.

  4. MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

    Howard et al. · 2017 · arxiv.org

    Architecture design for mobile constraints.

  5. Orca: A Distributed Serving System for Transformer-Based Generative Models

    Yu et al. · 2022 · usenix.org

    Introduced iteration-level (continuous) batching.

  6. 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.

  7. 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.

  8. 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.

  9. Efficiently Scaling Transformer Inference

    Pope et al. · 2022 · arxiv.org

    The partitioning and memory maths of large-model inference.

  10. Fast Inference from Transformers via Speculative Decoding

    Leviathan et al. · 2022 · arxiv.org

    Draft-then-verify decoding with identical outputs.

  11. 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.

  12. Accelerating Large Language Model Decoding with Speculative Sampling

    Chen et al. · 2023 · arxiv.org

    DeepMind's independent speculative-sampling formulation.

  13. 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.

  14. FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning

    Dao · 2023 · arxiv.org

    Better work partitioning across warps and blocks.

  15. 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.

  16. SGLang: Efficient Execution of Structured Language Model Programs

    Zheng et al. · 2023 · arxiv.org

    RadixAttention for automatic KV-cache reuse across requests.

  17. Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads

    Cai et al. · 2024 · arxiv.org

    Speculative decoding without a separate draft model.

  18. 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.

  19. 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.

  20. Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving

    Qin et al. · 2024 · arxiv.org

    Serving designed around storing and moving the KV cache.

  21. FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision

    Shah et al. · 2024 · arxiv.org

    Hopper-specific asynchrony and FP8.

  22. DeepSeek-V3 Technical Report

    DeepSeek-AI · 2024 · arxiv.org

    MLA, MoE and FP8: architecture co-designed with inference cost.

  23. 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.

  24. Apple Intelligence Foundation Language Models: Tech Report 2025

    Apple · 2025 · arxiv.org

    How a production on-device model stack is designed.

Courses & videos(2)

  1. GPU MODE lectures

    GPU MODE community · github.com

    The best community course on writing and profiling GPU kernels.

  2. 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)

  1. Programming Massively Parallel Processors (4th ed.)

    Hwu, Kirk & El Hajj · 2022 · shop.elsevier.com

    The CUDA textbook.

  2. How to Scale Your Model

    Google DeepMind (Austin et al.) · 2025 · jax-ml.github.io

    Rooflines and the arithmetic of serving at scale.

  3. TinyML

    Pete Warden & Daniel Situnayake · 2019 · oreilly.com

    ML on microcontrollers: the extreme end of on-device.

Articles, blogs & official docs(15)

  1. Making Deep Learning Go Brrrr From First Principles

    Horace He · horace.io

    Compute, memory and overhead — the essay to read first.

  2. 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.

  3. GPU Glossary

    Modal · modal.com

    Plain-language definitions of GPU hardware and software terms.

  4. CUDA Programming Guide

    NVIDIA · docs.nvidia.com

    The official reference for the CUDA programming model.

  5. Triton tutorials

    Triton · triton-lang.org

    Write GPU kernels in Python: vector add → fused softmax → matmul.

  6. vLLM documentation

    vLLM project · docs.vllm.ai

    The most widely used open LLM serving engine.

  7. SGLang documentation

    SGLang project · docs.sglang.io

    Fast serving with prefix caching and structured generation.

  8. TensorRT-LLM documentation

    NVIDIA · nvidia.github.io

    NVIDIA's optimised inference library.

  9. llama.cpp

    ggml-org · github.com

    CPU and edge inference with GGUF quantisation.

  10. ExecuTorch documentation

    PyTorch · docs.pytorch.org

    PyTorch's on-device runtime for phones and embedded.

  11. LiteRT

    Google AI Edge · ai.google.dev

    The successor to TensorFlow Lite for on-device inference.

  12. MLX documentation

    Apple ml-explore · ml-explore.github.io

    Array framework for Apple silicon; great for local LLMs.

  13. Core ML

    Apple · developer.apple.com

    Deploy models in Apple apps.

  14. ONNX Runtime documentation

    Microsoft · onnxruntime.ai

    Cross-platform inference runtime.

  15. KernelBench

    Stanford Scaling Intelligence Lab · github.com

    Can LLMs write fast GPU kernels? A benchmark to watch.