Lesson 4 of 6

Switching parts off and steering

Change a real model while it runs. Switch attention heads off, copy activations from one prompt into another to see where a fact travels, and add a direction that changes what the model writes.

Advanced30 min

Builds on Reading a model layer by layer, How circuits form: induction heads, and Superposition: more features than neurons

In this lesson you will

  • Use ablation to test whether an answer depends on a particular attention head
  • Use activation patching to find where the information behind an answer sits and when it moves
  • Build a steering vector from two sets of prompts and use it to change what a model writes
  • Explain what each kind of intervention shows and what it does not

Reading a model layer by layer showed what is inside SmolLM2-135M at each depth. Reading cannot tell you what the model uses. For that you need an experiment: change one part while the model runs and see whether the output changes. This lesson runs three kinds of experiment on the same model: switching attention heads off, copying activations from one prompt into another, and pushing the activations in a chosen direction.

Layers and heads are numbered from 1, as in the lab. “After layer 24” means the residual stream once 24 layers have run; “after layer 0” is the embedding.

Switching heads off

AblationSwitching off part of a model, for example setting an attention head's output to zero, to see which behaviors depend on it.Taught in How circuits form: induction headsOpen in glossary removes a part and runs the model again. For an attention head, the simplest version replaces its output with zeros. A gentler version replaces it with the head’s average output over the prompt’s positions, so later layers still receive a typical value, just one that says nothing about the particular token.

On The Eiffel Tower is located in the city of, the model gives " Paris" a probability of 88%. Switching off each of the 270 heads in turn, with zeros:

  • 237 of the 270 heads change that probability by less than 5 percentage points.
  • Layer 2, head 1 has by far the largest effect: without it, " Paris" falls to 16%. With its average instead of zero, it falls to 47%.
  • The next largest drops are layer 1, head 5 (to 59%) and layer 24, head 5 (to 61%).
  • Some heads work against the answer. Without layer 2, head 6, " Paris" rises to 94%.

Model microscope

Type a prompt and look inside a real language model: what it would say at every layer, where each attention head looks, and what happens when you switch parts off.

Recorded from SmolLM2-135M

Loading the model's recorded outputs for four prompts: every layer and head, tracking the tokens near the top at the last position, every single head switched off, and patching at every layer.

About the download

See inside a real language model: its prediction at every layer, all 270 attention heads, and what happens when you switch parts off. This uses SmolLM2-135M, a 135-million-parameter base language model from Hugging Face (2024), run from its original weights by this site's own engine.

The first time, your browser downloads about 272 MB of model files from Hugging Face. They are cached for later visits. Everything runs on your device; nothing you type is sent anywhere.

Manage downloads

Loading the recorded results

Challenges

0 of 3 complete

  1. With the model's answer tracked, select the first layer where it becomes the top guess at the last token. (not yet)
  2. Switch off one single head that cuts the tracked answer's probability by at least a third. (not yet)
  3. Patch one layer from the second prompt so the model's top answer changes. (not yet)

Try this

  • The lab opens on The Colosseum is located in the city of, where the model gives " Rome" 72%. In Switch heads off, select layer 2, head 1 and run. " Rome" drops to 10%. Replace the head’s output with its average instead, and " Rome" is still only 13%: this head matters on more than one prompt.
  • Under Patch from another prompt, the second prompt is the Eiffel Tower one, and both have 10 tokens. Choose Where the prompts differ (the subject’s tokens) and press Sweep every layer. The chart tracks " Rome": near zero for every layer up to 23, then back above 70% from layer 24.
  • Set the layer to 10 and press Patch this layer to see what replaced " Rome" in the top list.
  • Switch to The last token and sweep again. The curve does the opposite: " Rome" holds until layer 23 and collapses from layer 24.

Copying activations between prompts

Activation patchingRunning a model on one prompt while copying in an internal activation from a run on another prompt, to test whether that activation carries the information that changes the output.Open in glossary runs the model on two prompts that differ in one detail, here the landmark, then runs one prompt again while copying in part of the other’s residual stream. If copying a piece makes the answer change, that piece carried the information the answer depends on.

