This repository contains the code and implementation details for the research paper titled "A Closer Look at Time Steps is Worthy of Triple Speed-Up for Diffusion Model Training." In this paper, SpeeD, a novel speed-up method for diffusion model training, is introduced.
- Kai Wang2, Yukun Zhou1,2, Mingjia Shi2, Zekai Li2, Zhihang Yuan3, Yuzhang Shang4, Xiaojiang Peng*1, Hanwang Zhang5, Yang You2
- 1Shenzhen Technology University, 2National University of Singapore, 3Infinigence-AI, 4Illinois Institute of Technology, and 5Nanyang Technological University [Kai, Yukun, and Mingjia contribute equally to this work. We will update this repo asap.]
Our method, which is easily compatible, can accelerate the training of diffusion model.
Inspired by the following observation on time steps, we propose the re-sampling + re-weighting strategy as shown below.
To take a closer look at time steps, we find that the time steps could be divided into three areas: acceleration, decceleration and convergence areas. Samples of the corresponding time step in the convergence area are of limited benefit to training, while these time steps take up the most. Empirically, the training losses of these samples are quite low compare to the ones of the other two areas.
Asymmetric Sampling: Suppress the attendance of the time step in convergence areas.
Change-Aware Weighting: The faster changing time steps in the diffusion process are given more weight.
This code base does not use hardware acceleration technology, experimental environment is not complicated.
You can create a new conda environment:
conda env create -f environment.yml
conda activate speed
or install the necessary package by:
pip install -r requirements.txt
If necessary, we will provide more methods (e.g., docker) to facilitate the configuration of the experimental environment.
We provide a complete process for generating tasks including training, inference and test. The current code is only compatible with class-conditional image generation tasks. We will be compatible with more generation tasks about diffusion in the future.
We refactor the facebookresearch/DiT code and loaded the configs using OmegaConf . The configuration file loading rule is recursive for easier argument modification. Simply put, the file in the latter path will override the previous setting of base.yaml.
You can modify the experiment setting by modifying the config file and the command line. More details about the reading of config are written in configs/README.md.
For each experiment, you must provide two arguments by command,
-c: config path;
-p: phase including ['train', 'inference', 'sample'].
Baseline
Class-conditional image generation task with 256x256 ImageNet dataset and DiT-XL/2 models.
# Training: training diffusion and saving checkpoints
torchrun --nproc_per_node=8 main.py -c configs/image/imagenet_256/base.yaml -p train
# inference: generating samples for testing
torchrun --nproc_per_node=8 main.py -c configs/image/imagenet_256/base.yaml -p inference
# sample: sample some images for visualization
python main.py -c configs/image/imagenet_256/base.yaml -p sample
Ablation
You can modify the experiment setting by modifying the config file and the command line. More details about the configs are in configs/README.md.
For example, change the classifier-free guidance scale in sampling by command line:
python main.py -c configs/image/imagenet_256/base.yaml -p sample guidance_scale=1.5
Test the generation tasks require the results of inference. The more details about testing in evaluations.
The majority of this project is released under the Apache 2.0 license as found in the LICENSE file.
If you find our code useful in your research, please consider giving a star ⭐ and citation 📝.
@article{wang2024closer,
title={A Closer Look at Time Steps is Worthy of Triple Speed-Up for Diffusion Model Training},
author={Kai Wang, Mingjia Shi, Yukun Zhou, Zekai Li, Zhihang Yuan, Yuzhang Shang, Xiaojiang Peng, Hanwang Zhang and Yang You},
year={2024},
journal={arXiv preprint arXiv:2405.17403},
}
We thank Tianyi Li, Yuchen Zhang, Yuxin Li, Zhaoyang Zeng, and Yanqing Liu for the comments on this work. Kai Wang (idea, writing, story, presentation), Yukun Zhou (implementation), and Mingjia Shi (theory, writing, presentation) contribute equally to this work. Xiaojiang Peng, Hanwang Zhang, and Yang You are equal advising. Xiaojiang Peng is the corresponding author.
We are grateful for the following exceptional work and generous contribution to open source.