Skip to main content

MSE-optimal diffusion model scheduler (DMSE) for the HuggingFace diffusers library

Project description

diffusers-dmse

MSE-optimal diffusion model scheduler (DMSE) for the HuggingFace diffusers library.

Inherits DDPMScheduler and modifies the reverse process to omit stochastic resampling, yielding a deterministic path that converges to the conditional mean estimator (CME) — the MSE-optimal denoiser.

Paper

B. Fesl, B. Böck, F. Strasser, M. Baur, M. Joham, W. Utschick, "On the Asymptotic Mean Square Error Optimality of Diffusion Models," AISTATS 2025.

[arXiv] [OpenReview] [PMLR]

Installation

pip install diffusers-dmse

Usage

Denoising a noisy observation (primary use case)

Use init_step() to find the timestep matching the observed SNR, then run the reverse process from that point. This implements Eq. (12) of the paper.

from diffusers import UNet2DModel
from diffusers_dmse import DMSEScheduler
import torch

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

scheduler = DMSEScheduler.from_pretrained("google/ddpm-cat-256")
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to(device)

# set_timesteps must be called before init_step
scheduler.set_timesteps(1000)

# Find starting timestep matching the observed SNR (in dB)
t_init, idx = scheduler.init_step(snr=10.0, is_logarithmic=True)

x = noisy_observation  # your input tensor, shape (B, C, H, W)
for t in scheduler.timesteps[idx:]:
    with torch.no_grad():
        eps = model(x, t).sample
    x = scheduler.step(eps, t, x).prev_sample

Unconditional generation (deterministic DDPM)

Drop-in replacement for DDPMScheduler. Runs the full reverse chain without noise, equivalent to DDIM with eta=0 using the DDPM posterior mean.

from diffusers import UNet2DModel
from diffusers_dmse import DMSEScheduler
import torch

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

scheduler = DMSEScheduler.from_pretrained("google/ddpm-cat-256")
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to(device)
scheduler.set_timesteps(50)

x = torch.randn((1, 3, 256, 256), device=device)
for t in scheduler.timesteps:
    with torch.no_grad():
        eps = model(x, t).sample
    x = scheduler.step(eps, t, x).prev_sample

Key difference from DDPMScheduler

DDPM DMSE
Reverse step x_{t-1} = µ_t(x_t) + σ_t·z, z~N(0,I) x_{t-1} = µ_t(x_t)
Stochastic Yes No
Optimal for Generation diversity MSE / denoising
Starting point t=T (pure noise) SNR-matched t via init_step()

Related repositories

  • Diffusion_MSE: Full source code for the AISTATS 2025 paper, including GMM, MNIST, and audio experiments.
  • Diffusion_channel_est: Application of DMSE to MIMO channel estimation (IEEE Wireless Communications Letters, 2024). [Paper]

License

MIT License. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffusers_dmse-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diffusers_dmse-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file diffusers_dmse-0.1.0.tar.gz.

File metadata

  • Download URL: diffusers_dmse-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for diffusers_dmse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c2579ad4363ffc3cbd9add987d3e39ddc180c04b33493e6f880bd2b81b8ba1b4
MD5 4fe435d6f706660dd978527a5ed20463
BLAKE2b-256 616f84673c3a0bea870278c1d9a543ab288ef90a460df9dba8757b9c2d2464dd

See more details on using hashes here.

File details

Details for the file diffusers_dmse-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: diffusers_dmse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for diffusers_dmse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be7e77577ea428d9c4a64f9f35ade185842f3052f0aedef47b4386e71e3fea0b
MD5 2b675a4271c07f1b8813c48c0b6b1e65
BLAKE2b-256 cd29c723275723a38af4ca58e557d36f9b18e60b7bc484c08de4e4e17efe8959

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page