Steering Llama 2 via Contrastive Activation Addition

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

TL;DR

Contrastive Activation Addition (CAA) is a lightweight, inference-time method for steering Large Language Model (LLM) behavior by adding "steering vectors" directly into the model's residual stream. By simply averaging the activation differences between positive and negative examples of a behavior, researchers can precisely dial traits like honesty, sycophancy, or safety up or down without the prohibitive cost of finetuning.

What Problem Does This Paper Address?

Aligning LLMs to be "helpful, honest, and harmless" typically relies on Reinforcement Learning from Human Feedback (RLHF) or extensive finetuning. While effective, these methods are computationally expensive, often opaque, and can be difficult to control with precision once the model is deployed. Prompt engineering (like system prompts) offers a simpler alternative but is often brittle and fails to consistently steer complex behaviors.

The authors of this paper sought a middle ground: a way to intervene directly in the model's internal "thought process" (its activations) to modulate high-level behaviors reliably and efficiently.

Methods

The core of the paper is Contrastive Activation Addition (CAA). The process involves three main steps:

  1. Vector Generation: The researchers take pairs of prompts that differ only in the behavior they elicit. For example, a multiple-choice question where answer (A) is sycophantic and (B) is honest. They run these through the model and extract the activations from the "residual stream" at a specific layer and token position.
  2. Mean Difference (MD): By averaging the difference between these "positive" and "negative" activations across hundreds of pairs, they isolate a specific direction in the model's latent space that represents the behavior. This is the steering vector.
  3. Steering at Inference: When a user provides a new prompt, the steering vector is added to the model's activations at every token position following the instruction. By changing a "multiplier" (coefficient), they can increase or decrease the intensity of the behavior.
Figure 1: We perform forward passes on contrastive examples of answers to multiple-choice questions, ex- tracting residual stream activations at a particular layer at the token position of the answer. We then take the mean activation difference over many contrast pairs. At inference time, this vector is added back into the resid- ual stream with a chosen multiplier at all token positions after the instruction to control the behavior.

Standard PCA (Principal Component Analysis) was used to visualize these activations, revealing that high-level concepts often become linearly separable in the model's middle layers.

Datasets

The study utilized a variety of datasets to test seven distinct behaviors:

  • Existing Benchmarks: Anthropic’s "Advanced AI Risk" (for Corrigibility, Myopic Reward, Survival Instinct, and AI Coordination) and Perez et al.’s Sycophancy datasets.
  • New Datasets: The authors used GPT-4 to generate new contrastive datasets for Hallucination and Refusal.
  • Evaluation Benchmarks: MMLU was used to ensure general capabilities weren't degraded, and TruthfulQA was used to assess the impact on truthfulness.

Key Insights and Ideas

  • Behavioral Clustering: One of the most striking findings is that high-level concepts aren't scattered randomly. As shown in Figure 2, "behavioral clustering" emerges suddenly around the middle layers (e.g., layer 10 in Llama 2 7B), where the model's internal state clearly separates based on the intended behavior rather than just the specific tokens used.
  • Layer Universality: Steering vectors aren't strictly tied to the layer they were extracted from. A vector generated at layer 13 can effectively steer the model even when applied to earlier or later layers, suggesting it captures a "general representation" of the concept.
  • Additive Alignment: CAA works "on top" of existing alignment. You can take a model already trained with RLHF and use CAA to further refine its safety or honesty, or even use it to "undo" certain biases.
  • Generalization: Remarkably, steering vectors derived from simple multiple-choice questions successfully steer the model during complex, open-ended text generation.

Key Results

  • Effective Steering: CAA consistently altered model behavior across all seven tested categories. For instance, subtracting a "sycophancy vector" made the model significantly more likely to give honest, objective answers rather than just agreeing with the user.
  • Efficiency: Generating a CAA vector takes less than five minutes on a single GPU, compared to the hours and multiple GPUs required for finetuning.
  • Superior to Prompting: CAA provided more precise control than system prompting. In many cases, adding a steering vector modified behavior beyond what could be achieved by a positive system prompt alone.
  • Preserved Intelligence: The intervention had minimal impact on the model's MMLU scores, proving that you can steer a model's "personality" without making it "dumber."

Limitations and Future Work

  • Rater Bias: The study relied heavily on GPT-4 to evaluate open-ended responses. While the authors found GPT-4 to be a reliable rater, it may still possess its own biases.
  • Hyperparameter Tuning: Finding the "optimal" layer and multiplier currently requires a sweep (testing multiple options), which adds a step to the process.
  • Targeted Intervention: The current method adds the vector to all tokens after the prompt. Future work could explore adding it only to specific, semantically relevant tokens to improve efficiency and text quality.
  • Adversarial Use: The authors acknowledge that CAA could be used to steer models toward harmful behaviors, suggesting it could be a powerful tool for "red-teaming" and safety testing.

Summary updated

BibTeX
@inproceedings{panickssery2024steering,
  author = {Nina Panickssery 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