Skip to content

Track 01

Live

LLM Internals & Architecture

Implement and inspect a decoder-only transformer, explain how it learns and generates, and evaluate the design choices behind modern and reasoning models.

  • Intermediate
  • 2 primers live
  • 26 of 26 chapters live
  • 373 min live

What you'll be able to do

By the end of the core course.

  1. Trace a decoder-only transformer from tokens to logits, with explicit tensor shapes
  2. Implement attention, the transformer block, training, and cached generation
  3. Explain how model and context choices change memory, latency, and quality
  4. Evaluate modern attention, sparse, and reasoning designs against stated tradeoffs

Main subjects

The territory this track covers.

  1. 01Transformer architecture
  2. 02Tokenisation and embeddings
  3. 03Attention and masking
  4. 04Positional encoding
  5. 05Pretraining and generation
  6. 06KV cache and context
  7. 07MQA, GQA, and MLA
  8. 08Mixture of Experts
  9. 09Multi-token prediction
  10. 10Architecture comparison
  11. 11Reasoning evaluation
  12. 12Reasoning distillation

Who this is for

Experienced developers learning model internals for the first time, and senior engineers who want to inspect the machinery behind the API.

Before you start

  • Comfort reading Python and basic PyTorch
  • Familiarity with vectors and matrix multiplication
  • No prior machine-learning course required

Curriculum

2 primers live · 26 of 26 chapters live

Primers

2 of 2 live

Short published pieces that set up the vocabulary before the numbered course.

Core course

14 of 14 live

The main sequence, read in order.

Module 01

Transformer architecture and model inputs

Trace a decoder-only model from input IDs to logits, then turn text into tokenised, correctly shifted training sequences.

3 of 3 lessons live

  1. 01Transformer Architecture Explained: Trace a Decoder-Only LLMFollow one small decoder-only transformer from token IDs to logits, with explicit tensor shapes and component boundaries.Intermediate14 min readRead
  2. 02Tokenisation and Embeddings: From Text to TensorsFollow a short text string through GPT-2 byte-level BPE tokenisation and an embedding lookup, with explicit tensor-shape tracing from [B,T] to [B,T,d] to [B,T,V].Intermediate12 min readRead
  3. 03Preparing Training Sequences: Shift, Pad, and PackOne small batch traced from token IDs through padded input IDs, labels, causal mask, logits, and loss. Covers padding and sequence packing conventions.Intermediate15 min readRead

Module 02

Attention mechanisms from scratch

Implement scaled dot-product attention, control what each token can see, and merge parallel heads.

3 of 3 lessons live

  1. 04Self-Attention: Queries, Keys, and ValuesBuild self-attention in PyTorch: Q/K/V projections, scaled dot-product scores, stable softmax, weighted value aggregation, verified against torch.nn.functional.scaled_dot_product_attention.Intermediate14 min readRead
  2. 05Causal and Padding Masks: Implementation and TestsConstruct causal and key-padding masks, combine via broadcast AND, and verify future-token leakage. Covers causal mask, padding mask, combined formula, and fully masked rows.Intermediate15 min readRead
  3. 06Multi-Head Attention: Splitting, Merging, and ProjectingBuild multi-head attention from scratch: combined in-projection, head splitting, parallel attention, head merging, output projection. Verified against PyTorch reference.Intermediate14 min readRead

Module 03

Building and training a language model

Add position information, assemble the decoder block, stack a GPT-style model, then train and debug it.

4 of 4 lessons live

  1. 07Positional Information: Absolute Embeddings and RoPECompare learned absolute position embeddings with RoPE: trace shapes, verify position-offset extrapolation, and state the Staff/Principal decision framework.Intermediate13 min readRead
  2. 08Inside the Transformer Block: Residuals and NormalisationTrace residuals through a decoder block with pre-norm RMSNorm/SwiGLU. Compare LayerNorm/RMSNorm, GELU/SwiGLU, pre-norm vs post-norm with shapes and a PyTorch block.Intermediate12 min readRead
  3. 09Assembling a GPT-Style Language ModelBuild a small runnable GPT-style decoder-only model by stacking decoder blocks, adding final normalisation, tying or untying the output projection, and verifying forward shapes and parameter counts.Intermediate15 min readRead
  4. 10Training and Debugging: Next-Token Loss and Optimiser StepsConstruct next-token targets with shifted logits, compute cross-entropy loss and perplexity, implement optimizer steps and gradient accumulation, and run a tiny-batch overfit run.Intermediate14 min readRead

Module 04

Generation, KV cache, and context