Both prompts are 10 tokens long. The subject is split into three tokens in each: " E", "iffel", " Tower" and " Col", "osse", "um". These are the measured probabilities after copying from the Eiffel Tower run into the Colosseum run:

What is copiedAfter layers 0 to 23After layers 24 to 30
The three subject tokens" Paris" 87% to 97%" Paris" below 0.1%, " Rome" 72% to 77%
The last token, " of"" Paris" below 0.1%" Paris" 84% to 89%
Only the subject’s last token" Paris" below 0.1%" Paris" below 0.1%

Read the first two rows together. Up to layer 23, everything that makes the answer Paris instead of Rome sits at the subject’s positions: swap them and the answer follows, swap the last position and nothing happens. After layer 24, it is the other way around. Attention is the only part of a transformer that moves information from one position to another, so the move happens in layer 24’s attention heads. Two earlier measurements fit: layer 24, head 5 was among the largest single-head drops above, and in the first lesson it gave the second largest direct push toward " Paris" of all 270 heads. Neither proves that this head does the moving, but together they make it the first place to look.

This style of experiment is often called Causal tracingFinding where a model stores and moves information by restoring or swapping activations layer by layer and position by position and measuring the effect on the output.Open in glossary, after Meng, Bau, Andonian, and Belinkov (2022). They corrupted the subject in GPT models with noise and restored one activation at a time, and found that MLP layers in the middle of the network, at the subject’s last token, were decisive, with attention carrying the result to the last position later. The second half of that picture matches what you see here. The third row does not: in this small model and this pair of prompts, the subject’s last token alone was not enough at any layer. All three subject tokens had to be copied together. The setups also differ: in causal tracing the other subject tokens carry noise, while here they still spell out the Colosseum.

Steering with a direction

In the superposition lesson, forcing one sparse autoencoder feature on made a large model bring up the Golden Gate Bridge. A Steering vectorA direction added to a model's residual stream while it runs, usually the difference between its average activations on two contrasting sets of prompts, used to push its output one way.Open in glossary gets a direction more cheaply, without training anything:

  1. Run the model on a few sentences of one kind (“I love this. It is wonderful.”) and a few of the opposite kind (“I hate this. It is terrible.”).
  2. Average each set’s residual stream after one layer, and subtract one average from the other.
  3. While the model writes, add a multiple of that difference to the stream after the same layer, at every position.

Turner and colleagues (2023) introduced this as activation addition, with “Love” versus “Hate” as an example prompt pair. They used a single pair of prompts and added the difference at the first few positions of the prompt. The lab instead averages three sentences per side, skips the first position, whose stream reflects only the first word, and adds the result at every position.

Measured with the default settings (after layer 4, three sentences per side), continuing I think my neighbor is and always picking the most likely token (↵ marks a new line):

StrengthWhat the model writes next
0a good one.↵↵I’m not sure if I’m going to be
+2a great example of a person who is a good example of a person who is
-2a liar. I don’t know what he’s saying, but I don
+8to our our place to our a year of a↵↵↵a↵a

Steering a model

Build a direction in the model's residual stream from two sets of prompts, add it while the model writes, and see what changes.

Recorded from SmolLM2-135M

Loading the model's recorded outputs for the default sets and start of the text, at every layer and strength.

About the download

Steer a real language model by adding a direction to its residual stream while it writes. This uses SmolLM2-135M, a 135-million-parameter base language model from Hugging Face (2024), run from its original weights by this site's own engine.

The first time, your browser downloads about 272 MB of model files from Hugging Face. They are cached for later visits. Everything runs on your device; nothing you type is sent anywhere.

Manage downloads

Loading the recorded results

Challenges

0 of 3 complete

  1. Find a layer and strength where steering changes what the model writes. (not yet)
  2. Change the text with a positive strength, then with a negative one. (not yet)
  3. Try steering at an early layer (below 6) and at a late one (above 20). (not yet)

Try this

  • Press Generate with the defaults (after layer 4, strength +2), then set the strength to -2 and generate again.
  • Raise the strength to +8. The text falls apart: a large addition pushes the stream far from anything the later layers were trained on.
  • Move the layer to 20 and try +2 and -2. On this prompt, +2 still reads warmer (“a great person.↵↵I love her so much!”), but -2 breaks the text instead of turning it hostile.
  • Write your own two sets, for example sentences about the ocean against sentences about the desert, and see whether the continuation drifts toward the topic.
