Transformers & model design
Understand the shared Transformer structure, then explore GPT-2, GPT-3, Llama, Mixtral, DeepSeek-V3, Qwen3, and the original Kimi K2 from input embeddings to output logits.
Read each model as an argument: problem → mechanism → measurable payoff → cost. Every detail view links the mechanism back to Tensorium.
From knowing the parts to defending a design
Six connected lessons. Begin with a numerical intervention, then read the explanation, trace tensors, explain it back, and defend a deployment decision. All lessons remain open; answers are self-reviewed and code checks are transparent.
Need the block-level foundation? Revisit the visual Transformer walkthroughBefore the model names: change one thing in a tiny decoder
Start with “the cat sat on the mat”. Predict whether changing later words’ value vectors should affect “sat”, then move the slider. This isolates one attention head; the reading below connects it to normalization, the FFN, and both residual paths.
Can the future change “sat”?
Follow head 1 at position 2 in the course’s fixed toy model. Keep Q and K fixed; add an offset to both coordinates of future value vectors. With the causal mask on, the output must not move. Turn it off to deliberately introduce future leakage.
| Position / token | Raw score | Weight | Value after intervention |
|---|---|---|---|
| 0 · the | 0.169 | 31.73% | [-0.821, -0.224] |
| 1 · cat | -0.180 | 22.40% | [0.840, 0.333] |
| 2 · sat | 0.537 | 45.87% | [0.813, -0.285] |
| 3 · on (future) | 0.277 | 0.00% | [-0.133, -0.131] |
| 4 · the (future) | 0.149 | 0.00% | [-0.839, -0.213] |
| 5 · mat (future) | 0.202 | 0.00% | [-0.899, -0.331] |
Output = Σ weightⱼ × valueⱼ = [0.301, -0.127]
Change from zero offset: [0.000, 0.000]
Exactly zero change: forbidden values have zero weight. This is a useful debugging invariant.
Isolated intervention on one head, not retraining or a benchmark of a real checkpoint.
MODEL DESIGN · LESSON 1 OF 6
What stays recognizably a Transformer?
After this lesson: Reconstruct the invariant skeleton before discussing upgrades.
Imagine explaining “the cat sat on the mat” without using the word attention until you have described its job. Each position needs a representation that can incorporate other permitted positions. Self-attention provides that mixing; a feed-forward network then transforms features at each position. Normalization and residual paths support the repeated computation. Attention is one component, not the entire model.
The original 2017 Transformer was an encoder–decoder architecture for translation. Its encoder reads the source, and its decoder uses masked self-attention and cross-attention to encoder outputs. GPT-2 is a useful published decoder-only reference: no separate encoder or cross-attention is required for its next-token task. This course follows that causal decoder, not every possible Transformer.
GPT-2 uses learned absolute positions, full multi-head attention, pre-LayerNorm, and a GELU MLP. More recent models edit these choices while retaining a residual stream, contextual mixing, local transformations, and an output head. GPT-3 is also a scaling case, not evidence that every capability gain requires a new attention mechanism. We do not infer unpublished GPT-4 internals from its name.
What it buys
A reusable causal block supports parallel teacher-forced training and autoregressive generation.
What it costs
Full attention compares each query with all allowed keys. More layers, wider states, and longer sequences increase work.
Keep the claim bounded: The original Transformer used a different normalization arrangement; the formula here is the GPT-style pre-norm block.
Primary sources and named configurations
- Attention Is All You Need · original encoder–decoder architecture
- GPT-2 technical report · pre-normalized decoder
Sources checked 23 October 2026. Configurations are named historical examples, not a latest-model ranking. Mathematical estimates, report claims, and measured performance are kept separate.
Make the explanation yours · optional
Explain it in your own words
Reconstruct the invariant skeleton before discussing upgrades. Try aloud first, then write your explanation. Compare it with a worked explanation, not a keyword score.
Change the situation: Is “attention is all you need” a literal claim that the model contains only attention?
No. The architecture also includes feed-forward transformations, embeddings, normalization, residual paths, and output projections.
Draft and self-review saved in this browser, not to your account. Do not enter confidential information on a shared device.
Now compare how the eight named models change these components
Select a model name for its full input-to-output architecture, or a mechanism to inspect that block directly.
Design contrasts, not a quality ranking or a claim that these are the latest releases. Model architecture, training recipe, data, and post-training all matter.
The lesson is shareable through this page’s URL. Explanations, self-review, and code drafts are saved in this browser only; they are not independent evidence of mastery.