Teacher guide — Residual streams and attention over depth
Duration: 120 minutes
Positioning: Understand residual dilution, retrieval of earlier states, and depth-checkpoint trade-offs.
Expected evidence: Mixed: established mechanisms + source-reported Kimi K3-style choices.
Observable outcomes and preparation
- Trace a residual stream.
- Compute a depth mixture.
- Evaluate storage cost.
Before class, the instructor runs the worked case and lab, prints the exercise packet, prepares a four-column board—assumption, prediction, observation, delta—and checks that every mathematical notation is paired with dimensions. The demonstration must not become slide reading.
Diagnostic
- Explain in one sentence: Residual connection. What observation would falsify your explanation?
- Explain in one sentence: Dilution. What observation would falsify your explanation?
- Explain in one sentence: Depth states. What observation would falsify your explanation?
Teaching decision: if two of three answers remain nominal or lack a validity condition, rebuild the vocabulary with a numerical example before any formula. A fluent but unfalsifiable answer does not count as mastery.
Timed plan
| Time | Activity | Observable evidence |
|---|---|---|
| 0–10 min | Individual diagnostic, then pair comparison | Three answers and one named uncertainty |
| 10–25 min | Situation and vocabulary | Annotated input → state → output diagram |
| 25–55 min | Develop the mechanism on the board | Shapes, assumptions, and intermediate calculation visible |
| 55–75 min | Worked case with deliberate errors | Reasoned correction, not only the right number |
| 75–95 min | Causal lab: predict, change one variable, run | Prediction / observation / delta table |
| 95–112 min | Exercises 1 and 2 with peer correction | Retained artifact and applied rubric |
| 112–120 min | Exit ticket and transfer | Mechanism, boundary, next experiment |
Teaching notes
Chapter 15 — Residual dilution and Attention Residuals
15.1 Residual streams
Goal: understand how deep Transformers preserve and update information. A residual connection adds a layer’s change to the current representation: x_next = x + F(x).
Intuition: Each editor keeps the current draft and adds a revision instead of rewriting from a blank page.
Step by step
-
Start x₀=[1,2].
-
Layer change F(x₀)=[0.5,−0.2].
-
Residual result x₁=[1.5,1.8].
-
A later layer receives both the old path and the new change.
Worked example: In a very deep network, repeatedly mixing everything into one stream may make some earlier signals difficult to recover. This is called residual dilution in the supplied narrative.
Why it matters: Residual connections help optimization, but they do not guarantee every useful earlier feature stays equally accessible.
Quick check: If x=[3,1] and F(x)=[−1,2], what is x+F(x)? Answer: [2,3].
15.2 Attention over depth
Goal: let a layer choose among earlier representations, not only accept the latest accumulated stream. Attention Residuals, abbreviated AttnRes, use attention-like weighting over depth.
Intuition: A researcher compares several saved drafts and chooses the most relevant passages for the next revision.
Step by step
-
Keep selected earlier layer outputs or block summaries.
-
Compute relevance scores for the current layer.
-
Normalize the scores into weights.
-
Form a weighted mixture and use it in the new computation.
Worked example: three depth states are h₁=[1,0], h₂=[0,2], h₃=[3,1]. Weights [0.2,0.3,0.5] give 0.2h₁+0.3h₂+0.5h₃ = [1.7,1.1].
Why it matters: Attention over depth costs storage and computation. Blockwise AttnRes reduces this cost by keeping or attending to coarser checkpoints rather than every layer output.
Quick check: What do AttnRes weights sum to after softmax? Answer: 1.
15.3 Evidence boundary
Goal: avoid treating an architectural sketch as a released specification. Exact checkpoint spacing, equations and layer placement must be verified from the authoritative Kimi K3 source.
Intuition: A building concept drawing explains the idea but is not the final engineering blueprint.
Step by step
-
Mechanism-level lesson: learned access to earlier depth states may fight dilution.
-
Product-level details: exact block sizes and reported gains require primary evidence.
Worked example: This distinction keeps the course useful even if future releases revise names or numbers.
Why it matters: Scientific reading means tracking what is derived, what is measured and what is merely reported.
Quick check: Which source should settle an exact implementation dispute? Answer: official code or an authoritative technical report for the exact model version.
Running the worked case
Depth scores [2,1,0] over {x₂₄,x₁₂,x₀} give softmax ≈ [0.67,0.24,0.09]. The mixture favors x₂₄, the most recent checkpoint, while the other two together retain 33%.
Do not reveal the result at once. Ask learners to predict the next operation, its shape, and the expected sign. After each line ask: “What changed? What stayed fixed? Which assumption did we use?” A calculation error repaired with a causal chain is worth more than a guessed result.
Lab protocol
- Write a qualitative and, where possible, numerical prediction before touching a control.
- Change one variable only; retain a capture or record initial and final values.
- Explain the delta through the mechanism, not “the tool did that.”
- Test one boundary value and state where the model stops representing a real system.
Misconceptions
| # | Observable misconception | Grounded correction | Probe |
|---|---|---|---|
| 1 | “Residual connection guarantees the outcome without assumptions or measurement.” | Addition changes everything: x_{l+1} = x_l + F_l(x_l). Each layer ADDS its transformation to the stream instead of replacing it; if F ≡ 0, x passes through unchanged — the identity path guarantees a direct gradient to every layer. | Ask for a counterexample, then restate the mechanism with its validity condition. |
| 2 | “Dilution guarantees the outcome without assumptions or measurement.” | Under the assumption of roughly orthogonal contributions (‖F_l‖ = 0.5), the energy follows ‖x_l‖² ≈ 1 + 0.25·l: x₀’s share goes from 100% to 25% (l = 12), 14.3% (l = 24), 7.7% (l = 48). Diluted, never erased — addition is conservative. | Ask for a counterexample, then restate the mechanism with its validity condition. |
| 3 | “Depth states guarantees the outcome without assumptions or measurement.” | The solution: photograph along the way. Keep a few chosen x_j — {x₀, x₁₂, x₂₄} — as retrieval points along depth, the informational analogue of training checkpoints. | Ask for a counterexample, then restate the mechanism with its validity condition. |
Boundary to maintain: AttnRes is presented as a course mechanism and source-reported case study; exact Kimi K3 details require a primary source.
Probing questions
- If we remove or reverse Residual connection, which output changes first, and what observation would show it?
- If we remove or reverse Dilution, which output changes first, and what observation would show it?
- If we remove or reverse Depth states, which output changes first, and what observation would show it?
- If we remove or reverse Depth scores, which output changes first, and what observation would show it?
- If we remove or reverse Blocking, which output changes first, and what observation would show it?
- If we remove or reverse What this does not prove, which output changes first, and what observation would show it?
Assessment
| Level | Criterion |
|---|---|
| 0 | Repeats terms without connecting input, transformation, and output. |
| 1 | Describes the chain but checks neither shape nor assumption. |
| 2 | Executes the case, explains the result, and names one limitation. |
| 3 | Transfers to a new case, compares an alternative, and proposes a measurement that could invalidate the choice. |
Exit threshold: level 2 on the worked case and at least one exercise; a memorized formula without interpretation remains level 1.
Observation and remediation protocol
During discussion, the instructor records evidence rather than impressions. Evidence of understanding contains a named object, a justified transformation, and a checkable consequence. If a learner gives the right result without a chain, ask for the preceding line. If the chain is coherent but the result is wrong, preserve the chain and isolate the arithmetic error. If vocabulary from another concept is used, compare both mechanisms in an input, state, output, cost, and boundary table. Remediation targets the first break only: vocabulary, shapes, operation, interpretation, or claim scope. After correction, use a neighboring case with a changed value; success on the same example does not prove transfer. For pair work, assign operator and verifier roles, then swap. The verifier does not supply the answer: they request an assumption, check the shape, and ask what observation could contradict the reasoning. The instructor retains the exit ticket and classifies the dominant break. The next session opens with a three-minute problem aimed at that break instead of repeating the whole lesson.
Differentiation
- Support: provide shapes and the first transformation; let the learner complete interpretation and boundary.
- Core path: worked case without result, lab with one assigned variable, diagnostic exercise.
- Extension: change one assumption, compare two mechanisms, and define the metric that would decide between them.
Post-session follow-up
Within twenty-four hours, return each annotated exit ticket with one priority, the exact resource to reopen, and a mini-case different from the worked case. Revision requires three items: a written prediction, a retained trace, and one sentence explaining the delta. At the next session, sample two submissions: one that repaired the break and one that remains ambiguous. Discuss them anonymously, then state the criterion that separates them. Do not use completion rate as evidence of mastery. Evidence of remediation is a correct chain on a new case with a stated boundary. If the same break appears in more than one third of the group, repair the support or demonstration before blaming learners.
Follow-up closes only when the new artifact shows the causal chain, check, and boundary—not merely when a file has been submitted.
Sources and evidence boundary
- Owner-supplied bilingual course packet, Chapter 15.
- He et al., “Deep Residual Learning for Image Recognition”, CVPR (2016).
- Elhage et al., “A Mathematical Framework for Transformer Circuits” (residual-stream view), Anthropic (2021).
- Course source packet supplied by the owner; named-product details remain source-reported until primary verification.
Scope: Mixed: established mechanisms + source-reported Kimi K3-style choices. These references support the session frame; they do not turn a reported product choice into an independently verified result.
Exit ticket
In no more than six lines: mechanism; calculation or trace; observation; boundary; evidence level; next experiment. The instructor marks one priority causal break for revision.