Phase C · mechanistic interpretability

Logit / tuned lens

nostalgebraist 2020; Belrose et al. 2023

← back to the method catalogue

What it does?

The logit lens reads a system's intermediate state through its own output decoder. In a transformer it takes the hidden state at some middle layer and applies the final output projection to it, as if that intermediate state were the last layer, to see what the model would 'say' at that point. This reveals how the prediction forms across depth, and the tuned-lens variant learns a small correction so the readout is more faithful at each stage. It is a standard, cheap tool for tracing how information develops inside a network. We build the analogue on the VCS by reading an intermediate value through the machine's own decoding, and comparing the decoded value to the true intermediate value at that site. On this transparent machine the readout is exact: the state is linearly readable at the right site, so the lens reproduces the true intermediate value on every game. This is expected, because the VCS keeps its variables in plain, addressable memory rather than in a distorted distributed code. Readability, however, is only the positive control. The scored question is where the lens's readout weight sits: on the cells the oracle marks as truly causal, or on clocks and counters that merely co-vary with the value. Reading the right value at the right site confirms that the value is represented and readable, but it does not by itself explain how that value is computed or what role it plays.

Logit / tuned lens result

Left: the frame. Right: the recovered structure/effect against the ground truth (matched components or preserved behaviour), with the RAM cells labelled. logit_lens_faithful_weight_fraction_vs_causal_mask = 0.438 — this example only (pong, state gameplay(seed=0,prefix=90)+15); the audit aggregate is below.

Mechanistic family · reading intermediate states

Learn the method — a beginner's guide

New to explainable AI? This block explains the method as it is used on neural networks, then how we run the very same method on an Atari 2600, where — unlike for a network — we know the right answer. Every implementation step links to the code. See also the XAI primer for the shared vocabulary.

The idea in plain words

A transformer language model is a stack of layers. Each layer reads a shared vector, the residual stream, and adds its contribution back to it. Only at the very end does an unembedding matrix turn that vector into one score per word in the vocabulary. Those scores are the logits; a softmax turns them into probabilities for the next word.

The logit lens asks a cheeky question: what if we applied that final unembedding to the residual stream halfway up the stack, as if the model stopped there? Because every layer writes into the same stream, this often gives sensible words. You can watch the prediction form layer by layer: vague at first, then sharpening into the final answer. The tuned lens improves on it. It learns a small linear correction for each layer, so that earlier layers, whose “language” drifts a little from the last layer's, are translated before decoding. Both are cheap, popular ways to trace how information develops through depth.

How it works on a neural network

Let \(h_\ell\) be the residual stream after layer \(\ell\), \(W_U\) the unembedding and \(\mathrm{LN}\) the final layer normalisation. Then

\[ \text{logits}_L = W_U\,\mathrm{LN}(h_L), \qquad \text{logit lens: } W_U\,\mathrm{LN}(h_\ell), \qquad \text{tuned lens: } W_U\,\mathrm{LN}(A_\ell h_\ell + b_\ell). \]

The tuned-lens translator \((A_\ell, b_\ell)\) is trained so its output distribution matches the model's final one (by minimising a KL divergence). No new information is created: the lens only reads what is already linearly there.

Toy example. A vocabulary of two words, “Paris” and “Rome”, and \(W_U = I\) (identity). The residual stream after layers 1, 2 and 3 is \((0.2, 0.1)\), \((1.5, 0.3)\) and \((3.0, 0.2)\). The softmax probability of “Paris” is \(1/(1+e^{-(z_1-z_2)})\): 0.52 after layer 1, 0.77 after layer 2, 0.94 after layer 3. The logit lens shows the answer “Paris” forming gradually. If layer 1 stored the answer in a rotated basis, the raw lens would read nonsense there, and a learned \(A_1\) would undo the rotation: that is the tuned lens.

Recipe

  1. Run the model and save the residual stream \(h_\ell\) at every layer.
  2. Logit lens: apply the final norm and unembedding to each \(h_\ell\) and read the decoded prediction.
  3. Tuned lens: for each layer, fit an affine map \(A_\ell h_\ell + b_\ell\) on training data so the decoded output matches the final output.
  4. Evaluate on held-out data: how well does each layer's readout match the final answer, and from which layer on?
  5. Check what the readout relies on: are its weights on components that actually drive the output?

