Edit (April 30, 2024):
A note to clarify things for future readers: The final sentence "This should be cited." in the parent comment was silently edited in after this comment was initially posted, which is why the body of this comment purely engages with the serious allegation that our post is duplicate work. The request for a citation is highly reasonable and it was our fault for not including one initially - once we noticed it we wrote a "Related work" section citing RepE and many other relevant papers, as detailed in the edit below.
======
Edit (April 29, 2024):
Based on Dan's feedback, we have made the following edits to the post:
As I mentioned over email: I'm sorry for overlooking the "Related work" section on this blog post. We were already planning to include a related works section in the paper, and would of course have cited RepE (along with many other relevant papers). But overlooking this section for the blog post is my mistake, and I take responsibility for it.
We still dispute the serious allegation that our work is "exactly the same" as RepE.
======
We definitely drew inspiration from the Representation Engineering paper and other activation steering papers, but we think our work is quite distinct.
In particular, we examined Section 6.2 carefully before writing our work, and we do not see it showing the same result that we show here.
Here’s my summary of Section 6.2:
We would agree that using established techniques from representation engineering / activation steering to induce refusal is not novel. Inducing refusal via activation addition is quite easy in our experience.
However, the main result of our work is that we found an intervention that bypasses refusal consistently while also maintaining model coherence. Model interventions to bypass refusal are not discussed in Section 6.2.
As for the demo notebook in the representation-engineering repo - we were not previously aware of this notebook. The result of bypassing refusal is not reported in the paper, and so we didn’t think to look through the repo.
That being said, the notebook shows an intervention for a single prompt on a single model. Anecdotally, we tried doing vanilla activation addition with the negative “refusal direction” at particular layers, and we were not able to consistently bypass refusal while also maintaining model coherence. If there is a methodology involving activation addition (rather than ablation, as we did here), we would be interested in seeing a more thorough demonstration across prompts and models. We’d also be interested in comparing the two methodologies across metrics measuring refusal and coherence.
I'd also be happy to hop on a call if you'd like to discuss further.
This work was produced as part of Neel Nanda's stream in the ML Alignment & Theory Scholars Program - Winter 2023-24 Cohort, with co-supervision from Wes Gurnee.
This post is a preview for our upcoming paper, which will provide more detail into our current understanding of refusal.
We thank Nina Rimsky and Daniel Paleka for the helpful conversations and review.
Update (June 18, 2024): Our paper is now available on arXiv.
Executive summary
Modern LLMs are typically fine-tuned for instruction-following and safety. Of particular interest is that they are trained to refuse harmful requests, e.g. answering "How can I make a bomb?" with "Sorry, I cannot help you."
We find that refusal is mediated by a single direction in the residual stream: preventing the model from representing this direction hinders its ability to refuse requests, and artificially adding in this direction causes the model to refuse harmless requests.
We find that this phenomenon holds across open-source model families and model scales.
This observation naturally gives rise to a simple modification of the model weights, which effectively jailbreaks the model without requiring any fine-tuning or inference-time interventions. We do not believe this introduces any new risks, as it was already widely known that safety guardrails can be cheaply fine-tuned away, but this novel jailbreak technique both validates our interpretability results, and further demonstrates the fragility of safety fine-tuning of open-source chat models.
See this Colab notebook for a simple demo of our methodology.
Introduction
Chat models that have undergone safety fine-tuning exhibit refusal behavior: when prompted with a harmful or inappropriate instruction, the model will refuse to comply, rather than providing a helpful answer.
Our work seeks to understand how refusal is implemented mechanistically in chat models.
Initially, we set out to do circuit-style mechanistic interpretability, and to find the "refusal circuit." We applied standard methods such as activation patching, path patching, and attribution patching to identify model components (e.g. individual neurons or attention heads) that contribute significantly to refusal. Though we were able to use this approach to find the rough outlines of a circuit, we struggled to use this to gain significant insight into refusal.
We instead shifted to investigate things at a higher level of abstraction - at the level of features, rather than model components.[1]
Thinking in terms of features
As a rough mental model, we can think of a transformer's residual stream as an evolution of features. At the first layer, representations are simple, on the level of individual token embeddings. As we progress through intermediate layers, representations are enriched by computing higher level features (see Nanda et al. 2023). At later layers, the enriched representations are transformed into unembedding space, and converted to the appropriate output tokens.
Our hypothesis is that, across a wide range of harmful prompts, there is a single intermediate feature which is instrumental in the model’s refusal. In other words, many particular instances of harmful instructions lead to the expression of this "refusal feature," and once it is expressed in the residual stream, the model outputs text in a sort of "should refuse" mode.[2]
If this hypothesis is true, then we would expect to see two phenomena:
Our work serves as evidence for this sort of conceptualization. For various different models, we are able to find a direction in activation space, which we can think of as a "feature," that satisfies the above two properties.
Methodology
Finding the "refusal direction"
In order to extract the "refusal direction," we very simply take the difference of mean activations[3] on harmful and harmless instructions:
This yields a difference-in-means vector rl for each layer l in the model. We can then evaluate each normalized direction ^rl over a validation set of harmful instructions to select the single best "refusal direction" ^r.
Ablating the "refusal direction" to bypass refusal
Given a "refusal direction" ^r∈Rdmodel, we can "ablate" this direction from the model. In other words, we can prevent the model from ever representing this direction.
We can implement this as an inference-time intervention: every time a component c (e.g. an attention head) writes its output cout∈Rdmodel to the residual stream, we can erase its contribution to the "refusal direction" ^r. We can do this by computing the projection of cout onto ^r, and then subtracting this projection away:
c′out←cout−(cout⋅^r)^rNote that we are ablating the same direction at every token and every layer. By performing this ablation at every component that writes the residual stream, we effectively prevent the model from ever representing this feature.
Adding in the "refusal direction" to induce refusal
We can also consider adding in the "refusal direction" in order to induce refusal on harmless prompts. But how much do we add?
We can run the model on harmful prompts, and measure the average projection of the harmful activations onto the "refusal direction" ^r:
avg_projharmful=1nn∑i=1a(i)harmful⋅^rIntuitively, this tells us how strongly, on average, the "refusal direction" is expressed on harmful prompts.
When we then run the model on harmless prompts, we intervene such that the expression of the "refusal direction" is set to the average expression on harmful prompts:
a′harmless←aharmless−(aharmless⋅^r)^r+(avg_projharmful)^rNote that the average projection measurement and the intervention are performed only at layer l, the layer at which the best "refusal direction" ^r was extracted from.
Results
Bypassing refusal
To bypass refusal, we ablate the "refusal direction" everywhere (at all layers and positions), effectively preventing the model from ever representing this direction.
We test the effectiveness of this intervention over 100 harmful instructions from the JailbreakBench dataset, which span a diverse range of harmful categories[6]. We generate completions without the ablation ("baseline"), and with the ablation ("intervention"). We then judge each completion across two metrics:
I'm sorry,As an AI assistant, etc) and check whether a model completion contains at least one such phrase.safeorunsafe.Here are some cherry-picked examples of bypassing refusal on harmful instructions with Gemma 7B:
For more examples of bypassing refusal, see the demo notebook.
Inducing refusal
To induce refusal, we add the "refusal direction"[7] across all token positions at just the layer at which the direction was extracted from. For each instruction, we set the magnitude of the "refusal direction" to be equal to the average magnitude of this direction across harmful prompts.
We test the effectiveness of this intervention over 128 harmless instructions from the Alpaca dataset. We generate completions without the addition ("baseline"), and with the addition ("intervention"). We then judge the completions using the "Refusal score" metric, as defined above.
We find this result unsurprising and implied by prior work, but include it for completeness. For example, Zou et al. 2023 showed that adding a harmfulness direction led to an 8 percentage point increase in refusal on harmless prompts in Vicuna 13B.
Here are a couple of fun examples of inducing refusal on harmless instructions with Gemma 7B:
Visualizing the subspace
To better understand the representation of harmful and harmless activations, we performed PCA decomposition of the activations at the last token across different layers. By plotting the activations along the top principal components, we observe that harmful and harmless activations are separated solely by the first PCA component.
Interestingly, after a certain layer, the first principle component becomes identical to the mean difference between harmful and harmless activations.
These findings provide strong evidence that refusal is represented as a one-dimensional linear subspace within the activation space.
Feature ablation via weight orthogonalization
We previously described an inference-time intervention to prevent the model from representing a direction ^r: for every contribution cout∈Rdmodel to the residual stream, we can zero out the component in the ^r direction:
c′out←cout−^r^rTcoutWe can equivalently implement this by directly modifying component weights to never write to the ^r direction in the first place. We can take each matrix Wout∈Rdmodel×dinput which writes to the residual stream, and orthogonalize its column vectors with respect to ^r:
W′out←Wout−^r^rTWoutIn a transformer architecture, the matrices which write to the residual stream are as follows: the embedding matrix , the positional embedding matrix, attention out matrices, and MLP out matrices. Orthogonalizing all of these matrices with respect to a direction ^r effectively prevents the model from writing ^r to the residual stream.
Related work
Note (April 28, 2024): We edited in this section after a discussion in the comments, to clarify which parts of this post were our novel contributions vs previously established knowledge.
Model interventions using linear representation of concepts
There exists a large body of prior work exploring the idea of extracting a direction that corresponds to a particular concept (Burns et al. 2022), and using this direction to intervene on model activations to steer the model towards or away from the concept (Li et al. 2023, Turner et al. 2023, Zou et al. 2023, Marks et al. 2023, Tigges et al. 2023, Rimsky et al. 2023). Extracting a concept direction by taking the difference of means between contrasting datasets is a common technique that has empirically been shown to work well.
Zou et al. 2023 additionally argue that a representation or feature focused approach may be more productive than a circuit-focused approach to leveraging an understanding of model internals, which our findings reinforce.
Belrose et al. 2023 introduce “concept scrubbing,” a technique to erase a linearly represented concept at every layer of a model. They apply this technique to remove a model’s ability to represent parts-of-speech, and separately gender bias.
Refusal and safety fine-tuning
In section 6.2 of Zou et al. 2023, the authors extract “harmfulness” directions from contrastive pairs of harmful and harmless instructions in Vicuna 13B. They find that these directions classify inputs as harmful or harmless with high accuracy, and accuracy is not significantly affected by appending jailbreak suffixes (while refusal rate is), showing that these directions are not predictive of model refusal. They additionally introduce a methodology to “robustify” the model to jailbreak suffixes by using a piece-wise linear combination to effectively amplify the “harmfulness” concept when it is weakly expressed, causing increased refusal rate on jailbreak-appended harmful inputs. As noted above, this section also overlaps significantly with our results inducing refusal by adding a direction, though they do not report results on bypassing refusal.
Rimsky et al. 2023 extract a refusal direction through contrastive pairs of multiple-choice answers. While they find that steering towards or against refusal effectively alters multiple-choice completions, they find steering to not be effective in bypassing refusal of open-ended generations.
Zheng et al. 2024 study model representations of harmful and harmless prompts, and how these representations are modified by system prompts. They study multiple open-source models, and find that harmful and harmless inputs are linearly separable, and that this separation is not significantly altered by system prompts. They find that system prompts shift the activations in an alternative direction, more directly influencing the model’s refusal propensity. They then directly optimize system prompt embeddings to achieve more robust refusal.
There has also been previous work on undoing safety fine-tuning via additional fine-tuning on harmful examples (Yang et al. 2023, Lermen et al. 2023).
Conclusion
Summary
Our main finding is that refusal is mediated by a 1-dimensional subspace: removing this direction blocks refusal, and adding in this direction induces refusal.
We reproduce this finding across a range of open-source model families, and for scales ranging 1.8B - 72B parameters:
Limitations
Our work one important aspect of how refusal is implemented in chat models. However, it is far from a complete understanding. We still do not fully understand how the "refusal direction" gets computed from harmful input text, or how it gets translated into refusal output text.
While in this work we used a very simple methodology (difference of means) to extract the "refusal direction," we maintain that there may exist a better methodology that would result in a cleaner direction.
Additionally, we do not make any claims as to what the directions we found represent. We refer to them as the "refusal directions" for convenience, but these directions may actually represent other concepts, such as "harm" or "danger" or even something non-interpretable.
While the 1-dimensional subspace observation holds across all the models we've tested, we're not certain that this observation will continue to hold going forward. Future open-source chat models will continue to grow larger, and they may be fine-tuned using different methodologies.
Future work
We're currently working to make our methodology and evaluations more rigorous. We've also done some preliminary investigations into the mechanisms of jailbreaks through this 1-dimensional subspace lens.
Going forward, we would like to explore how the "refusal direction" gets generated in the first place - we think sparse feature circuits would be a good approach to investigate this piece. We would also like to check whether this observation generalizes to other behaviors that are trained into the model during fine-tuning (e.g. backdoor triggers[8]).
Ethical considerations
A natural question is whether it was net good to publish a novel way to jailbreak a model's weights.
It is already well-known that open-source chat models are vulnerable to jailbreaking. Previous works have shown that the safety fine-tuning of chat models can be cheaply undone by fine-tuning on a set of malicious examples. Although our methodology presents an even simpler and cheaper methodology, it is not the first such methodology to jailbreak the weights of open-source chat models. Additionally, all the chat models we consider here have their non-safety-trained base models open sourced and publicly available.
Therefore, we don’t view disclosure of our methodology as introducing new risk.
We feel that sharing our work is scientifically important, as it presents an additional data point displaying the brittleness of current safety fine-tuning methods. We hope that this observation can better inform decisions on whether or not to open source future more powerful models. We also hope that this work will motivate more robust methods for safety fine-tuning.
Author contributions statement
This work builds off of prior work by Andy and Oscar on the mechanisms of refusal, which was conducted as part of SPAR under the guidance of Nina Rimsky.
Andy initially discovered and validated that ablating a single direction bypasses refusal, and came up with the weight orthogonalization trick. Oscar and Andy implemented and ran all experiments reported in this post. Andy wrote the Colab demo, and majority of the write-up. Oscar wrote the "Visualizing the subspace" section. Aaquib ran initial experiments testing the causal efficacy of various directional interventions. Wes and Neel provided guidance and feedback throughout the project, and provided edits to the post.
Recent research has begun to paint a picture suggesting that the fine-tuning phase of training does not alter a model’s weights very much, and in particular it doesn’t seem to etch new circuits. Rather, fine-tuning seems to refine existing circuitry, or to "nudge" internal activations towards particular subspaces that elicit a desired behavior.
Considering that refusal is a behavior developed exclusively during fine-tuning, rather than pre-training, it perhaps in retrospect makes sense that we could not gain much traction with a circuit-style analysis.
The Anthropic interpretability team has previously written about "high-level action features." We think the refusal feature studied here can be thought of as such a feature - when present, it seems to trigger refusal behavior spanning over many tokens (an "action").
See Marks & Tegmark 2023 for a nice discussion on the difference in means of contrastive datasets.
In our experiments, harmful instructions are taken from a combined dataset of AdvBench, MaliciousInstruct, and TDC 2023, and harmless instructions are taken from Alpaca.
For most models, we observe that considering the last token position works well. For some models, we find that activation differences at other end-of-instruction token positions work better.
The JailbreakBench dataset spans the following 10 categories: Disinformation, Economic harm, Expert advice, Fraud/Deception, Government decision-making, Harassment/Discrimination, Malware/Hacking, Physical harm, Privacy, Sexual/Adult content.
Note that we use the same direction for bypassing and inducing refusal. When selecting the best direction, we considered only its efficacy in bypassing refusal over a validation set, and did not explicitly consider its efficacy in inducing refusal.
Anthropic's recent research update suggests that "sleeper agent" behavior is similarly mediated by a 1-dimensional subspace.