A steering vector in a few linesPython with NumPy
import numpy as np

# Residual streams (length 4) for prompts on each side, averaged per side.
happy = np.array([[0.9, 0.1, 0.3, 0.2],
                  [0.8, 0.0, 0.4, 0.1]])
angry = np.array([[0.1, 0.9, 0.3, 0.2],
                  [0.0, 0.8, 0.5, 0.1]])
vector = happy.mean(axis=0) - angry.mean(axis=0)
print("steering vector:", np.round(vector, 2))

# Add it, scaled, to a new prompt's residual stream and read the output.
W_U = np.array([[1.0, -1.0, 0.0, 0.0],   # " kind"
                [-1.0, 1.0, 0.0, 0.0]])  # " rude"
h = np.array([0.4, 0.5, 0.3, 0.2])
for strength in (0, 1, -1):
    logits = W_U @ (h + strength * vector)
    p = np.exp(logits - logits.max())
    p /= p.sum()
    print(f"strength {strength:+d}: P(kind) = {p[0]:.2f}")
steering vector: [ 0.8  -0.8  -0.05  0.  ]
strength +0: P(kind) = 0.45
strength +1: P(kind) = 0.95
strength -1: P(kind) = 0.03

A difference of averages over three sentences per side is a blunt tool. It captures everything that differs between the two sets, not only the feeling, and in this 135-million-parameter model the range of strengths where the text changes but still reads as language is narrow. Later methods, such as contrastive activation addition (Panickssery and colleagues, 2024), average over hundreds or thousands of prompt pairs.

What these experiments can and cannot show

  • Ablation shows that an output depends on a part, for one prompt. It does not show what the part computes. Zeros are also an unnatural input, which is why the average is often the fairer replacement.
  • Backups hide parts. Models often spread a job across several heads, so switching one off can leave the output unchanged even when the job matters. You saw this in How circuits form, where switching off one of several induction heads made copying only somewhat worse, because the others covered for it.
  • Patching locates where the difference between two prompts sits and when it moves. It does not explain how the fact was retrieved.
  • Steering shows that adding a direction changes behavior. It does not show that the model represents the concept you had in mind as that exact direction.

Each of these is stronger evidence than reading activations alone, because each changes the computation and measures the consequence. None of them, on a few prompts, explains a model.

Key ideas

  • Interventions test what a model uses: change one part while it runs and measure what happens to the output.
  • Ablation switches a part off. Most of SmolLM2-135M’s heads barely matter for one factual prompt; one early head matters a great deal.
  • Activation patching copies part of one run into another. For the Eiffel Tower and Colosseum prompts, the information behind the answer sits on the subject’s tokens until layer 24 moves it to the last position.
  • A steering vector is a difference between average activations on two sets of prompts. Added with a small strength it shifts what the model writes; with a large one it breaks the text.
  • Each result holds for the prompts tested. General claims need many prompts, and careful choices of what to replace activations with.

Check yourself

Pick an answer to see why it is right or wrong. Nothing is graded. Your first answer is saved in this browser so the question can come back for review.

1You copy activations from the Eiffel Tower run into the Colosseum run. Copying the subject's tokens works up to the stream after layer 23 and stops working after layer 24. Copying the last token works only from after layer 24 on. What is the most likely reading?
2Switching off one head in layer 2 drops the probability of " Paris" from 88% to 16%. Does that head store the fact that the Eiffel Tower is in Paris?
3Adding the steering vector with strength 2 makes the model's continuation warmer, but strength 8 produces broken text. Why?

Progress is saved in this browser only.

Up nextAlignment: getting the goal right
Next
Inside the model
  1. 1Reading a model layer by layer
  2. 2How circuits form: induction heads
  3. 3Superposition: more features than neurons
  4. 4Switching parts off and steering
  5. 5Alignment: getting the goal right
  6. 6How alignment is attempted

Try "embedding", "softmax", "overfitting", or "backpropagation".