From a neural network to the Atari

Layers \(\ell\)The frames of the 15-frame horizon after \(f^*\): step 0 (the checkpoint) to step 15.
Residual stream \(h_\ell\)The full 128-byte RAM at that step. RAM is the one state every frame reads and writes, like the residual stream.
Final logitThe value of a target variable's RAM cell at the end of the horizon (one per candidate cell; 8 for Pong).
Unembedding \(W_U\) (logit lens)The identity readout: read the target's own cell at step \(t\). There is no learned matrix on the VCS.
Tuned-lens translator \(A_\ell, b_\ell\)A ridge-regression readout from all 128 bytes at step \(t\) to the final value.
True intermediate value (unknown in an LLM)The actual byte at that step on the bit-exact run, plus the oracle's mask of which cells causally drive each final value.

How we apply it to the VCS

Our runner logit_lens.jl builds both lenses on the VCS and scores them against values we can measure directly.

Where we differ from the original. A transformer has one shared unembedding; on the VCS each variable lives in its own address, so the “unembedding” is just “look at that address”. Our layers are time steps, not stacked modules. And the training runs are mostly deliberate pokes, not a natural data distribution. Readout fidelity reaching the ceiling is therefore expected: the machine keeps its variables in plain, addressable memory. The more informative numbers are the tuned-lens curves and the faithful-weight share, which is the record's scored faithfulness.

Read the code

XAI the interpretability method   substrate the bit-exact emulator it runs on (jutari, Julia).

Reading the result

The figure plots readout fidelity against the true intermediate value, step by step, and it sits at the ceiling on every game. Read that as a sanity check: the variable is stored at the site we read, in plain form. The richer story is in the per-step curves. The logit lens reaches the final value only once the cell stops changing. The tuned lens can sometimes predict it earlier by combining other bytes. Then check the faithful-weight share: an early prediction built on causal cells is the mechanism showing through; one built on non-causal cells is a correlation, the same present-versus-used trap as in probing.

Pitfalls

Try it yourself

julia --project=jutari tools/xai_study/phaseC_mechanistic/logit_lens.jl --games core

Writes logit_lens_<game>.{json,npz} and logit_lens_core_summary.json into tools/xai_study/phaseC_mechanistic/out/. --n-traj K changes the number of runs the lenses are fit on (default 48).

Original papers & further reading

Read next: Linear probing + control tasks · Activation patching / causal mediation · Interchange interventions / DAS · A8 · Whole-state recording

How it's scored

The scored faithfulness is the faithful-weight fraction. For each game variable we fit a tuned lens (a per-step linear readout) and find the earliest step at which it decodes the variable's final value. At that step we measure what share of the lens's readout weight sits on cells the intervention oracle marks as truly causal for that variable, rather than on correlated clocks and counters. A high share means the lens reads the mechanism; a low share means it rides a correlate. Readout fidelity, the R-squared of the lens-decoded value against the true intermediate value, is kept as a positive control and is the quantity the example figure plots: on this transparent machine the state is linearly readable at the right site, so fidelity sits at the ceiling. The point of the faithful-weight score is that readability alone does not show use. A readout can decode a value early by combining cells that merely co-vary with it. There is no sprite-position hard-case here, because the method reads an internal value rather than a rendered position, and it does not rely on a gradient. The grading is always against the oracle; the audit box reports the measured triad.

The score is measured against the §1 intervention oracle — never against another interpretability method. F (faithful) is always vs the oracle; see the execution stack. How each of F / S / M is actually computed for this method (and whether it matches the paper) is in the box just below; the numbers are in the In the audit box under it.

How F, S, M are computed here

The exact formula this method uses for each score, read from its runner, and whether it matches the paper's §3 (F ∧ S ∧ M triad) definition. From the committed audit fsm_math_phaseC.json.

