Finding NeMo: Localizing Neurons Responsible For Memorization in Diffusion Models

Dominik Hintersdorf, Lukas Struppek, Kristian Kersting, Adam Dziedzic, Franziska Boenisch

Abstract

Diffusion Models (DMs) are known to occasionally generate verbatim copies of their training data, posing significant risks to copyright and privacy. This paper introduces NeMo (Finding Neuron Momorization), a novel, gradient-free method to identify the specific neurons responsible for this behavior. By localizing memorization to a remarkably small subset of neurons—often a single neuron—the researchers demonstrate that "curing" a model of memorization is possible through surgical deactivation, preserving overall image quality while eliminating the reproduction of sensitive or copyrighted content.

Introduction

State-of-the-art Diffusion Models like Stable Diffusion are trained on massive, internet-scale datasets (e.g., LAION). A persistent challenge in these models is verbatim memorization: the tendency to output pixel-for-pixel replicas of training images when prompted. Current mitigation strategies, such as dataset filtering or inference-time prompt blocking, are often computationally expensive or easily circumvented.

NeMo addresses this by pinpointing the internal storage of these memorized samples. Instead of treating the model as a black box, the authors identify the specific "guilty" neurons within the architecture, allowing for precise intervention without the need for retraining.

Methodology: The NeMo Framework

NeMo utilizes a two-stage, gradient-free localization process to find memorization neurons:

  1. Quantifying Memorization Strength: The authors discovered that for memorized prompts, the "noise difference" (the delta between initial random noise and the first predicted noise step) remains nearly identical across different random seeds. They use the Structural Similarity Index (SSIM) of these noise differences as a proxy to detect and measure the strength of memorization.
  2. Initial Selection (OOD Detection): The method identifies neurons exhibiting "Out-of-Distribution" (OOD) activation patterns. A neuron is flagged if its activation for a specific prompt deviates significantly (by several standard deviations) from its typical behavior on a hold-out set of 50,000 normal prompts.
  3. Refinement: To ensure precision, the candidate list is refined by iteratively re-activating neurons and monitoring the memorization score. If deactivating a specific neuron does not reduce the SSIM-based memorization score, it is discarded as an "innocent bystander."

Key Insights: Where Memorization Lives

The "Single Neuron" Phenomenon

One of the paper's most striking findings is that complex, high-resolution images are often stored within a single neuron. In a test set of 500 memorized prompts, 28 distinct images were found to be tied to just one specific neuron each. For instance, Neuron #221 in the first cross-attention layer was identified as a "super-memorizer" for various podcast covers, while Neuron #25 specialized in specific portraits of people.

The Role of Value (V) Layers

The research localizes memorization almost exclusively to the Value (V) mapping layers of the cross-attention mechanism, specifically within the down-blocks and mid-blocks of the U-Net architecture. While Key (K) layers help the model associate prompts with concepts, the V layers appear to store the actual visual content. Deactivating these specific V-layer neurons effectively cuts the information flow of the memorized data while leaving the model's conceptual understanding intact.

Experimental Results

  • Effective Mitigation: By deactivating a small number of neurons (typically between 4 and 21 out of millions), the researchers reduced the SSCD score (a metric for image similarity) from 1.0 (a perfect copy) to approximately 0.10.
  • Restoring Generative Diversity: Once the memorization neurons are blocked, the model reverts to its intended generative behavior. Instead of producing a single memorized image, it generates a diverse array of novel images relevant to the prompt.
  • Preserving Model Quality: Evaluations using FID and KID metrics on the COCO dataset confirmed that deactivating these neurons does not degrade the model's general performance. Even deactivating up to 750 neurons—far more than required for mitigation—resulted in no significant loss of image quality.
  • Efficiency: NeMo is highly efficient, localizing the neurons responsible for a memorized sample in an average of 14 seconds on standard hardware, without requiring memory-intensive gradient calculations.

Limitations and Future Directions

While highly effective for verbatim memorization, the method faces challenges with Template Memorization, where the model replicates a layout or composition rather than exact pixels. These cases often involve more distributed representations (median of 21 neurons vs. 4). Additionally, in rare "highly memorized" instances where data is spread across 100+ neurons, complete elimination is more difficult.

Future work suggests that the NeMo approach could be extended to Large Language Models (LLMs) to identify neurons storing sensitive text or used for "knowledge editing" to permanently remove undesirable concepts like violence or explicit content from generative models.

Summary updated

BibTeX
@inproceedings{hintersdorf2024finding,
  author = {Dominik Hintersdorf and Lukas Struppek and Kristian Kersting and Adam Dziedzic and Franziska Boenisch},
  title = {{Finding NeMo: Localizing Neurons Responsible For Memorization in Diffusion Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=YAEKMFZyJm},
}
Figure