Steering Llama 2 via Contrastive Activation Addition

Nina Rimsky, Nick Gabrieli, Julian Schulz, Meg Tong, Evan Hubinger, Alexander Matt Turner

Abstract

We introduce Contrastive Activation Addition (CAA), a method for steering language models by modifying their activations during forward passes. CAA computes “steering vectors” by averaging the difference in residual stream activations between pairs of positive and negative examples of a particular behavior. During inference, these steering vectors are added at all token positions after the user’s prompt, allowing precise control over the degree of the targeted behavior. We demonstrate that CAA significantly alters model behavior in Llama 2 Chat, is effective on top of traditional alignment methods, and minimally reduces general capabilities.

Introduction

Aligning Large Language Models (LLMs) to be helpful, honest, and harmless typically involves Reinforcement Learning from Human Feedback (RLHF) or supervised finetuning. While powerful, these methods are computationally intensive and can result in "black-box" models that are difficult to interpret or adjust post-training. Conversely, prompt engineering is lightweight but often lacks the precision needed to control complex semantic behaviors reliably.

Contrastive Activation Addition (CAA) offers a "middle ground." It provides a mechanism to control high-level behaviors—such as sycophancy, truthfulness, or refusal—by intervening directly in the model's latent space. This approach is significantly more efficient than finetuning and more robust than prompting.

Methodology

The CAA process consists of two primary stages: vector extraction and inference-time steering.

Vector Extraction

To isolate the mathematical representation of a specific behavior, we use "contrast pairs." These are prompts (e.g., multiple-choice questions) where one response represents the target behavior (positive) and the other represents its opposite (negative). We record the activations in the model's residual stream at a specific layer $n$ for both responses. The steering vector is calculated by taking the difference between the positive and negative activations and averaging this difference across a large dataset of pairs.

Diagram of steering vector generation for CAA, showing the extraction and averaging of activation differences from contrast pairs.

Steering at Inference

During generation, the extracted steering vector is added to the model's activations at every token position following the initial instruction. A multiplier coefficient allows for real-time adjustment: a positive coefficient amplifies the behavior, while a negative one suppresses it.

Diagram of steering vector application during inference, illustrating the addition of the vector to the residual stream after the prompt.

Experimental Setup

We evaluated CAA using Llama 2 (7B and 13B variants) across several behavioral datasets:

  • Advanced AI Risk (Anthropic): Behaviors including corrigibility and survival instinct.
  • Sycophancy: Datasets focused on political and NLP-related flattery.
  • Custom GPT-4 Sets: Newly generated contrastive pairs for hallucination and refusal.

Performance was measured using held-out multiple-choice questions and open-ended generation tasks evaluated by GPT-4. General model capabilities were monitored via MMLU and TruthfulQA benchmarks.

Key Insights

The "Concept" Layer

Principal Component Analysis (PCA) reveals that behavioral concepts tend to cluster and become linearly separable in the residual stream approximately one-third of the way through the model (e.g., layers 10-13 for Llama 2 7B). This suggests a transition point where the model moves from syntactic processing to abstract semantic representation.

Additive Alignment

CAA acts as a complementary layer to existing alignment. It can further enhance the safety of a finetuned model or mitigate "over-refusal" issues. Interestingly, steering vectors extracted from base models remain effective when applied to chat-finetuned versions, suggesting that RLHF primarily alters the probability of behaviors rather than their underlying internal representations.

Truthfulness vs. Sycophancy

A notable finding is that suppressing the "sycophancy" vector improves performance on TruthfulQA. This indicates that models often possess the correct information but may prioritize user-pleasing responses; CAA provides a way to bypass this behavioral bias to access latent knowledge.

Results

  • Effective Control: CAA significantly shifts model behavior. For Llama 2 13B, the sycophancy steering vector increased the rate of sycophantic responses from ~20% to over 60%.
  • Generalization: Vectors derived from simple multiple-choice formats successfully steer complex, open-ended prose generation.
  • Capability Preservation: CAA interventions result in negligible impact on MMLU scores, maintaining the model's general intelligence while altering its behavioral tendencies.
  • Efficiency: Generating a steering vector is highly efficient, requiring only a few minutes on a single GPU.

Conclusion and Future Work

Contrastive Activation Addition is a robust and efficient method for steering LLM behavior. While current evaluations rely on automated judges like GPT-4, future work will explore more granular token targeting and interventions in other model components like MLP blocks or attention heads. CAA not only provides a tool for better alignment but also offers a window into how high-level concepts are encoded within neural networks.

Summary updated

BibTeX
@inproceedings{rimsky2024steering,
  author = {Nina Rimsky and Nick Gabrieli and Julian Schulz and Meg Tong and Evan Hubinger and Alexander Matt Turner},
  title = {{Steering Llama 2 via Contrastive Activation Addition}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=4SevDx4mZl},
}
Figure