AxisFormula (as computed) What it measuresMatches §3?
F
faithfulness
\(F = \dfrac{\sum_t |A_t|\cdot \mathbb{1}[\text{site causal}]}{\sum_t |A_t|}\)Mean fraction of the tuned-lens readout weight that lands on truly-causal sites (the oracle causal mask): low => the lens reads a spurious correlate (present != used).✓ matches logit_lens.jl now emits top-level metric_name=logit_lens_faithful_weight_fraction_vs_causal_mask with extra.triad.F = mean faithful-weight fraction vs the oracle causal mask; it replaced the readout-fidelity-to-the-true-intermediate (=1.0 by construction). This is §3's causal-agreement F for a readout-direction method. Record: logit_lens_pong.json extra.triad.F=0.438.
how it's measured — call stack:
  1. mean_faithful_weight_frac: share of lens readout weight on causal sites — logit_lens.jl:573
  2. emit F = faithful-weight fraction vs the oracle causal mask — logit_lens.jl:702
  3. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242
S
sufficiency
S = null (undefined)Not scored: the lens reports readout fidelity to the true intermediate, not a held-out do(u) output prediction.— n/a logit_lens.jl (S = nothing). n/a is defensible per paper. Record: extra.triad.S = null.
M
minimality
\(M = |U^{\star}| / |\hat{U}| \in (0,1]\quad U^{\star}=\{u:\Delta y(u)>0\},\ \hat{U}=\{u:|\mathrm{attr}(u)|>\tau\}\)Oracle-causal sites over the number of readout sites the lens names above threshold.✓ matches logit_lens.jl now emits M = |U*|/|U_hat| in extra.triad.M (M_note '|U*|=4 (oracle movers) / |U_hat|=74 (method above-threshold)'), the paper's set-size ratio. Record: logit_lens_pong.json extra.triad.M=0.054. Replaced the former faithful-weight-fraction proxy (now used as F).
how it's measured — call stack:
  1. minimality_score(lens readout weights, oracle Δy) — logit_lens.jl:700
  2. minimality_score: |U*| oracle movers / |U_hat| lens-named sites — triad_sm.jl:57
  3. true causal effect Δy(u) by bit-exact re-run — oracle_intervene.jl:242

✓ matches = the same quantity as §3; ◐ partial = the same kind of estimator but a differing detail; ✗ does not match = a different quantity (see the note). Definitions: F = agreement with the oracle's true causal effects Δy(u); S = held-out predictive score in [−1, 1]; M = |U*|/|Û| (true-minimal-set size / named-set size).

In the audit

This is the method's entry in the actual cross-method audit — scored on the paper's correctness triad, each axis a mean over 44 of the 44 scored games (44 committed §R records), not the single example shown above. Tradition: causal. The example figure (Pong) is one of those records.

0.793F — faithfulness vs oracle (mean over 44 games, ±0.059 CI95)
n/aS — sufficiency: held-out predictive (n/a where the paper does not define this axis)
0.192M — minimality: true-minimal-set / named-set (n/a otherwise)
44committed records aggregated
0.00human-plausibility proxy

F faithfulness (scored vs the oracle for every method) · S sufficiency (held-out predictive score in [−1, 1]; a negative value means the explanation predicts held-out interventions worse than the unperturbed baseline; reported for the predictive methods across all three phases where the calibration/held-out split is defined) · M minimality (true-minimal-set / named-set; where the method names a cause set) — n/a otherwise, per the paper's F ∧ S ∧ M triad.

Source: leaderboard.json · the whole leaderboard is on the methods page and the Paper 2 audit.

Results per game

This method's faithfulness on each of the 44 scored games (all-regime F; this method has no content-vs-position split (see the note below)). Click a header to sort. Every number is read from site_data.json (methods.logit_lens.per_game).

content-F and position-F are n/a for this method. The content-vs-position split applies only to pixel-attribution methods — those that produce an attribution map over the framebuffer, whose score can be read separately on the smooth content outputs and the discrete position outputs (where the naive gradient is provably zero). This method does not attribute to a pixel output; it is graded by its own fidelity metric (logit_lens_faithful_weight_fraction_vs_causal_mask), reported as the F column, so there is no content or position regime to separate.

