Towards Safe Self-Distillation of Internet-Scale Text-to-Image Diffusion Models

Sanghyun Kim, Seohyeon Jung, Balhae Kim, Moonseok Choi, Jinwoo Shin, Juho Lee

TL;DR

Safe self-Distillation Diffusion (SDD) is a data-free fine-tuning method that prevents text-to-image models from generating harmful, explicit, or copyrighted content. By training the model's cross-attention layers to match concept-conditioned noise predictions with unconditional ones—stabilized by an exponential moving average (EMA) teacher—SDD effectively erases single or multiple problematic concepts without degrading general image quality.

What Problem Does This Paper Address?

Text-to-image diffusion models like Stable Diffusion learn rich visual representations from massive, uncurated web datasets (such as LAION-5B). Consequently, they also inherit problematic behaviors, generating copyrighted artistic styles, explicit nudity (NSFW), and harmful or toxic imagery.

Prior remedies have substantial drawbacks:

  • Filtering training data is computationally prohibitive, incomplete, and often degrades model capability by removing benign images.
  • Inference-time guidance (e.g., Safe Latent Diffusion or SEGA) increases generation latency by roughly 50% and struggles when tasked with suppressing several concepts at once.
  • Direct fine-tuning methods (such as Erasing Stable Diffusion, or ESD) push concept predictions in the opposite direction using Classifier-Free Guidance (CFG). This often leads to concept cancellation in multi-concept settings, catastrophic forgetting, and visual artifacts.

Methods

SDD introduces a self-distillation objective that neutralizes target concepts by forcing the model to treat sensitive prompts as if they were empty, unconditional inputs:

  1. Unconditional Target Matching: Instead of steering the latent space away with negative CFG, SDD minimizes the $\ell_2$ distance between the noise estimate conditioned on target concept $c_s$ and the stop-gradient unconditional noise estimate: $$\mathcal{L}_{\text{SDD}} = \|\epsilon_\theta(z_t, c_s, t) - \text{sg}(\epsilon_\theta(z_t, t))\|_2^2$$ Only the cross-attention layers are updated.

  2. EMA Teacher Stabilization: To prevent catastrophic forgetting and maintain structural image details, SDD maintains an Exponential Moving Average (EMA) teacher $\theta^*$. Intermediate noisy latents $z_t$ are generated on-the-fly using the EMA teacher, eliminating the need for external training images.

  3. Multi-Concept Scaling: When removing multiple concepts (e.g., 20 distinct safety risks), using CFG to steer away from all concepts simultaneously causes gradients to interfere and cancel out. SDD overcomes this by:
  4. Randomly selecting a single concept $c_p$ to sample the intermediate latent $z_t$.
  5. Concatenating all target concepts into a single prompt string $c_s$. The cross-attention layers naturally identify and eliminate the relevant harmful concept present in $z_t$.

Datasets

The authors evaluate SDD across safety, copyright, and general generation benchmarks:

  • NSFW Evaluation: 5,000 generated images using the prompt "<country> body" covering the top-50 GDP countries (evaluated via NudeNet).
  • I2P Benchmark: 4,703 real-world user prompts known to generate inappropriate content (23,515 images total), evaluated with the Q16 classifier across 20 distinct harmful concepts (e.g., violence, sexual, theft, blood).
  • General Image Quality: 30,000 MS-COCO prompts (COCO-30k) evaluated against MS-COCO 2014 validation images to calculate FID, LPIPS perceptual similarity, and CLIP text-alignment scores.
  • Artist Style Prompts: Prompts targeting distinctive styles (e.g., Vincent van Gogh, Thomas Kinkade, Kilian Eng).
  • Training Data: Fully data-free; synthetic latent trajectories are generated dynamically.

Key Insights and Ideas

  • Erasing means forgetting, not inverting: Previous techniques tried to steer generations away from harmful concepts using negative guidance vectors. SDD demonstrates that simply setting the conditioned response equal to the unconditional baseline is far more stable and avoids adversarial distortions.
  • EMA preserves semantic anchors: Without an EMA teacher, fine-tuning quickly collapses high-level context (e.g., erasing "Van Gogh" collapses "sunflower paintings" into photorealistic sunflowers). The slowly updated teacher ensures that general artistic attributes ("painting", "cottage") are preserved while stripping only the target artist identity.
  • Decoupled multi-concept distillation: Generating latent representations from one concept at a time while evaluating loss on the concatenated list sidesteps vector cancellation in diffusion noise space.

Key Results

  • NSFW Eradication: On the "<country> body" benchmark, SDD reduced the percentage of nudity images (%NUDE) to 1.68%, significantly outperforming baseline Stable Diffusion (74.18%), ESD-x-3 (14.32%), and SLD max (4.30%), while achieving a better FID (15.42 vs. 21.35 for SD).
  • Multi-Concept Detoxification (20 I2P Concepts): When removing 20 harmful concepts at once, SDD reduced harmful image generation (%HARM) from 24.42% down to 5.03% and %NUDE from 74.18% down to 12.62%. In comparison, ESD-x-3 retained 13.04% %HARM and 47.38% %NUDE.
  • Style Removal Without Spillover: Erasing a specific artist selectively altered images requesting that artist, leaving generations for other artists intact.

Limitations and Future Work

  • Residual Harm: The method significantly suppresses target concepts but cannot guarantee 100% eradication; adversarial prompt engineering can still occasionally bypass filters.
  • Risk of Quality Drift: Long training runs or aggressive updates can still cause subtle catastrophic forgetting or slight degradation in image fidelity.
  • Data-Free Bias: Relying purely on model self-generation means pre-existing demographic and representational biases in the base model may persist.
  • Future Directions: Combining SDD with pre- and post-processing defenses, exploring automated prompt tuning, and extending to broader safety policies.

Summary updated

BibTeX
@inproceedings{kim2023towards,
  author = {Sanghyun Kim and Seohyeon Jung and Balhae Kim and Moonseok Choi and Jinwoo Shin and Juho Lee},
  title = {{Towards Safe Self-Distillation of Internet-Scale Text-to-Image Diffusion Models}},
  booktitle = {DeployableGenerativeAI @ ICML},
  year = {2023},
  url = {https://openreview.net/forum?id=6zALFeqxY0},
}

Loading related content...

Figure