Self-Control of LLM Behaviors by Compressing Suffix Gradient into Prefix Controller

Min Cai, Yuchen Zhang, Shichang Zhang, Fan Yin, Dan Zhang, Difan Zou, Yisong Yue, Ziniu Hu

TL;DR

Researchers have developed SELFCONTROL, a novel framework that allows Large Language Models (LLMs) to steer their own behavior at inference time using self-evaluation gradients. By compressing these "suffix gradients" into a compact PREFIXCONTROLLER, the method achieves precise, zero-latency control over attributes like toxicity, truthfulness, and emotion without requiring expensive human-annotated datasets.

What Problem Does This Paper Address?

Aligning LLMs with human intentions typically requires massive amounts of human-annotated preference data (for RLHF or DPO) or manual curation of contrastive pairs for representation engineering. These approaches are often "black boxes," lack transparency, and struggle with out-of-domain behaviors. Furthermore, adding a new desired behavior usually requires expensive fine-tuning, which can inadvertently degrade the model's performance on previously learned tasks.

The authors ask: Can we use the model's own internal knowledge to control its behavior on-the-fly, without human labels, and in a way that is both efficient and composable?

Methods

The authors introduce a two-stage approach:

  1. SELFCONTROL (Instance-Level): When a model generates a response, the system appends a "suffix string"—a natural language question asking the model to evaluate itself (e.g., "Was your response happy? Yes or No?"). The model calculates a suffix score based on the probability of answering "Yes" vs "No." It then computes the gradient of this score with respect to its own internal latent representations ($H_{input}$). By iteratively updating these representations using the gradient, the model "steers" its internal state toward the desired behavior before final generation.

    Figure 2: Framework of SELFCONTROL. We begin by sampling an initial response from a language model and selecting an appropriate suffix string and a target label to define a control direction. Suffixes can be combined. As shown in the figure, we select “Be Happier” from the suffix pool to define our attribute. Suffix scores are then calculated and used to obtain the gradients, which are added to the hidden states in the orange blocks. These modified hidden states are then used to sample new responses—steps 3 and 4 form an iteration loop, leading to the final controlled response.
  2. SELFCONTROL$_{PREFIX}$ (Across-Instance): The iterative gradient search is computationally expensive. To solve this, the authors train a PREFIXCONTROLLER—a small, parameter-efficient adapter. This adapter learns to map standard input representations to the "optimized" representations discovered during the SELFCONTROL phase using a Mean Squared Error (MSE) loss. Once trained, this prefix can be plugged into the model for instant, zero-latency control.

    Figure 3: Training pipeline of SELFCONTROLPREFIX using PREFIXCONTROLLER. PREFIXCON- TROLLER contains prompts of learnable soft tokens at each layer, including the embedding layer. Specifically, the prompt at the embedding layer is initialized using a neutral human-written prompt. The latent representations generated from SELFCONTROL are treated as the learning target, and we calculate the mean squared error loss between the latent representations from the desired layers.

Datasets

The framework was evaluated across a diverse set of tasks and datasets:

  • Detoxification: RealToxicityPrompts (LLaMA-2, Mistral, LLaMA-3.1).
  • Privacy Protection: DecodingTrust (rejecting email address generation).
  • Emotion Control: Five emotional attributes (anger, fear, happiness, surprise, disgust) from the RepE dataset.
  • Harmlessness/Helpfulness: Anthropic-HH dataset.
  • Reasoning: GSM-8K (math word problems).
  • Truthfulness: Synthetic cities and neg_cities datasets.

Key Insights and Ideas

  • The Model as Its Own Judge: The core "aha moment" is that LLMs often "know" when they are being toxic or untruthful; SELFCONTROL simply provides a mathematical bridge (gradients) to turn that self-awareness into behavioral change.
  • Layer-Wise Specialization: The authors found that different behaviors are "stored" in different parts of the Transformer. As shown in Figure 5, low-level tasks like reasoning and harmlessness are influenced by earlier layers, while high-level attributes like privacy and emotion are controlled by the final layers.
  • Fundamental Restructuring: Unlike previous methods (like Contrast Vectors) that merely rotate or translate the representation space, SELFCONTROL fundamentally restructures the internal geometry of the model's representations, leading to a clearer linear pattern for truthfulness and other attributes.
  • Compositionality: Because the controllers are prefix-based, they are modular. You can combine a "happier" controller with a "calmer" controller to achieve a composite emotional tone.
Figure 1: Our SELFCONTROL and SELFCON- TROLPREFIX are able to control LLM behaviors, e.g., emotion. With SELFCONTROL, you can obtain the suffix gradient for the desired attribute for precise control, while SELFCONTROLPREFIX enables the composition of these attributes with PREFIXCONTROLLER.

Key Results

  • Detoxification: Improved over state-of-the-art (SOTA) methods by 8.3%.
  • Privacy Protection: Achieved a 48.2% improvement, effectively eliminating privacy leakage in tested scenarios (0% leakage vs. 58% for the base model).
  • Truthfulness: Enhanced truthfulness by 3.1% in in-context learning tasks.
  • Efficiency: The PREFIXCONTROLLER is 10x faster than the iterative SELFCONTROL method and adds virtually no latency compared to the original uncontrolled model.
  • Reasoning: Surprisingly, the method also improved math reasoning on GSM-8K, outperforming standard greedy decoding by a significant margin.

Limitations and Future Work

While powerful, the authors note several areas for further exploration:

  • Gradient Sources: The study focused exclusively on maximizing suffix scores; other differentiable signals might offer even better control.
  • Adapter Architecture: The PREFIXCONTROLLER uses standard PEFT (Parameter-Efficient Fine-Tuning) modules, which may not be the optimal architecture for learning these specific gradient-based representations.
  • Mechanistic Transparency: While the PCA visualizations (Figure 6) provide some insight, the exact mechanism of how these prefixes alter model logic remains a subject for future research.
  • Embedding Level: The effectiveness of control at the embedding level versus deeper hidden layers is not yet fully understood.

Summary updated

BibTeX
@misc{cai2024self,
  author = {Min Cai and Yuchen Zhang and Shichang Zhang and Fan Yin and Dan Zhang and Difan Zou and Yisong Yue and Ziniu Hu},
  title = {{Self-Control of LLM Behaviors by Compressing Suffix Gradient into Prefix Controller}},
  year = {2024},
  eprint = {2406.02721},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.02721},
}
Figure