GameF (all)content-Fposition-FSMNote
Gopher1.000n/an/an/a1.000recovers the true causes
Kung-Fu Master1.000n/an/an/a1.000recovers the true causes
Pacman1.000n/an/an/a0.875recovers the true causes
Bowling0.995n/an/an/a0.298recovers the true causes
Bank Heist0.991n/an/an/a0.069recovers the true causes
Phoenix0.984n/an/an/a0.116recovers the true causes
Carnival0.975n/an/an/a0.168recovers the true causes
Q*bert0.972n/an/an/a0.271recovers the true causes
Freeway0.969n/an/an/a0.122recovers the true causes
Kangaroo0.950n/an/an/a0.144recovers the true causes
Name This Game0.947n/an/an/a0.085recovers the true causes
Centipede0.928n/an/an/a0.074recovers the true causes
Road Runner0.908n/an/an/a0.165recovers the true causes
Ice Hockey0.891n/an/an/a0.096recovers the true causes
Air Raid0.890n/an/an/a0.106recovers the true causes
Private Eye0.877n/an/an/a0.275recovers the true causes
Krull0.875n/an/an/a0.247recovers the true causes
Venture0.862n/an/an/a0.182recovers the true causes
Tennis0.860n/an/an/a0.169recovers the true causes
Space Invaders0.847n/an/an/a0.121
Montezuma's Revenge0.842n/an/an/a0.119
Riverraid0.842n/an/an/a0.183
Double Dunk0.827n/an/an/a0.114
Yars' Revenge0.824n/an/an/a0.147
Alien0.820n/an/an/a0.061
Breakout0.815n/an/an/a0.067
Skiing0.814n/an/an/a0.061
Seaquest0.812n/an/an/a0.310
Hero0.805n/an/an/a0.140
Video Pinball0.803n/an/an/a0.080
Demon Attack0.791n/an/an/a0.151
Jamesbond0.764n/an/an/a0.105
Asterix0.749n/an/an/a0.111
Atlantis0.748n/an/an/a0.096
Ms. Pac-Man0.734n/an/an/a0.168
Berzerk0.662n/an/an/a0.209
Fishing Derby0.624n/an/an/a0.050
Frostbite0.568n/an/an/a0.137
Chopper Command0.553n/an/an/a0.111
Assault0.530n/an/an/a0.163
Pitfall0.458n/an/an/a0.104
Pong0.438n/an/an/a0.054
Boxing0.291n/an/an/a0.081
Enduro0.064n/an/an/a0.018

Call stack — how it runs on jutari / jaxtari

The path from this method's runner (run_game) into the bit-exact VCS substrate, and the computation it involves. Every step links to the exact source on main. From callstack_phaseC.json.

Applied on the substrate

  1. Boot the real ROM with the xitari-parity reset (60 NOOP + 4 RESET) — env_reset!(env; boot_noop_steps = 60, boot_reset_steps = 4) jutari
  2. Deterministically step the emulator one action per env-frame (drives the RAM-tape / trajectory-set recording) — env_step!(env::StellaEnvironment, action::Integer) jutari
  3. Assemble the shared gameplay-state testbed (checkpoint at f*, causes, shared screen output, cause-density gate) — build_shared_testbed(game; ... intervene_ram = intervene_ram!, run_intervention = run_intervention, soft_ram_peek = soft_ram_peek, ...) runner
  4. Freeze byte-exact RAM + screen out of the env at a frame — snapshot(env::StellaEnvironment, frame::Integer) jutari

The computation

  1. Build the per-site trajectory set (poke each candidate cell across offsets, record the RAM tape) the readouts are fit on — build_trajset(base_ckpt, src_ckpt, ...) -> intervene_ram! runner intervene_ram! @ logit_lens.jl:277; record_ram_tape @ :213
  2. Per-site readout fidelity: ridge-fit a linear readout from each site to the output and score R^2 — ridge_fit(X, y; lambda) ; r2(y, yhat) runner r2 @ :300
  3. Faithful-weight fraction vs the oracle causal mask: build the causal mask by poking each site (+SET_DELTA), re-run, and compare which readout weights land on truly-causal cells — build_causal_mask(base_ckpt, tail, ...) -> intervene_ram! runner intervene_ram! @ logit_lens.jl:379

Scored against the exact intervention oracle Δy(u): run_intervention(checkpoint, actions, target_frame, horizon, cause).

Implementation
tools/xai_study/phaseC_mechanistic/logit_lens.jl
Reference
nostalgebraist 2020; Belrose et al. 2023
Record
logit_lens_pong.json
All records
phaseC_mechanistic/out

The figure is generated from the committed record by docs/gen_method_figures.py; the game frame and each RAM cell's screen footprint are produced by render_scenes.jl / cell_footprints.jl.