Tong Zhao1,2,βοΈ, Mingkun Lei2,βοΈ, Liangyu Yuan3,βοΈ,
Yanming Yang2, Chenxi Song2, Yang Wang2, Beier Zhu4, Chi Zhang2,π§
1Zhejiang University, 2AGI Lab, Westlake University, 3Tongji University, 4University of Science and Technology of China
βοΈ Equal contribution Β· π§ Corresponding author
Contact: zhaotong68@westlake.edu.cn, chizhang@westlake.edu.cn
- π Few-step diffusion sampling with superior stability and visual fidelity
- π§ Dynamic gradient weighting that adaptively aggregates historical gradients and implicitly scales the effective time step size
- β‘ Lightweight learned solver β no modification to the base diffusion model
- π― Compatible with both pixel-space models and latent-space models
- [2026.3.12] π₯ We release the code.
Official implementation of DyWeight, a learned sampling method for diffusion models that dynamically predicts optimal solver weights during generation.
Complete workflow: The full pipeline (training, sampling, and FID evaluation) with recommended configurations is provided in run.sh. You can find all commands there.
We provide support for large-scale latent diffusion models to validate the transferability and practical effectiveness of DyWeight.
For FLUX.1-dev usage details (setup, scripts, and notes), please refer to dyweight_flux/flux.md.
git clone https://github.com/Westlake-AGI-Lab/DyWeight.git
cd DyWeight
conda env create -f environment.yml
conda activate DyWeight
bash run.sh We recommend organizing project files into the following directory structure for training, sampling, and evaluation:
DyWeight/
βββ exps/ # Trained DyWeight predictor checkpoints (5-digit experiment IDs, e.g., 00000-cifar10-...)
βββ src/ # Pre-trained diffusion models (organized by dataset_name; auto-downloaded on first run)
β βββ cifar10/
β βββ ffhq/
β βββ imagenet64/
β βββ lsun_bedroom_ldm/
β βββ ...
βββ ref/ # FID reference statistics (.npz) for calc evaluation
βββ samples/ # Generated samples (organized by dataset/solver_nfe)
βββ ...
- exps: Default output directory for
train.py;--predictor_path=00000resolves here. - src: Pre-trained diffusion models are downloaded to
./src/<dataset_name>/viatorch_utils/download_util.py. - ref: Store FID reference
.npzfiles here.
Train DyWeight predictor (see run.sh for more examples). Pre-trained diffusion models are automatically downloaded to src/ on first run.
# CIFAR-10 (NFE=3, requires 2 GPUs)
OMP_NUM_THREADS=1 torchrun --standalone --nproc_per_node=2 train.py \
--dataset_name=cifar10 \
--batch=16 \
--total_kimg=10 \
--sampler_stu=dyweight --sampler_tea=ipndm \
--num_steps=5 --teacher_steps=35 \
--afs=True --max_history_steps=3 \
--schedule_type=polynomial --schedule_rho=7 \
--loss_type=inception \
--lr=3e-2 --use_cosine_annealing=TrueNote: NFE = (num_steps - 1) - 1 if afs=True, else (num_steps - 1)
Generate 50k samples for FID evaluation:
# Using trained predictor (saved in ./exps/)
OMP_NUM_THREADS=1 torchrun --standalone --nproc_per_node=2 sample.py \
--predictor_path=00000 \
--batch=128 \
--seeds=0-49999 \
--solver=dyweightCompute FID score (requires 50k generated samples first, 30k for MS-COCO dataset):
python -m eval.fid calc \
--images=samples/cifar10/dyweight_nfe3 \
--ref=ref/cifar10-32x32.npzFID Reference Statistics: Point --ref to a local .npz file in ref/, or use the following reference statistics:
- NVIDIA EDM fid-refs β CIFAR-10, FFHQ, AFHQv2, ImageNet-64, etc.
- AMED FID Statistics β Extended references including LDM, MS-COCO, and more.
Pre-trained diffusion models are automatically downloaded to src/<dataset_name>/ during training and sampling. Alternatively, download manually and place them in the corresponding directories.
| Codebase | dataset_name | Resolution | Pre-trained Model | Link |
|---|---|---|---|---|
| EDM | cifar10 | 32Γ32 | edm-cifar10-32x32-uncond-vp.pkl | Download |
| EDM | ffhq | 64Γ64 | edm-ffhq-64x64-uncond-vp.pkl | Download |
| EDM | afhqv2 | 64Γ64 | edm-afhqv2-64x64-uncond-vp.pkl | Download |
| EDM | imagenet64 | 64Γ64 | edm-imagenet-64x64-cond-adm.pkl | Download |
| Consistency | lsun_bedroom | 256Γ256 | edm_bedroom256_ema.pt | Download |
| ADM | imagenet256 | 256Γ256 | 256x256_diffusion.pt + 256x256_classifier.pt | diffusion Β· classifier |
| LDM | lsun_bedroom_ldm | 256Γ256 | lsun_bedrooms.zip | Download |
| LDM | ffhq_ldm | 256Γ256 | ffhq.zip | Download |
| LDM | vq-f4 | - | vq-f4.zip (LDM first-stage model) | Download |
| Stable Diffusion | ms_coco | 512Γ512 | v1-5-pruned-emaonly.ckpt | Download |
| - | prompts | - | MS-COCO_val2014_30k_captions.csv | Download |
| Setup | Category | Typical Resolution | Recommended GPU (VRAM) |
|---|---|---|---|
| CIFAR-10 | Pixel-space benchmark | 32Γ32 | RTX 4090 (24GB) |
| FFHQ | Pixel-space benchmark | 64Γ64 / 256Γ256 (depending on config) | RTX 4090 (24GB) |
| AFHQv2 | Pixel-space benchmark | 64Γ64 / 256Γ256 (depending on config) | RTX 4090 (24GB) |
| ImageNet-64 | Pixel-space benchmark | 64Γ64 | RTX 4090 (24GB) |
| LSUN Bedroom (LDM) | Latent diffusion benchmark | latent space (typically 256Γ256 image equivalent) | A100 / H100 (80GB) |
| Stable Diffusion (MS-COCO) | Large-scale latent T2I | 512Γ512 (typical) | A100 / H100 (80GB) |
| FLUX.1-dev (MS-COCO) | Large-scale latent T2I | 512Γ512 / 1024Γ1024 (depending on setup) | A100 / H100 (80GB) |
Adjust --batch-gpu according to available VRAM.
This repository is built upon the following codebases. We thank the authors for their excellent work and open-source contributions:
- EDM β Elucidating the Design Space of Diffusion-Based Generative Models
- diff-sampler (AMED) β Open-source toolbox for fast sampling of diffusion models
- EPD β Distilling parallel gradients for fast ODE solvers of diffusion models
If you find our work useful, please cite our related paper:
@article{zhao2026dyweight,
title={DyWeight: Dynamic Gradient Weighting for Few-Step Diffusion Sampling},
author={Tong Zhao and Mingkun Lei and Liangyu Yuan and Yanming Yang and Chenxi Song and Yang Wang and Beier Zhu and Chi Zhang},
year={2026},
eprint={2603.11607},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2603.11607},
}