Localizing and Editing Knowledge In Text-to-Image Generative Models

Samyadeep Basu, Nanxuan Zhao, Vlad I Morariu, Soheil Feizi, Varun Manjunatha

TL;DR

Researchers have successfully mapped where specific visual knowledge—like artistic styles or object identities—resides within text-to-image (T2I) models like Stable Diffusion. By discovering that this knowledge is pinpointed in a single layer of the text-encoder, they developed DIFF-QUICKFIX, a method that can edit or remove concepts in under a second, achieving a 1000x speedup over traditional fine-tuning.

The Challenge of Model Editing

Large-scale T2I models are trained on billions of images, leading them to "memorize" a vast array of concepts, including copyrighted styles, trademarked characters, and potentially outdated facts. When we want to remove a specific concept or update a stale one, we face two major hurdles:

  1. Localization: We don't know exactly where in the billions of parameters this specific knowledge is stored.
  2. Efficiency: Current editing methods usually involve fine-tuning the model, which is computationally expensive and slow.

This research seeks to answer "where is the knowledge?" and uses that answer to make model editing nearly instantaneous.

Tracing Knowledge with Causal Mediation

To locate knowledge, the authors adapted Causal Mediation Analysis (also known as Causal Tracing) for the multimodal T2I setting. The process works in three steps:

  1. Corrupting the input: Adding Gaussian noise to the text embedding of a specific attribute (e.g., "Van Gogh").
  2. Restoring internal states: Systematically copying "clean" activations from an uncorrupted run back into the corrupted model, one layer at a time.
  3. Measuring the effect: If restoring a specific layer's activations causes the model to generate a faithful image again, that layer is deemed "causal" for that knowledge.
Overview of Causal Tracing in T2I models. Restoring a "causal" state fixes the corrupted generation, while a "non-causal" state does not.

Key Insights: UNet vs. Text-Encoder

The study reveals that knowledge storage is fundamentally different in the two main parts of a diffusion model:

  • Distributed UNet Knowledge: In the UNet, knowledge is distributed across many components (ResNet blocks and self-attention layers). Furthermore, different attributes rely on different sets of layers. For example, the first self-attention layer is causal for "style" but not for "objects" or "action."
  • The "Aha" Moment in the Text-Encoder: Unlike Large Language Models (LLMs), where factual knowledge often lives in the middle MLP layers, the authors found that in T2I models, knowledge is highly localized. It is concentrated in the first self-attention layer corresponding to the last subject token of the attribute.
Causal Tracing results for the UNet show that causal states (dark green bars) are spread across many layers and vary by attribute (Style, Objects, Action, Color).

Fast Editing with DIFF-QUICKFIX

Based on the finding that knowledge is localized to a single causal layer in the text-encoder, the authors introduced DIFF-QUICKFIX. By applying a closed-form linear update to that specific layer's weights, they enable "data-free" editing that bypasses the iterative optimization of fine-tuning.

Key Results: * Speed: DIFF-QUICKFIX performs edits in under one second, providing a 1000x speedup over existing fine-tuning methods like Concept-Ablation. * Effectiveness: Despite the speed, it achieves comparable or better performance in removing styles and objects. * Multi-Concept Editing: The method can effectively ablate up to 10 distinct concepts simultaneously without a significant drop in image quality. * Knowledge Updating: It successfully updates facts (e.g., changing the generated image for a specific role to reflect a new person) by shifting the model's internal associations.

Limitations and Future Work

Because knowledge in the UNet is highly distributed, the authors found it much harder to perform targeted edits there without causing "collateral damage" to other concepts. Consequently, DIFF-QUICKFIX focuses primarily on the text-encoder.

Additionally, the study focused on style, objects, color, and action. Other attributes like "viewpoint" or "count" proved more difficult, often because the base models struggle with them even before editing. Future work may leverage the distributed nature of the UNet to develop even more sophisticated editing techniques that combine both text-encoder and UNet modifications.

Summary updated

BibTeX
@inproceedings{basu2024localizing,
  author = {Samyadeep Basu and Nanxuan Zhao and Vlad I Morariu and Soheil Feizi and Varun Manjunatha},
  title = {{Localizing and Editing Knowledge In Text-to-Image Generative Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=Qmw9ne6SOQ},
}
Figure