tiny-llm

July 25, 2026 · View on GitHub

CI (main)

tiny-llm is a hands-on course for systems engineers who want to understand LLM inference end to end. You can think of it as an LLM-serving counterpart to CMU's Needle project: build the path that loads a Qwen3 model, turns tokens into logits, and generates text.

The course begins with array and matrix operations, then introduces kernels and serving machinery as the running model needs them. Keeping the implementation small enough to read end to end makes it possible to connect the equations to memory traffic, kernel occupancy, KV-cache growth, batching, and request scheduling.

The course is built on MLX arrays and the MLX extension runtime, without using high-level neural-network layers. When a chapter teaches an operator, your solution implements that operator in Python, C++, or Metal rather than calling the corresponding optimized MLX operation. MLX remains the correctness oracle and performance baseline.

The Learning Path

The course follows a four-week learning path:

  • Week 1: From Matmul to Text. Build a readable Qwen3 model from array operations: attention, RoPE, GQA, RMSNorm, the MLP, sampling, and the autoregressive loop.
  • Week 2: A Step Closer to vLLM. Add a KV cache, establish a synchronized MLX baseline, and let profiles choose the next optimization. The path moves from quantized decode matvec to fused model kernels, tiled prefill, and split-K where the measured Qwen shapes need it.
  • Week 3: Build a Mini vLLM. Introduce continuous batching and chunked admission, then make paged KV the canonical serving layout. Decode attention and FlashAttention learn to read pages directly so the scheduler does not rebuild dense history on every step.
  • Week 4: Build a Coding Agent. Use multi-turn sessions to motivate cache reuse, context compaction, rewind, interruption, and evaluation.

Why MLX and Qwen3?

Apple silicon provides a practical local environment with one shared memory space and direct access to Metal kernels. Students can inspect the complete path on one machine instead of depending on an expensive CUDA GPU setup.

Qwen3-4B is large enough to expose real weight-bandwidth, attention, and cache costs, but small enough to iterate on locally. Its grouped-query attention, QK normalization, BF16 activations, and 4-bit weights also keep the exercises close to current model-serving work.

Start Here

The book is published at skyzh.github.io/tiny-llm. Begin with the environment setup, or verify an existing checkout with:

pdm install -v
pdm run check-installation
pdm run test-refsol -- -- -k week_1

The tiny_llm package is where students implement the exercises. tiny_llm_ref contains the reference solution used by the tests and benchmark appendix. The detailed chapter order and current status live in the book summary.

Roadmap

The status columns track whether each chapter's code, tests, and documentation are ready. Week 4 remains a design draft and is not yet part of the rendered daily course.

Week + ChapterTopicCodeTestDoc
1.1Attention
1.2RoPE
1.3Grouped Query Attention
1.4RMSNorm and MLP
1.5Load the Model
1.6Generate Responses (aka Decoding)
1.7Sampling
2.1KV Cache🚧
2.2Benchmark and Profile🚧🚧🚧
2.3Quantized Matvec🚧
2.4Fused Decode Attention🚧🚧🚧
2.5Fused Model Kernels🚧🚧🚧
2.6SIMD-Matrix Prefill🚧
2.7Split-K Prefill🚧
3.1Continuous Batching🚧
3.2Chunked Prefill🚧
3.3Paged KV Cache🚧
3.4Direct Paged Attention🚧
3.5Paged FlashAttention🚧
3.6 (optional)Speculative Decoding🚧🚧🚧
3.x (optional)MoE (Mixture of Experts)
4.1Agent Loop🚧🚧🚧
4.2Tools🚧🚧🚧
4.3Safety and Validation🚧🚧🚧
4.4Interactive Sessions🚧🚧🚧
4.5Context Compaction🚧🚧🚧
4.6Control and Recovery🚧🚧🚧
4.7Evaluation🚧🚧🚧

Other topics not covered include quantized or compressed KV caches, cross-request prefix caching, fine-tuning, and long-context techniques.

Community

Join skyzh's Discord server to study with the tiny-llm community.

Join skyzh's Discord Server