Training-Free Safe Denoisers for Safe Use of Diffusion Models

Mingyu Kim, Dongjun Kim, Amman Yusuf, Stefano Ermon, Mijung Park

Powerful diffusion models (DMs) like Stable Diffusion have revolutionized content creation, but they come with a dark side: the ability to generate "not-safe-for-work" (NSFW) imagery, reproduce copyrighted material, or leak private training data. While researchers have tried to fix this using expert-crafted "negative prompts" or by expensive retraining, these methods often fail against clever adversarial attacks or degrade the model's overall creative quality.

In a new paper presented at NeurIPS 2025, researchers from UBC and Stanford propose a radically different approach: Training-Free Safe Denoisers. Instead of changing the model itself, they change how it "walks" through the data space during generation, steering it away from unsafe regions in real-time.

TL;DR

This paper introduces a mathematical framework to steer diffusion model sampling trajectories away from "unsafe" regions using a small set of reference images rather than just text. This training-free method effectively mitigates NSFW generation and data memorization while maintaining—and sometimes even improving—image quality and diversity.

What Problem Does This Paper Address?

Current safety mechanisms for diffusion models generally fall into two camps:

  1. Text-based guidance: Using negative prompts (e.g., "nudity, violence") to tell the model what not to do. These are easy to bypass with "jailbreaking" prompts that describe unsafe scenes without using forbidden words.
  2. Model unlearning: Retraining the model to "forget" certain concepts. This is computationally expensive and can lead to "catastrophic forgetting," where the model loses its ability to generate unrelated, safe content well.

The authors identify a specific gap: models often memorize training data (see Figure 1b) or fall into unsafe distribution regions even when the prompt seems benign. They sought a way to provide safety guarantees at inference time without the overhead of retraining.

Figure 1: The method prevents nudity (a) and mitigates data memorization (b) by steering the model away from specific real images.

Methods

The core idea is the Safe Denoiser. The authors formally derive a relationship showing that a "safe" denoising step can be constructed by taking the standard model output and subtracting a "direction" that leads toward unsafe data.

Mathematically, they define the safe denoiser as: $$E_{safe} = E_{data} + \beta^*(x_t)(E_{data} - E_{unsafe})$$

Here’s the intuition:

  • $E_{data}$ is where the model naturally wants to go.
  • $E_{unsafe}$ is the direction toward a "negation set" (a small collection of unsafe or private images).
  • $\beta^*(x_t)$ is an adaptive weight that grows larger the closer the current sample is to the unsafe region.
Figure 2: An overview of the safe denoiser. (a) The safe denoiser Esafe negates the direction of the unsafe denoiser Eunsafe from the data denoiser Edata. (b) Trajectories from data denoiser and safe denoiser, starting from the same initial point far from the data distribution, reveal distinct paths: while the sample path from the data denoiser falls into the unsafe region, the trajectory from the safe denoiser successfully avoids it.

Crucially, this is training-free. You don't need to fine-tune the model; you just need a few examples of what you want to avoid. The algorithm approximates the "unsafe direction" by looking at the distance between the current noisy image and the images in your negation set.

Datasets

The researchers put their method through a gauntlet of safety benchmarks:

  • Safety Evaluation: They used I2P (Inappropriate P2P) and CoPro (a large-scale dataset with 226k prompts) to test against concepts like hate, harassment, and self-harm.
  • Adversarial Attacks: They tested against prompts from Ring-A-Bell, UnlearnDiff, and MMA-Diffusion, which are specifically designed to trick models into generating NSFW content.
  • General Quality: COCO-30K was used to ensure the model still generates high-quality, diverse images for standard prompts.
  • Specific Tasks: ImageNet for class removal (e.g., "forgetting" the Chihuahua class) and FFHQ for sexual debiasing in facial generation.

Key Insights and Ideas

  • Image-Based Guidance is Robust: Unlike text prompts, which can be ambiguous or bypassed, using actual images as "negative anchors" provides a much stronger signal for what the model should avoid.
  • The "U-Shaped" Sweet Spot: The authors found that safety isn't just about maximizing the penalty. There is an optimal threshold ($\beta_t$) for applying the safe denoiser. If applied too weakly, safety fails; if applied too aggressively, it can actually push the model back toward unsafe regions or destroy image quality.
  • Diversity Boost: Surprisingly, the safe denoiser can improve the FID score (a measure of image quality and diversity). High "Classifier-Free Guidance" (CFG) usually makes images look better but reduces variety. The safe denoiser introduces a form of "safe stochasticity" that recovers some of that lost diversity.
  • Efficiency: Because it uses simple distance calculations between the current sample and a small set of reference images, the computational overhead is negligible—adding only about 0.02 to 0.07 seconds per image on an RTX 4090.

Key Results

  • Superior Safety: When combined with existing methods like SAFREE, the Safe Denoiser reduced the Attack Success Rate (ASR) on the difficult MMA-Diffusion benchmark from 60.1% down to 46.9%.
  • Data Privacy: The method successfully prevented the model from regenerating specific private images (like the "Ann Graham Lotz" case) by using those images in the negation set. The resulting images retained the style of the prompt but changed the specific identity features.
  • Class Negation: On ImageNet, the model was able to completely stop generating "Chihuahuas" (Top-1 accuracy dropped to 0.0%) while maintaining high precision and recall for all other 999 classes.

Limitations and Future Work

While promising, the authors note a few hurdles:

  • Hyperparameter Tuning: The method requires tuning the strength ($\eta$) and the threshold ($\beta_t$) to balance safety and image fidelity.
  • Negation Set Requirement: You need a representative set of "unsafe" images to steer away from. While the authors showed that even a few images work, building comprehensive negation sets for every possible harmful concept is a challenge.
  • New Modalities: This work focused on images. Extending these theoretical safety guarantees to video or audio diffusion models remains an open area for research.

By treating safety as a navigation problem rather than a memory problem, this research offers a practical, low-cost way to make generative AI more responsible without stifling its creative potential.

Summary updated

Abstract

There is growing concern over the safety of powerful diffusion models (DMs), as they are often misused to produce inappropriate, not-safe-for-work (NSFW) content or generate copyrighted material or data of individuals who wish to be forgotten. Many existing methods tackle these issues by heavily relying on text-based negative prompts or extensively retraining DMs to eliminate certain features or samples. In this paper, we take a radically different approach, directly modifying the sampling trajectory by leveraging a negation set (e.g., unsafe images, copyrighted data, or datapoints needed to be excluded) to avoid specific regions of data distribution, without needing to retrain or fine-tune DMs. We formally derive the relationship between the expected denoised samples that are safe and those that are not safe, leading to our $\textit{safe}$ denoiser which ensures its final samples are away from the area to be negated. Inspired by the derivation, we develop a practical algorithm that successfully produces high-quality samples while avoiding negation areas of the data distribution in text-conditional, class-conditional, and unconditional image generation scenarios. These results hint at the great potential of our training-free safe denoiser for using DMs more safely.
BibTeX
@inproceedings{kim2025training,
  author = {Mingyu Kim and Dongjun Kim and Amman Yusuf and Stefano Ermon and Mijung Park},
  title = {{Training-Free Safe Denoisers for Safe Use of Diffusion Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=QQS7TudonJ},
}
Figure