Skip to content
DeepForgeby svx
Advancedtransformerscapstoneattentiontraininginference

Build a Transformer from Scratch

32 problems·~14h·5 stages

The capstone: assemble a working transformer from first principles, one component at a time. Tokenization and embeddings feed scaled attention, attention assembles into a block, masks and a stable loss train it, and caches plus FLOPs let you decode and measure it. Several problems intentionally revisit Deep Learning Essentials and LLM Engineering; that repetition is spaced review, not filler, and it is how the pieces finally lock together. Take it after Deep Learning Essentials.

Your progress

0/32 · 0%

Path readiness 0%Easy 0% · Medium 0% · Hard 0%

Continue path · Byte-Level BPE Token Count

What you will learn

  • Tokenize, embed, and position tokens for a transformer
  • Build scaled and multi-head attention from first principles
  • Assemble a pre-norm block with LayerNorm, GELU, and residuals
  • Train with masking and a stable loss, then decode with a KV cache
  • Measure attention cost and forward FLOPs per token

Before you start

1Tokenize and Embed

0/6

Everything starts as text: byte-level BPE token counts and merge steps, embedding lookups and parameter budgets, the backward scatter-add that trains them, and sinusoidal positional encoding.

Stage checkpoint

0/2 to pass

A checkpoint is a short retrieval test drawn from this stage: solve 2 of 3 from memory to mark the stage complete. The stage stays open either way.

Tried this set and did not pass? Record it — the next set swaps in fresh problems from the same stage.
LabRecommended next stepXOR BoundaryHard

2Attention from First Principles

0/7

The core mechanism: scaled attention scores, softmax weights, and the weighted sum, then multi-head split and merge, a parameter count with bias, and cross-attention shapes.

Stage checkpoint

0/2 to pass

A checkpoint is a short retrieval test drawn from this stage: solve 2 of 3 from memory to mark the stage complete. The stage stays open either way.

Tried this set and did not pass? Record it — the next set swaps in fresh problems from the same stage.
LabRecommended next stepXOR BoundaryHard

3The Block

0/7

Wrap attention in the pieces that make it trainable: LayerNorm and its RMSNorm comparison, GELU in both tanh and exact forms, pre- versus post-norm residual scaling, and a full encoder block with its parameter count.

Stage checkpoint

0/2 to pass

A checkpoint is a short retrieval test drawn from this stage: solve 2 of 3 from memory to mark the stage complete. The stage stays open either way.

Tried this set and did not pass? Record it — the next set swaps in fresh problems from the same stage.
LabRecommended next stepXOR BoundaryHard

4Training and Masking

0/6

Teach the stack to predict: numerically stable softmax, the softmax cross-entropy backward pass, padding and sliding-window attention masks, seeded attention dropout, and a mixed-precision loss-scaling step.

Stage checkpoint

0/2 to pass

A checkpoint is a short retrieval test drawn from this stage: solve 2 of 3 from memory to mark the stage complete. The stage stays open either way.

Tried this set and did not pass? Record it — the next set swaps in fresh problems from the same stage.
LabRecommended next stepXOR BoundaryHard

5Decode and Measure

0/6

Run it and count the cost: KV-cache sizing and appends, online-softmax rescaling and logsumexp tracking, quadratic attention FLOPs, and forward FLOPs per token.

Stage checkpoint

0/2 to pass

A checkpoint is a short retrieval test drawn from this stage: solve 2 of 3 from memory to mark the stage complete. The stage stays open either way.

Tried this set and did not pass? Record it — the next set swaps in fresh problems from the same stage.
LabRecommended next stepXOR BoundaryHard

Capstone

Project

Close the path with one real artifact from the catalog.

Build a GPT from Scratch

The full decoder-only transformer, exactly the stack this path assembles piece by piece.