Load compatible weights, generate text, implement the KV cache, and measure where the context window stops helping.

4 of 4 lessons live

  1. 11Pretrained Weights and Text GenerationLearn how to adapt a Hugging Face checkpoint to your model architecture, then generate text using four decoding strategies with explicit traceable examples and stopping rules.Intermediate12 min readRead
  2. 12Prefill and Decode: Measuring the Two PhasesGiven a prompt length, output length, and batch size, trace the two phases separately, measure them, and explain which latency metric each measurement informs.Intermediate11 min readRead
  3. 13KV Cache Implementation and Memory AccountingUpdate the cache correctly across positions, verify cached and uncached logits match, and calculate memory at a stated precision.Intermediate14 min readRead
  4. 14Context Windows and Their LimitsDistinguish the configured context limit from effective context, then test truncation, positional limits, and evidence-position sensitivity.Intermediate11 min readRead

Advanced modules

12 of 12 live

Deep dives for readers who have finished the core course.

Module 05

Modern LLM architectures

Compare the attention, routing, and prediction changes behind current model designs under explicit constraints.

6 of 6 lessons live

  1. 15MHA vs. MQA vs. GQA: Attention Architecture TradeoffsCompare MHA, MQA, and GQA under explicit constraints: query head sharing, KV-cache formula, ratios, and when architecture choice requires evaluation rather than unconditional ranking.Advanced14 min readRead
  2. 16Mixture of Experts: Routing, Dispatch, and Load BalancingTrace MoE routing: scores, top-k dispatch, normalised output. Separate active and stored params, compute, memory, latency; include minimal example, capacity/overflow case, brief dense-to-MoE note.Advanced15 min readRead
  3. 17Multi-Head Latent Attention: DeepSeek's KV-Cache DesignDeepSeek MLA: joint K/V compression, decoupled RoPE key, projection absorption during decode. A constrained matrix-order trick; cache ratios depend on stated toy dimensions.Advanced14 min readRead
  4. 18Multi-Token Prediction: Objectives and TradeoffsMTP predicts future training targets; DeepSeek uses sequential modules discardable at inference, Meta uses parallel heads. Training quality and inference speed must be evaluated separately.Advanced15 min readRead
  5. 19What Can You Remove From a Transformer?Compare structural removal (layers, MLP width, attention) from zeroing weights and quantization. Include compatibility, recovery training, an ablation plan, and the latency/parameter gap.Advanced14 min readRead
  6. 20Architecture Comparison: Documenting a Defensible ChoiceCompare modern decoder-only configurations under a fixed baseline with explicit conditions, a defensible decision framework, original ablation design, and labelled arithmetic.Advanced14 min readRead

Module 06

Reasoning models and test-time computation

Evaluate reasoning, spend test-time compute deliberately, and understand the training methods behind reasoning models.

6 of 6 lessons live

  1. 21How Reasoning Models Work: Training Paths, Traces, and CostReasoning models are built through several non-exclusive paths. A correct final answer can coexist with an unfaithful trace; token cost and process checks must be measured separately.Advanced16 min readRead
  2. 22Evaluating Reasoning: Baselines, Verifiers, and Parsing FailuresEstablish a baseline, build a small dataset, extract and normalize answers, count parser failures separately, apply verifiers with their limits, compute exact match and pass@k, and classify errors.Advanced12 min readRead
  3. 23Inference-Time Scaling: Sampling, Best-of-N, and Self-ConsistencyCompare repeated sampling, best-of-N, and self-consistency under shared token, latency, and selection budgets; show selection mechanisms, worked arithmetic, and failure cases.Advanced13 min readRead
  4. 24Self-Refinement: Critique, Revision, and Stopping PoliciesCompare generate–critique–revise using model self-feedback versus external tool checks, with worked cases, stopping policy, cost model, and a checkable exercise.Advanced13 min readRead
  5. 25Reinforcement Learning for Reasoning: Verifiable Rewards and GRPOTrain reasoning models with verifiable rewards using GRPO. Covers rollouts, group-relative advantages, the GRPO objective, regularisation choices, reward hacking, and a worked numerical example.Advanced14 min readRead
  6. 26Reasoning Distillation: Teacher Data, Filtering, and Student EvaluationBuild teacher-generated reasoning data, filter it for quality, train a student model, and evaluate capability against deployment cost.Advanced12 min readRead

The core course is the shortest complete path. Advanced modules assume you have finished it.

Practice labs

Runnable CPU-only companions for selected lessons. Practice material, not published chapters; not counted in the Track 1 chapter count.

Browse all practice labs