Learn/Course 14
Transformers · weeks 17–19

Build a transformer from scratch

Domain autocomplete needs a model whose every component the team can explain.

Opening production brief

A measurable problem, before a model.

Users

Operators, product owners, and people affected by the transformer from scratch decision.

Data

tokenization, embeddings, RoPE, QKV projections with version, owner, event time, and availability contracts.

Constraints

Domain autocomplete needs a model whose every component the team can explain. Every solution must state latency, cost, capacity, and fallback limits.

Success

Offline evidence plus a deployable resolution: Tokenizer, attention, RoPE, residual stack, training loop, generation, and KV cache.

CHAPTER 1

Frame and baseline

Turn the production problem into explicit data, metric, and baseline contracts.

  1. 01

    Text to tensors: tokenization, embeddings, position

    Use text to tensors: tokenization, embeddings, position to move the transformer from scratch production brief toward a defensible release.

    65–90 min · checkpoint · deterministic lab
  2. 02

    Scaled dot-product self-attention by hand

    Use scaled dot-product self-attention by hand to move the transformer from scratch production brief toward a defensible release.

    65–90 min · checkpoint · deterministic lab
CHAPTER 2

Build and stress

Formalize the machinery, test counterexamples, and expose system limits.

  1. 03

    Heads, norms, residuals, and MLPs

    Use heads, norms, residuals, and mlps to move the transformer from scratch production brief toward a defensible release.

    65–90 min · checkpoint · deterministic lab
  2. 04

    Train a causal language model

    Use train a causal language model to move the transformer from scratch production brief toward a defensible release.

    65–90 min · checkpoint · deterministic lab
CHAPTER 3

Resolve and operate

Join model behavior to architecture, observability, rollout, and rollback.

  1. 05

    Sampling, KV cache, and efficient generation

    Use sampling, kv cache, and efficient generation to move the transformer from scratch production brief toward a defensible release.

    65–90 min · checkpoint · deterministic lab
  2. HW

    Decoder-only transformer from scratch

    Specify tokenizer, attention blocks, causal training, unit tests, sampling, and KV-cache parity without a transformer module.

    Rubric · staged hints · reference resolution
Prerequisite guidance

3 concepts make this faster.

Prerequisites are guidance, never hard gates.

C09Neural networksA small network built from forward pass through backpropagation and optimization.C11Sequence modelsA masked sequence model with BPTT, recurrent gates, and attention precursors.C12GPU trainingA profiled, mixed-precision, memory-budgeted training loop.
Ready to work the problem?

Text to tensors: tokenization, embeddings, position

Start lesson 01