SuperAPIAI Directory

tiny-llm

github.com · AI developer platforms

tiny-llm is a hands-on course for systems engineers, designed to help understand the end-to-end process of LLM inference. The course is based on Apple Silicon and MLX arrays, starting from matrix operations and progressively building a vLLM-like inference system, and finally implementing a coding agent. The course uses the Qwen3-4B model and emphasizes implementing operators from the ground up rather than calling high-level neural network layers.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS

About this tool

tiny-llm is a hands-on course for systems engineers, designed to help understand the end-to-end process of LLM inference. The course is based on Apple Silicon and MLX arrays, starting from matrix operations and progressively building a vLLM-like inference system, and finally implementing a coding agent. The course uses the Qwen3-4B model and emphasizes implementing operators from the ground up rather than calling high-level neural network layers.

Purpose

tiny-llm is designed to help systems engineers gain an in-depth understanding of the internal workings of LLM inference systems. The course starts with array and matrix operations and progressively introduces kernels and serving mechanisms, enabling learners to connect equations with concepts such as memory traffic, kernel occupancy, KV cache growth, batching, and request scheduling.

Main capabilities

The course follows a four-week learning path:

  • Week 1: From matrix multiplication to text generation. Build the Qwen3 model directly using mlx.core array operations, including attention, RoPE, GQA, RMSNorm, MLP, sampling, and the autoregressive loop.
  • Week 2: Faster single request. Day 1 adds kv-cache and request-limited capacity caching; Day 2 keeps W4 projection weights packed via quantized matrix-vector checkpoints; Day 3 adds SIMD matrix prefill in simd-matmul; Day 4 adds cumulative RMSNorm, RoPE, and SwiGLU checkpoints; Day 5 adds chunked prefill and runs the full selected model.
  • 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 that the scheduler does not have to rebuild dense history at every step.
  • Week 4: Build a coding agent. Start with a bounded, validated agent loop, then connect it to a small workspace. The course releases one reviewed checkpoint at a time; Days 1 through 9 now cover inspection, approved edits, one verification command, simple effect receipts, a visible checkpoint and recovery boundary, receipt-backed context compression, a visible inspection and guided pause, deterministic evaluation of observable results, then tokenizer/KV prefix reuse for two isolated guided branches and an explicit evidence-based choice, and finally bounded, scoped retrievable evidence for oversized tool results.

How to use

The course book is publishedat skyzh.github.io/tiny-llm. You can start with environment setup, or use the following command to verify an existing checkout:

# 具体命令请参考官方文档

The tiny_llm package is where students implement the exercises. tiny_llm_ref contains the reference solutions used by the tests and benchmark appendix. The book summary lists the chapter order; implementation, testing, and release readiness are tracked below.

The table tracks implementation (Code), testing (Test), rendered chapters (Doc), and Chi's review of learner materials (Audit). Week 4 releases one reviewed day at a time; Days 1 through 9 are currently available to learners. The Audit column reflects Chi's personal editing pass over published course content, independent of code/test/doc readiness.

Day 3 can send file contents to the model, modify files after approval, and run a precisely configured command. Use a disposable workspace with no secrets, and read the Week 4 overview before running the loop. Day 4 uses fake cache metadata from a scripted model to inspect the full tool observation boundary, then resumes a new model without replaying completed edits or commands. Day 5 compacts older completed effects in the model-visible transcript, while their exact receipts retain the full operations, results, and changed artifacts. Day 6 inspects a complete observation checkpoint, appends a visible operator instruction, and resumes a new model without replaying completed effects. Day 7 evaluates a completed run from declared final, file, result, and receipt facts, without grading hidden reasoning or exact transcript shape. Day 8 reuses two distinct guided, effect-isolated continuations for a real tokenizer/KV checkpoint, evaluates both with Day 7's tools, and makes one explicit pass selection without pretending completed effects were rewound. Day 9 stores exact oversized tool result bytes outside the model prompt, shows a bounded identity/summary/head-tail observation, and lets the model retrieve an explicit byte range through the existing loop.

Week 2 early chapter URLs are not reused by active Days 1-5 and remain available as historical material. The former Day 4 address now serves the active fusion primitives lesson. These historical pages describe an earlier test and checkpoint order, separate from the current Day 1 → Day 2 → Day 3 → Day 4 → Day 5 route.

Applicable Scenarios

tiny-llm is for systems engineers who want a deep understanding of LLM inference systems. Apple Silicon provides a practical local environment with a shared memory space and direct access to Metal kernels. Students can inspect the complete path on one machine without relying on an expensive CUDA GPU setup. Qwen3-4B is large enough to expose real weight bandwidth, attention, and cache costs, yet small enough to iterate on locally. Its grouped-query attention, QK normalization, BF16 activations, and 4-bit weights also bring the exercises close to current model serving work.

Limitations

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

Join skyzh's Discord server to learn together with the tiny-llm community.the complete path on one machine without relying on an expensive CUDA GPU setup. Qwen3-4B is large enough to expose real weight bandwidth, attention, and cache costs, yet small enough to iterate on locally. Its grouped-query attention, QK normalization, BF16 activations, and 4-bit weights also bring the exercises close to current model serving work.

Limitations

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

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

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools