00-START-HERE · 01-READING-ROUTES · 07_in_context_learning_the_mechanism_rag_rides_on · 09_prompting_for_retrieval_augmented_systems
| Aspect | Explanation |
|---|---|
| Purpose | Distinguish evidence about one model run from evidence about fixed model weights, then use residual streams, query-key circuits, output-value circuits, and induction heads to reason about Retrieval-Augmented Generation (RAG) failures without claiming more than the evidence supports. |
TL;DR
- RAG attribution scores one input. A circuit describes a fixed weight path that can transfer to later inputs.
- Attention mass shows where information could flow. It does not prove that removing a chunk would change the answer.
- Leave-one-out ablation directly tests document use, but duplicate chunks can hide each other’s contribution.
- The residual stream is a fixed-width information bus. Every layer reads and adds updates in one shared coordinate system.
- A query-key (QK) circuit decides where a head reads. An output-value (OV) circuit decides what it writes.
- An induction head implements the pattern . Literal token matching explains both unseen-string copying and chunk-boundary failures.
- Circuit evidence can support capability and distribution claims. Only an input-level document counterfactual can show that one answer used one document.
The story
Picture the generator as a fixed-width information bus running from token embeddings to answer logits. Retrieved chunks wait at many positions along the route. Attention routes content across positions. The residual stream carries that content through depth while every block reads the same coordinates and adds an update. The bus never widens when retrieval adds chunks. At the answer stop, one -dimensional vector must contain everything needed for the next token. The QK circuit selects the route. The OV circuit sets the cargo. A strong route score cannot certify the cargo, and two heads can follow the same route while writing opposite logit effects. An induction circuit adds a two-head transfer. The first head shifts the previous token forward. The second matches the current token against that shifted token and copies what followed. This lets the bus carry an identifier absent from training. A chunk boundary can preserve the matching token while placing the payload outside the window. The route recognizes the key, but the cargo is gone. The direct residual route then supplies a fluent answer from the parametric prior. Attribution audits one completed bus trip. A gradient measures local sensitivity, a probe reads decodable information, and a Shapley value averages causal credit across chunk combinations. A circuit inspection studies a fixed part of the bus design and can reveal copying capability across inputs. It cannot prove which document controlled one answer. For that claim, remove the document and rerun the trip. The evidence must use the same unit as the claim.
Decoder table
| Technical term | Plain-English meaning | Why it matters |
|---|---|---|
| RAG | Retrieval-Augmented Generation | A system that places retrieved chunks in the generator context. Limit: Retrieval does not prove that the generator used a chunk |
| Prompt instruction | A fixed part of the model input. Limit: Its effect remains input-specific | |
| Retrieved set of chunks | The candidate evidence placed in context. Limit: Presence in is not use | |
| Retrieved chunk | One attribution or ablation unit. Limit: Overlap can make it redundant with another chunk | |
| Number of retrieved chunks | Controls exact and leave-one-out attribution cost. Limit: It does not measure chunk independence | |
| Query | The question supplied to the generator. Limit: Changing changes run-level attribution | |
| Answer | The generated sequence whose score is measured. Limit: Its probability is a margin over many paths | |
| Logit and answer margin | A pre-softmax token score and its gap over competing scores | The emitted token depends on the full margin, not one circuit contribution |
| Softmax | Normalization that turns routing scores into attention weights | Saturation can make a heavily used route have a small local gradient |
| Parametric prior | The answer tendency carried in model weights without retrieved evidence | It produces a fluent fallback when a context-copying path fails |
| A subset of | One coalition in Shapley attribution. Limit: Exact enumeration scales as | |
| Log probability of under , , and | A causal score for comparing chunk subsets. Limit: It applies to one answer and one input setup | |
| Attribution assigned to chunk | A per-chunk contribution score. Limit: It changes with the input | |
| Gradient times input | Sum of embedding times answer-score gradient over a chunk | A one-run differential saliency score. Limit: Saturation can make strong reliance look weak |
| Integrated gradients | A differential method motivated by saturation failures | A less local gradient attribution. Limit: It is still run-level attribution |
| Probe | A classifier trained on an intermediate activation | Evidence that a property is decodable. Limit: Accuracy does not prove that the model uses the direction |
| Selectivity baseline | Probe performance relative to control labels | A check against probe memorization. Limit: It still does not establish causality |
| Leave-one-out | Drop one chunk, rerun, and measure the change | A direct document counterfactual. Limit: Duplicate chunks can each receive zero |
| Cosine threshold | Similarity cutoff for grouping near-duplicate chunks | It turns redundant chunks into one ablation unit before attribution |
| Shapley value | Average marginal contribution over chunk orderings | Credit for specified input interventions under redundancy; not proof of true provenance. Exact enumeration is exponential |
| Sampled Shapley | Approximation from sampled coalitions | Offline causal attribution at lower cost. Limit: It is not suitable for the request path in the chapter example |
| Attention weight | A scalar route weight across positions | Evidence about where information could flow. Limit: It is not exclusive evidence of use |
| Mechanistic circuit | One fixed chain of weight products from embedding to logit | A weight-level claim that transfers across inputs. Limit: It covers one path, not the full answer |
| Residual stream | Fixed-width vector carried through model depth at each position | A shared space for patching, decoding, and steering. Limit: Its width does not grow with retrieval |
| Pre-norm and post-norm | Normalization before versus after an additive sublayer | The clean shared-bus account applies to the pre-norm arrangement in the source |
| Positional and rotary embeddings | Position information added to token representations, with rotary embeddings rotating query and key by relative offset | Residual addition preserves position information but does not create it |
| Superposition | Several features sharing nonorthogonal residual directions | The dimension count suggests shared-coordinate pressure but does not prove a particular feature packing or interference rate |
| Embedding of token t | Input to gradient attribution. Limit: The associated derivative is local | |
| Residual stream at layer l | State read and updated by the next block. Limit: One layer-position state does not certify a document | |
| Residual-stream width | The number of shared bus coordinates. Limit: Width alone does not prevent superposition | |
| Number of layers | Depth of the stack. Limit: Path count grows exponentially in | |
| Number of heads per layer | Per-layer attention count. Limit: Single-head evidence may be small relative to the full stream | |
| Width of one attention head | Maximum rank of one head update. Limit: A head touches only a low-rank slice | |
| Layer normalization (LN) | Normalization applied before a pre-norm sublayer read | Stabilizes the read into each additive block. Limit: It adds a per-position scale to QK scores |
| Multilayer perceptron (MLP) | Non-attention sublayer that adds to the stream | Up to rank write demand per layer. Limit: It contributes to oversubscription and later overrides |
| Token embedding matrix | Maps vocabulary tokens into the residual space. Limit: Token-level circuit formulas are approximate with some serving details | |
| Unembedding matrix | Maps the final residual state to logits. Limit: It reads the same shared basis under the pre-norm bus view | |
| Query projection | One factor in the QK product. Limit: It is not individually identifiable | |
| Key projection | One factor in the QK product. Limit: It is not individually identifiable | |
| Value projection | One factor in the OV product. Limit: It is not individually identifiable | |
| Head output projection | Returns a head update to the residual stream. Limit: It is not individually identifiable | |
| Product | Determines the attention pattern. Limit: It does not determine what the head writes | |
| Product | Determines the channel update. Limit: It does not determine where the head reads | |
| Attention matrix | Mixes positions on the left of . Limit: It says nothing by itself about the OV content | |
| Attention from position to position | One run’s routing factor. Limit: It is recomputed for every input | |
| Pre-softmax attention score | Pairwise routing score. Limit: A one-layer score only sees the two current token identities | |
| Vocabulary-expanded QK bilinear form | Scores query-token and key-token pairs. Limit: It has no copying eigenspectrum | |
| Vocabulary-expanded OV linear map | Maps an attended token to logit changes. Limit: Materializing it is prohibitively large | |
| Gauge freedom | Invertible basis change inside one head | Explains why only projection products are identifiable. Limit: Individual matrix columns are coordinate conventions |
| Eigenvalue | Spectral value of the reduced OV operator | Indicates copying or suppression direction. Limit: The result is a weight-level statistic |
| Copying score | Mean normalized real part of OV eigenvalues | Cheap copier scan across heads. Limit: Its null floor changes with |
| Skip-trigram copying | One-layer memorized association such as are to perfect | Copying of learned token patterns. Limit: It does not generalize to an unseen identifier |
| Previous-token head | Layer-1 head that shifts token j-1 into position | Creates the key-side state needed for induction. Limit: The payload still must remain in the window |
| Induction head | Two-layer circuit implementing | Context copying for unseen strings. Limit: Production-scale causal evidence remains limited |
| Virtual attention head | Functional unit visible through a composition of heads | A composed mechanism not found in either head alone. Limit: Composition search grows rapidly with depth |
| Prefix-matching score | Attention from a current token to the position after an earlier copy | One-pass correlational locator for induction heads. Limit: Causality requires ablation |
| In-context learning score | Later-minus-earlier token loss under a specified evaluation distribution; distinct from random-repeat prefix matching | Regression signal for copying behavior. Limit: It does not prove document use on one answer |
| Fuzzy induction | Approximate matching by synonym, translation, or nearby direction | A mechanism for nonliteral context reuse. Limit: It can copy the neighboring wrong span |
| Constrained decoding | A sampler rule that restricts output to an allowed source string | It gives a quotation guarantee that a copying spectrum cannot provide |
| Quantization | Lower-precision model representation used for serving | Copying behavior can change across a precision swap before fluency reveals it |
| Direct residual path | Non-head path that continues to influence logits | Explains fluent fallback when copying fails. Limit: It can override a correct copying contribution |
| Activation patching | Replace an activation in one run with the corresponding clean activation | Causal localization at a layer and position. Limit: Its unit is a model coordinate, not a document |
| Logit lens | Apply the unembedding to intermediate residual states | Shows when a candidate token becomes decodable. Limit: Early-layer readout can be degenerate |
| Tuned lens | A trained layer-specific readout | Improves early-layer decoding. Limit: It is still a readout rather than proof of use |
| Steering vector | Additive intervention in residual space | Behavioral control that respects the additive bus. Limit: Addition does not directly delete a direction |
| Rung 1 | Claim about fixed weights and every input | Circuit scan and prefix-matching evidence. Limit: It cannot prove a specific answer used a chunk |
| Rung 2 | Claim in expectation over a query distribution | Head knockout on held-out queries. Limit: It transfers only to the sampled distribution |
| Rung 3 | Claim about one answer and one document | Document counterfactual. Limit: It says nothing about other inputs |
| top- | Maximum retrieved chunks passed into the generator | It caps document-level ablation cost while model head count keeps growing |
Core mechanics
Mathematical conventions
Use natural logarithms and nats for likelihoods. Row-vector convention is used throughout: , , , and . The four-projection and gauge counts assume an ordinary independent-head, non-rotary attention model; grouped-query sharing and rotary position encoding require adjustments. Attention includes a causal mask where appropriate, omitted only in schematic products. Storage is decimal except explicit KiB, MiB, GiB or TiB. Replay costs combine a prefill proxy with a weight-bandwidth decode proxy; neither is measured end-to-end latency. Coalition budgets charge every replay the full-context cost for illustration, although shorter coalitions and fixed-answer likelihood scoring can be cheaper. Keep precision until display.
8.1 Feature attribution versus mechanistic interpretability
The attribution object
| Aspect | Explanation |
|---|---|
| What | The model sees an instruction, retrieved chunks, and a query. It emits answer . The subset value is: An attribution method returns one value per chunk. |
| Why | The value lets an incident review compare the same answer under different evidence subsets. |
| Failure without it | Attention mass can look decisive while the answer still comes from the parametric prior. |
| Cost or complexity | The cost depends on whether the method differentiates, probes, ablates, or enumerates coalitions. |
Differential attribution
| Aspect | Explanation |
|---|---|
| What | For row embeddings, gradient-times-input gives the scalar score . This is a local differential score, not a unique decomposition of causal source use. |
| Why | It obtains a chunk score from one backward pass after the forward pass. |
| Failure without its limit | A saturated softmax can hide total reliance. For one attention weight: At , sensitivity is . The maximum is at . The relative attenuation is . |
| Cost or complexity | One backward pass is cheap, but the result is a first-order local approximation. Sundararajan et al. (2017) used saturation as the motivating axiom failure for integrated gradients. |
Probing
| Aspect | Explanation |
|---|---|
| What | A probe predicts a property such as grounding from a residual activation. |
| Why | High accuracy shows that the property is linearly decodable. |
| Failure without its limit | Decodability does not show that the model reads that direction. Hewitt and Liang (2019) showed that capable probes can fit random control labels. |
| Cost or complexity | Training and a selectivity baseline are required before the accuracy is informative. An intervention is still required before calling the direction a mechanism. |
Shapley attribution
| Aspect | Explanation |
|---|---|
| What | For a fixed answer , exact Shapley credit averages marginal changes in the chosen score: . Use cardinalities, not vector norms. |
| Why | It allocates the effect of specified input-subset interventions, including interactions. This is not proof of source truth, historical training membership or unique internal provenance. |
| Failure without it | Two redundant chunks can have zero individual leave-one-out effect. In a separate binary or normalized utility game, let and . Each gets Shapley credit. These utility values are not literal log probabilities from the earlier score. |
| Cost or complexity | Exact memoized enumeration needs subset-score evaluations, not necessarily generations. At , this is values. Charging the full replay proxy gives about single-GPU-equivalent days; evaluations give about minutes. Monte Carlo variance, coalition weighting, interactions and estimator choice determine accuracy. |
Circuits and attention
| Aspect | Explanation |
|---|---|
| What | A circuit isolates one direct product of weight matrices. For one head’s direct OV route to logits, the chapter uses: |
| Why | The weight product is fixed, but its actual contribution depends on the run-specific attention, activation state and downstream nonlinear processing; it does not prove use on every later query. |
| Failure without the distinction | A gradient aggregates all routes for one run, while a circuit isolates one route across runs. Jain and Wallace (2019) found weak correlation between attention and gradient importance in attention-based classifiers. They also produced very different attention distributions with equivalent predictions. Wiegreffe and Pinter (2019) argued that adversarial attention needs a baseline. Their narrower conclusion allows attention to remain plausible evidence. The defensible claim here is only that attention weight is not exclusive evidence of use. |
| Cost or complexity | Expanding all routes creates: end-to-end terms in an attention-only stack. At and the count is . Elhage et al. (2021) enumerated that small case. At and the count is . Even depth-two compositions in the -layer, -head model produce head pairs. Three query, key, and value composition routes make norms. |
Worked attribution budget
| Aspect | Explanation |
|---|---|
| What | The -billion-parameter model uses the prefill proxy at : or for tokens. A single-batch weight-bandwidth decode proxy is , or for tokens. Their sum is . KV traffic, kernels, compute limits, batching and intervention overhead can change the measured time. |
| Why | This price converts abstract evidence choices into incident and serving budgets. |
| Failure without it | Teams can fund exhaustive analysis for a question that a cheap document ablation settles. |
| Cost or complexity | Leave-one-out takes replays and for chunks. Exact Shapley takes replays and days. Sampled Shapley takes replays and minutes. De-duplicate before attribution. Collapse near-duplicates above a cosine threshold into one ablation unit. If six chunks repeat one fact, treat the retrieval budget as the finding. Use saliency only to rank the first ten ablation candidates when reaches the hundreds. Lundberg and Lee (2017) introduced sampled kernel estimation to make Shapley attribution usable at this scale. Run attribution offline, and log the prompt, retrieved chunk identifiers, and sampling seed for replay. Use generation-time citation when per-answer provenance is required. Treat a AUC probe as a monitor until an intervention shows use. Reserve circuit work for failures that repeat across hundreds of unrelated queries. |
8.2 The residual stream as an information bus
Plain composition and its two failures
| Aspect | Explanation |
|---|---|
| What | A plain deep stack computes: |
| Why | This form exposes why residual addition changes more than gradient flow. |
| Failure without residuals | A plain-stack gradient is a product of Jacobians. In the special scalar or isotropic-gain illustration, and . A mean singular value of or alone does not determine the product norm because directions and layer alignment matter. Residual coordinates facilitate comparisons, but not every non-residual network is uninterpretable or ill-typed. |
| Cost or complexity | The issue grows with depth through a product of Jacobians. |
Additive pre-norm blocks
| Aspect | Explanation |
|---|---|
| What | A residual block computes: The chapter’s pre-norm attention and MLP update is: |
| Why | Every block reads and writes the coordinate system created by the embedding. The gradient contains a pure identity route because: He et al. (2016) provide the residual-network anchor for that identity path. |
| Failure without it | Activation patching, the logit lens, and steering lose their shared basis. |
| Cost or complexity | For linearized blocks, expands into ordered products, including the identity. Matrix order matters; writing a commutative scalar product is only a mnemonic. Nonlinear blocks do not yield a literal fixed linear-path expansion without further assumptions. |
One head on the bus
| Aspect | Explanation |
|---|---|
| What | One head reads through and writes through . For and the update rank is at most . |
| Why | The linear map has rank at most and nullity at least . This identifies a nullspace, not untouched coordinate axes or a guarantee that the whole head leaves those directions unchanged once routing depends on the input. |
| Failure without the distinction | Teams patch a small head when the full answer-position stream is the causal state they need. |
| Cost or complexity | Counting attention heads plus one MLP per layer gives writes. If writes are independent isotropic unit vectors with zero cross terms in expectation, the root mean square norm is ; one unit is about of that scale. Real correlated or unequal writes need not obey this model, and norm share is not causal answer importance. |
Oversubscription and superposition
| Aspect | Explanation |
|---|---|
| What | Standard parameterization uses: Attention writes dimensions per layer. The MLP can write another . |
| Why | The sum of maximal attention and MLP output ranks over layers is at most , yielding the dimension-counting ratio at . This is a heuristic for repeated writes into shared coordinates, not a theorem that independent feature sets must collide or that a specific amount of superposition is necessary. |
| Failure without enough independent directions | Features share nonorthogonal directions. Elhage et al. (2022) call this superposition. Some heads and neurons also appear to delete information, as reported by Elhage et al. (2021). |
| Cost or complexity | Independent isotropic unit vectors in have root mean square inner product . The RMS projected norm onto a fixed -dimensional orthogonal subspace is , with expected squared norm . These random-geometry values are not measured readout interference. The illustrative factors are for depths ; they do not alone measure feature demand. |
The retrieval funnel
| Aspect | Explanation |
|---|---|
| What | With row-vector states, the next-token logit row is . The same dimensions are used in the vocabulary-expanded maps. |
| Why | Each next-token prediction reads a -dimensional current state, but later decoding steps can attend again to the retained context KV cache. This is not a one-time compression of the whole context into one permanently closed state. |
| Failure without enough selection | Distractors can impair evidence use, but fixed residual width or a context-to-position count alone does not prove such impairment or an information-capacity threshold. Measure answer quality and interventions. |
| Cost or complexity | Fifty chunks of tokens create positions. One layer of half-precision residual states occupies mebibytes (MiB). The answer position occupies kibibytes (KiB). The funnel is . Reducing from to cuts layer storage from to . It leaves the answer state at . |
Caveats and practical choices
| Aspect | Explanation |
|---|---|
| What | The clean shared-bus statement applies to the pre-norm arrangement. |
| Why | The original Transformer used post-norm and rescaled the bus in place. Xiong et al. (2020) analyzed the training stability of pre-norm. |
| Failure without the caveat | Pre-norm addition preserves an identity residual route, not immunity to all changes in representation. Positional information may enter through embeddings or through attention rotations such as RoPE. Unmasked attention without position signals is permutation-equivariant; a causal mask already distinguishes prefixes, so the blanket statement needs that unmasked-attention qualification. |
| Cost or complexity | Patch aligned layer/position states and measure effects; a tuned lens may improve decoding. Keep retrieval depth evidence-driven, not determined by the per-position payload. Projection can remove a chosen activation component without deleting a fact from the model. Comparing • and -chunk states requires aligned answer positions and appropriate baseline/patch runs; two arbitrary forwards do not establish a complete causal test. |
8.3 QK and OV circuits
One attention head
| Aspect | Explanation |
|---|---|
| What | For context matrix with positions and width : |
| Why | The equation separates routing from channel transformation. |
| Failure without the split | A attention weight gets mistaken for proof that the right content was written. |
| Cost or complexity | Each head has four projection matrices. For and one head has projection parameters. |
Gauge-invariant products
| Aspect | Explanation |
|---|---|
| What | For any invertible matrix : The product stays fixed. The same basis freedom holds for and . |
| Why | Only the products describe the model function independently of the head’s internal coordinate choice. |
| Failure without it | A statement about one column of , , , or becomes a statement about an arbitrary basis. |
| Cost or complexity | For full-rank independent projections without rotary transformations, two gauge actions have dimension , or of projection parameters. Degeneracy and sharing can change this count. With fixed RoPE rotations, an arbitrary QK basis transform need not preserve scores; it must satisfy the relevant rotation-commutation conditions. |
Where to look and what to move
| Aspect | Explanation |
|---|---|
| What | Define: Then: |
| Why | mixes position rows and mixes channels. The equality is matrix associativity with fixed , not a claim that these differently shaped matrices commute or that is independent of . |
| Failure without it | A correct QK route can hide an OV write that copies, suppresses, or changes the wrong token. |
| Cost or complexity | The split is exact for the head computation and drops no term. |
Vocabulary-expanded circuits
| Aspect | Explanation |
|---|---|
| What | The expanded maps are: |
| Why | One OV entry gives the logit shift from an attended source token to a target token. One QK entry gives a score contribution from a query-side token and a key-side token. |
| Failure without the type distinction | A bilinear QK form gets treated as an operator with a copying spectrum. Only the linear vocabulary-to-vocabulary OV map has that spectrum. |
| Cost or complexity | The full OV map for a -token vocabulary has entries. It occupies , or gibibytes (GiB), in half precision per head. Across heads, it would occupy tebibytes (TiB). |
Low-rank spectrum
| Aspect | Explanation |
|---|---|
| What | Factor the expanded OV map: The nonzero eigenvalues of equal those of . |
| Why | is only . |
| Failure without the reduction | The vocabulary-expanded map is too large to materialize. |
| Cost or complexity | The reduced matrix has entries, or at two bytes each, and across heads. The entry-count ratio is . These are payload sizes, not eigensolver workspace or an accuracy recommendation for half precision. An eigensolver-work proxy is about operations before algorithm constants; forming the reduced products can cost much more and is omitted. Laptop runtime must be benchmarked. The GPT-2 entry ratio is . |
Copying score and null
| Aspect | Explanation |
|---|---|
| What | As an explicitly defined heuristic, let , with for and . Eigenvalues summarize the reduced OV operator; positive real parts are not by themselves a token-by-token copying guarantee. |
| Why | A copier raises the logit of the token it attends to. |
| Failure without a null | A sign-symmetric random-product ensemble can have mean zero for this odd score. The heuristic follows an independent uniform-angle approximation; real-matrix eigenvalues are dependent and conjugate-paired, and trained/tied embeddings violate simple ensemble assumptions. This is not a calibrated null standard deviation for a deployed model. |
| Cost or complexity | suggests a rough screening flag only under that null approximation. Estimate an empirical null and account for scanning heads; this is not a conservative family-wise significance threshold. |
Serving-model caveats
| Aspect | Explanation |
|---|---|
| What | The expanded formulas are exact for the one-layer attention-only model with learned absolute positions analyzed by Elhage et al. (2021). |
| Why | Layer normalization rescales each position before a read. Rotary embeddings insert a relative rotation between query and key. |
| Failure without the caveat | RoPE changes QK routing; layer normalization changes the activations read by the value path and the final logit mapping. The weight product remains fixed, but its vocabulary-expanded contribution is not untouched by normalization or nonlinear downstream computation. |
| Cost or complexity | Move the gold chunk between first and last position to classify QK-side failures. If attention is diffuse rather than misplaced, cut . Inspect and rather than individual projections. Per-matrix deltas remain meaningful only when two checkpoints share a fixed basis. Use the OV spectrum to scan copying machinery and attention statistics to inspect routing. Route persistent OV-side failures to a low-rank adapter, steering, a different base model, constrained decoding, or another decode-level intervention. Changing retrieval, reranking, chunking, or ordering changes and the QK route. It does not change . Record across all heads on each base-model change and rederive its floor when changes. |
8.4 Induction heads and advanced copying
The one-layer ceiling
| Aspect | Explanation |
|---|---|
| What | The token-only term of a one-layer score is up to the attention scale. Real scores also include position and mask effects. This isolated term cannot read the predecessor identity at unless it is already represented in its input. |
| Why | The score depends only on the identities of and . |
| Failure without another layer | The desired location is marked by , not by payload token . An unseen part number has no trained bigram entry that points to its payload. |
| Cost or complexity | One-layer heads can implement memorized skip-trigram associations. They cannot implement the general unseen-token pointer by this score alone. |
The two-layer construction
| Aspect | Explanation |
|---|---|
| What | Using row vectors, a previous-token head contributes . The induction score contains the dimensionally valid term , omitting scaling, mask, position terms and other residual contributions. The transposed predecessor write is a column, giving a scalar score. |
| Why | Training can make the composed vocabulary map close to a positive multiple of the identity. Then the score is high when the current token matches the predecessor copied into position . The layer-2 OV circuit copies into the logits. |
| Failure without the composed identity | The circuit would depend on the specific content and . The near-identity composition names no specific identifier or payload. |
| Cost or complexity | The mechanism implements with two layers. Elhage et al. (2021) call the pair an induction head and the composition a virtual attention head. |
Why chunk boundaries break copying
| Aspect | Explanation |
|---|---|
| What | Literal identity matching finds an earlier occurrence of the current token. The payload is the token immediately after that earlier occurrence. |
| Why | A retrieved chunk can therefore support an identifier never seen in training. In the source example, X-4471-B and days become a confident days two weeks after rechunking into -token windows with no overlap. The weights, retriever, and correct indexed row do not change. |
| Failure without the payload in the window | A boundary can preserve the key and remove the next token. The direct residual path then produces a plausible prior answer. That explains a fluent wrong number rather than an abstention. |
| Cost or complexity | Keep atomic records within one chunk. Apply the same normalization to query and corpus text. Use one delimiter template across demonstrations, chunks, and questions. Use lexical retrieval for identifiers that must appear literally. |
Claim limits
| Aspect | Explanation |
|---|---|
| What | Olsson et al. (2022) observed a training phase change where the in-context learning score rose as induction heads formed. They causally knocked out heads in small attention-only models. |
| Why | The joint change and knockout support the induction account in those settings. |
| Failure without the boundary | Correlational production-scale evidence gets reported as a causal explanation of the served model. Models with real depth also contain fuzzy heads that can match synonyms, translations, or fixed strides. Fuzzy copying can select a neighboring wrong span. |
| Cost or complexity | Copying is a mechanism, not a faithfulness guarantee. Verbatim quotation requires constrained decoding. |
Random-repeat probe
| Aspect | Explanation |
|---|---|
| What | Double a random -token sequence. A uniform predictor over tokens has loss nats or bits per token. A second-copy loss of nats is a relative log-loss reduction , not a copying probability or accuracy. Its geometric mean probability on observed next tokens is . |
| Why | The repeated prefix provides a controlled source of next-token predictability; other mechanisms can exploit it too. Neither loss reduction nor prefix matching alone identifies a unique circuit. |
| Failure without the probe | A base-model or quantization change can degrade copying before a RAG evaluation set catches it. |
| Cost or complexity | A -token parameter-work proxy is ; sequences give . Multiplying by baseline/ablation conditions gives or minutes before intervention and logging overhead. Distinguish the random-repeat prefix-matching test from the published later-minus-earlier token-loss ICL metric; the formula alone does not specify the same test distribution. Probe serving precision and context length, not just bf16. |
Chunking cost example
| Aspect | Explanation |
|---|---|
| What | A -row table at tokens per row contains tokens. |
| Why | It makes record fragmentation measurable. |
| Failure without overlap | For fixed -token rows starting at offset zero, -token windows make chunks and internal boundaries. Boundary is row-aligned exactly when , or . Thus are aligned and split a row, affecting of rows. The earlier calculation incorrectly treated deterministic modular positions as uniform random offsets. |
| Cost or complexity | A -token overlap gives stride and chunks, a index-row factor. With final partial chunks retained, processed text is tokens, an embedding-token factor , not exactly the chunk-count factor. Because overlap exceeds the record length, each record is wholly present in at least one chunk in this setup; retrieval still must return that chunk. Real variable-length/tokenized rows require record-aware handling. Delimiter tokenization must be checked with the actual tokenizer. |
8.5 What circuits license and what they do not
Routing factor and weight factor
| Aspect | Explanation |
|---|---|
| What | One head’s source-position influence factors into a run-specific route and a fixed weight map. After unembedding, source position contributes: |
| Why | Circuit analysis freezes the left factor and reads the right factor from the weights. |
| Failure without the distinction | Naming an induction head gets treated as proof that it used chunk on this input. |
| Cost or complexity | The attention factor must be recomputed on every run. The fixed circuit transfers across runs but does not identify one document’s causal role. |
One addend versus the answer
| Aspect | Explanation |
|---|---|
| What | For fixed activations and attention, one can trace head contributions. A production nonlinear transformer’s final logits are not generally a finite sum of fixed weight-only paths with no activation, normalization or MLP terms. |
| Why | The emitted token depends on the margin over the entire sum. |
| Failure without this limit | One correct circuit contribution gets mistaken for control of the answer. The source example gives the right token a -nat push from one copier. The rest of the stack gives the wrong token a -nat push. The wrong token wins by while the copier still behaves exactly as predicted. |
| Cost or complexity | Head-by-head explanation scales with the model’s head count and path count. |
Three evidence rungs
| Aspect | Explanation |
|---|---|
| What | Rung 1 concerns weight-level structural capability, not a guarantee that the behavior occurs on every input. OV products are weight statistics; prefix matching is a run/distribution statistic and is not a property read from weights alone. |
| Why | It supports a capability statement such as this stack copies from context. |
| Failure without the quantifier | A weight-level property gets applied downward to one answer. |
| Cost or complexity | The chapter’s scan costs per model. |
| What | Rung 2 concerns expectation over a query mix. Head knockout on held-out queries licenses this claim. |
| Why | It shows that selected heads carry copying on the sampled distribution. |
| Failure without the quantifier | The result gets transferred beyond the query distribution. |
| Cost or complexity | The chapter’s causal scan costs minutes per model. |
| What | Rung 3 concerns one answer and one document. Dropping the chunk and rerunning licenses this claim. |
| Why | It answers whether the answer changed when that document disappeared. |
| Failure without matching units | Head patching returns a layer or head when legal asks about a document. |
| Cost or complexity | A -chunk answer takes replays and . Inference can move upward as a lead. It never moves downward as proof. |
Why head-level causal tracing loses the audit
| Aspect | Explanation |
|---|---|
| What | Activation patching can causally localize an input-specific effect. Meng et al. (2022) patch clean activations into corrupted runs. |
| Why | The method can reach an input-specific claim. |
| Failure without unit alignment | Its output is a model coordinate rather than a document. Once positions map to chunks, direct chunk ablation answers the document question more cheaply. |
| Cost or complexity | Patching all heads plus a baseline takes replays. At each, that is , or minutes per answer. Document ablation takes . The ratio is , exactly . |
Audit-scale economics
| Aspect | Explanation |
|---|---|
| What | Audit of daily answers. That creates audited answers. |
| Why | The calculation compares evidence in document units with evidence in head units. |
| Failure without the comparison | A team pays for more expensive evidence that does not answer the stated question. |
| Cost or complexity | Document ablation costs approximately or single-GPU-equivalent hours per day. Head patching costs approximately or hours. Their ratio is when every replay is charged equally. Continuous-capacity equivalents are of one GPU versus GPUs; batching and overhead change actual reservations. |
Licensed claims and remaining limits
| Aspect | Explanation |
|---|---|
| What circuits license | • Capability claims that survive the next query. • Predictions about chunk boundaries, one-sided normalization, and retokenized delimiters. • Cheap regression probes for base-model and quantization changes. • Distribution-tested interventions that act on heads. A calibration-set intervention can locate gullible heads and reduce their attention to low-credibility spans at inference. |
| What circuits do not license | • A claim that one answer used one cited chunk. • A guarantee that copied content is true. • A guarantee that fuzzy copying selected the correct neighboring span. • A causal production-scale explanation merely because a copying head was located. |
| Evidence and limitations | Rashkin et al. (2023) define attribution as a predicate over a source and a statement. That operational instance-level definition already uses document units. Min et al. (2023) found that more than of both supported and unsupported sentences carried citations. Citation presence therefore did not discriminate support in that result. Olsson et al. (2022) provide knockout evidence for small attention-only models. Their production-scale evidence remains correlational. “Our model has induction heads” is not a finding by itself. Their absence or a score collapse after quantization would be a finding. Copying a stale or poisoned source can be mechanically faithful and factually wrong. Mechanism is not warrant. |
| Operating rule | Run rung 1 per model build, rung 2 per release when head identity matters, and rung 3 per incident or audit slice. Use generation-time citation with sampled document ablation for provenance. Pair copying claims with source credibility unless ingestion already settled a single curated internal store. |
Diagrams
Figure 8.1
Diagram description and source
flowchart LR
C["Chunk token c_i"]
H11["Layer 1 head 1"]
H12["Layer 1 head 2"]
H21["Layer 2 head 1"]
H22["Layer 2 head 2"]
L["Logit for answer a"]
C -.->|attribution route| H11
C -.->|attribution route| H12
H11 -.-> H21
H11 -.-> H22
H12 -.-> H21
H12 -.-> H22
H21 -.-> L
H22 -.-> L
C ==>|one fixed circuit path, W_U W_O W_V W_E| L
| Method over chunks | Forward passes | Time in the figure |
|---|---|---|
| Saliency map | forward plus a backward pass | Forward proxy alone is ; total saliency time is not priced |
| Leave-one-out | ||
| Sampled Shapley | min | |
| Exact Shapley | days |
Figure : Saliency is a local derivative, a probe tests decodability, and Shapley values allocate a chosen subset-intervention score. None proves unique historical provenance or source truth. A fixed OV weight map is reusable across inputs but does not guarantee that its path controls the next answer. With equal full-replay charges, document conditions take approximately , sampled coalition evaluations take minutes, and exhaustive values take GPU-equivalent days. Fixed-answer scoring, shorter subsets and caching can change these budgets.
Figure 8.2
Diagram description and source
flowchart TB
E["Token embedding plus positional encoding"]
R["Residual stream, d = 4,096"]
A1["Layer 1, 32 heads, read LN(x), add update"]
M1["Layer 1 MLP, read LN(x), add update"]
AH["Layer 24, head h, read 128 dimensions, add rank at most 128"]
M32["Layer 32 MLP, read LN(x), add update"]
U["W_U LN(x_L) to logits"]
E --> R
R -.->|normalized read| A1
A1 --> R
R -.->|normalized read| M1
M1 --> R
R -.->|normalized read| AH
AH --> R
R -.->|normalized read| M32
M32 --> R
R --> U
| Context side | Answer side |
|---|---|
| One answer position | |
| at one layer | |
| All positions can hold retrieved content | This vector decides the next token |
Figure : A -position layer contains approximately of bf16 residual values while one position contains . This count ratio is not an information-loss or recall bound: each subsequent token can read the context KV cache again. Fixed width motivates testing selection and interference, not asserting that more retrieved tokens must hurt.
Figure 8.3
Diagram description and source
flowchart LR
XI["x_i at answer position"]
XJ["x_j at chunk-4 token"]
WQ["W_Q"]
WK["W_K"]
S["score s_ij / sqrt(d_h), alpha_ij = 0.9"]
WV["W_V"]
WO["W_O"]
UP["add alpha_ij x_j W_OV into x_i"]
XI --> WQ --> S
XJ --> WK --> S
XJ --> WV --> WO --> UP
S -.->|routing scalar| UP
| Circuit | Matrix shape | Maximum rank | Question |
|---|---|---|---|
| Where to look | |||
| What to move |
| OV spectrum | Visual pattern from the figure | Copying score |
|---|---|---|
| Copying head | Eigenvalues cluster near the positive real axis | |
| Random initialization | Eigenvalues spread across a disk |
Figure : QK routing and the fixed OV map separate two aspects of a head. The reduced OV spectrum is an efficient weight-level heuristic, not proof that a particular attended token is copied or that a cited chunk caused the answer. A deployed null requires model-specific calibration, especially with rotary positions, normalization and shared projections.
Figure 8.4
Diagram description and source
flowchart LR
A1["X-4471, t_(j-1)"]
B1["30 days, t_j"]
A2["X-4471, t_i"]
OUT1["30 days, predicted"]
A1 -->|1. previous-token write| B1
A2 -->|2. QK attends to shifted match| B1
B1 -->|3. OV copies t_j| OUT1
Diagram description and source
flowchart LR
K["X-4471, chunk ends"]
M["30 days, not retrieved"]
Q["X-4471, t_i"]
P["90 days, prior, not copied"]
K -.->|chunk boundary| M
M --x|copy target outside window| Q
Q -->|direct residual prior| P
Figure : The induction circuit is what lets a generator quote a string absent from its training data: a layer-1 head shifts every token onto the following position, and a layer-2 head attends wherever that shifted token matches the current one, then copies what came next. Because the match is on literal token identity and the payload is the next token, a chunk boundary that separates the two (b) removes the copy target while leaving the match intact, and the direct residual path answers from the parametric prior - fluent, and wrong.
Figure 8.5
| Rung and claim | Evidence that licenses it | Unit and cost |
|---|---|---|
| Weight-level structural capability, not behavior on every input | OV/QK products and architecture; a prefix-matching scan is separately input-dependent | Weight products or sampled activations; is only the repeat-probe work proxy |
| Distribution-level intervention effect | Ablate identified heads on held-out queries with matched baselines | Heads by queries; about minutes only for the stated -sequence scan |
| One-answer input intervention effect | Remove or replace a named chunk and compare under controlled decoding; test redundancy | Document units; equal-cost conditions give about |
Diagram description and source
flowchart TB
R1["Rung 1, weight claim"]
R2["Rung 2, distribution claim"]
R3["Rung 3, answer and document claim"]
R3 -.->|upward inference is a lead| R2
R2 -.->|upward inference is a lead| R1
R1 --x|downward inference is not proof| R3
Figure : Weight-level capability, held-out intervention effects and one-answer document interventions are different evidence units. A fixed path does not guarantee behavior on every input; a prefix-matching scan itself samples inputs. Document ablation measures the effect of the chosen removal intervention, not unique provenance or source truth. Redundancy, stochastic decoding and prompt-length changes need controls.
Whiteboard pack
Drawing order
. Draw a vertical box labeled residual stream with width .
. Add token embedding and positional encoding at the top.
. Draw two sublayers beside the box. Use dashed arrows for normalized reads and solid arrows for additive writes.
. Draw two token positions. Show attention moving information sideways between them.
. Split one head into for where to look and for what to move.
. Add a previous-token head, then a second head that matches [A] and copies [B].
. Finish with the three evidence rungs. Cross out any downward move from circuit evidence to one-answer proof.
90 to 100 word script
Start with the residual stream as a fixed-width bus. Each block reads a normalized copy and adds an update in the same coordinates. Attention moves information across positions. The stream carries it through depth. Split one head into QK, which chooses where to read, and OV, which determines what to write. Compose a previous-token head with a copying head and you get induction: [A][B] followed later by [A] predicts [B]. That explains unseen-string copying and chunk-boundary failures. But a circuit describes fixed weights, not one answer. To prove document use, drop that chunk, rerun, and compare.
Interview traps
1. “The answer attends 0.9 to the policy chunk. Did the model use it?”
No, because the weight shows strong routing but does not show whether the OV write changed the final answer margin. Drop the chunk and rerun. For chunks, the worked cost is replays and .
2. “Leave-one-out says no chunk mattered, but the answer came from context. Is ablation broken?”
Check redundancy first. If chunks and both contain the fact, dropping either leaves the other, so both leave-one-out marginals become zero. Group near-duplicates before ablation or use sampled Shapley, because exact Shapley costs replays in the example even though it splits credit correctly.
3. “Why do residual connections matter beyond gradient flow?”
Additivity preserves one shared basis from embedding to unembedding, so activation patching, layerwise logit decoding, and steering remain well-defined. The answer-position stream stays fixed at dimensions as grows, while position signals can be introduced at input or through attention rotations; a causal mask also breaks unrestricted permutation symmetry.
4. “The correct chunk gets 0.9 attention, but the model attaches its number to the wrong entity. Is retrieval at fault?”
The observed route says QK may have worked, but the failure can live in OV or in later layers that overwrite the correct update. Permute chunk positions to test routing sensitivity, then patch and decode the answer-position stream layer by layer. Do not interpret or alone because gauge freedom makes each projection basis-dependent.
5. “We found induction heads. Can we claim this answer used chunk 4?”
No, because a circuit fixes a weight-level transformation across inputs but does not fix the run-specific attention factor or the full logit sum. Use document ablation for the one-answer claim, and state the quantifier on every finding.
Key numbers
| Topic | Value | Meaning |
|---|---|---|
| Example generator | parameters | Model used throughout the chapter |
| Opening incident | -minute review, -day answer, -day chunk at position of | Attribution separates two fixes that each cost a quarter |
| Prompt length | tokens | Prefill example |
| Answer length | tokens | Decode example |
| Sustained throughput | FLOP/s | Replay-cost assumption |
| Prefill work | FLOPs per token | Twice the parameter count |
| Prefill time | per token | Derived from throughput |
| Full prefill | Unrounded -token parameter-work proxy | |
| Half-precision weights | Decode bandwidth example | |
| High-bandwidth memory rate | Decode bandwidth assumption | |
| Decode time | per token | Weight-read time |
| Full decode | -token answer | |
| One replay | Sum of idealized prefill and bandwidth decode proxies | |
| Saturated attention example | Sensitivity falls to | |
| Maximum softmax sensitivity | Reached at | |
| Saturation attenuation | ||
| Leave-one-out at | replays | Baseline plus one drop per chunk |
| Leave-one-out time | One answer | |
| Chunk overlap example | Creates duplicate “ days” chunks and | |
| Duplicate Shapley credit | each | Credit splits across the two duplicate chunks |
| Sampled Shapley | replays | Sampled coalition count |
| Sampled Shapley time | min | Offline audit scale |
| Exact Shapley | replays | coalitions |
| Exact Shapley time | Approximately GPU-equivalent hours | Constant full-replay-cost budget, not measured subset-scoring time |
| Mechanistic paths at | Full attention-only path expansion | |
| Mechanistic paths at | Production-depth path expansion | |
| Depth-two head pairs | -layer, -head stack | |
| Depth-two composition norms | Query, key, and value routes | |
| Residual width | Chapter model | |
| Vanishing-gradient example | Signal left through a plain stack | |
| Exploding-gradient example | Signal multiplier through a plain stack | |
| Layers | Chapter model | |
| Heads per layer | Chapter model | |
| Head width | Chapter model | |
| Total heads | ||
| Head update rank | At most | Low-rank OV write |
| Untouched directions | Nullity at least for the fixed linear OV map | Not untouched coordinate axes or whole-head invariance |
| Write-demand factor | Sum-of-maximal-ranks heuristic, not a measured capacity overload | |
| Total write demand | summed rank units | Repeated writes need not be independent features |
| Random-vector root mean square inner product | Geometry at | |
| Unrelated write captured by one read subspace | ||
| Writes through layer | ||
| Approximate stream norm | ||
| One unit write share | ||
| Context example | tokens | positions |
| Context stream at one layer | Half-precision residual states | |
| Answer-position stream | half-precision values | |
| Retrieval funnel | Context positions to answer position | |
| increase example | to | Tenfold tighter context-to-answer funnel |
| Smaller context stream | Five chunks rather than | |
| Large-window warning | tokens versus an answer state | Context capacity does not widen the output funnel |
| Early intervention range | Layers through | One write is a larger share before the stream accumulates many edits |
| One-head parameters | Four projections | |
| Gauge directions | Two copies of | |
| Gauge fraction | Function-preserving coordinate freedom | |
| Vocabulary size | Chapter model | |
| Expanded OV entries | One head | |
| Expanded OV storage | One head in half precision | |
| Expanded OV decimal storage | Same one-head map in decimal units | |
| Expanded OV storage for all heads | heads | |
| Reduced OV eigenproblem | Same nonzero spectrum | |
| Reduced storage | per head | numbers |
| Reduced storage for all heads | heads | |
| Spectrum reduction | Expanded entries divided by reduced entries | |
| GPT-2 spectral sanity check | vocabulary, versus entries, reduction | Low-rank reduction transfers across model shape |
| All-head eigendecomposition | , about before constants | Omits forming the reduced products and eigensolver workspace |
| Random mean | only under a sign-symmetric ensemble | Not a universal model-initialization guarantee |
| Kappa noise floor | Independent-angle heuristic, not a calibrated deployed null | |
| Copying-score screen | as a heuristic flag | Not a multiple-comparison-corrected significance test |
| Probe monitoring example | area under the curve (AUC) | Decodability without proof of use |
| Saliency triage | First candidates when is in the hundreds | Rank candidates before causal ablation |
| Random-repeat sequence | tokens repeated | -token context |
| Uniform loss | or | Vocabulary size |
| Published in-context learning score | Loss at token minus loss at token | Olsson et al. probe anchor |
| Example copy-2 loss | Approximately relative log-loss reduction; not copying accuracy | |
| One probe prefill | tokens | |
| Thirty-two probes | All-head prefix scan | |
| Causal head scan | runs | One baseline plus ablations |
| Causal head scan time | min | repeat sequences under each of intervention conditions |
| Parts table | rows | Chunking example |
| Row length | tokens | Atomic record size |
| Table length | tokens | |
| No-overlap chunks | -token windows | |
| Internal boundaries | No-overlap chunking | |
| Clean boundaries | of boundaries aligned in this deterministic setup | Alignment occurs at every ninth boundary |
| Split rows | rows, or | Exact fixed-row/offset count, not the erroneous random-offset estimate |
| Overlap | tokens | Exceeds row length |
| Overlap stride | minus | |
| Overlap chunks | Worked count | |
| Index-cost factor | Chunk-count factor; embedding-token factor is | |
| Record-aware split threshold | About one tenth of a chunk | Point where overlap becomes the expensive guarantee |
| Correct head contribution | Example push toward | |
| Competing contribution | Example push toward | |
| Wrong-answer margin | Difference between contributions | |
| Per-answer head patching | replays | Baseline plus each head |
| Per-answer head patch time | Approximately compute-equivalent minutes | |
| Head versus document ratio | ||
| Daily answers | Audit example | |
| Audit slice | answers | |
| Document-ablation audit | Approximately GPU-equivalent hours/day | |
| Document audit capacity | Fraction of one continuous accelerator | |
| Head-patching audit | Approximately GPU-equivalent hours/day | |
| Head-patching capacity | accelerators | Continuous capacity |
| Citation observation | More than | Both supported and unsupported sentences in the cited result |
00-START-HERE · 01-READING-ROUTES · 07_in_context_learning_the_mechanism_rag_rides_on · 09_prompting_for_retrieval_augmented_systems