forked from tianweiy/DMD2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4e54501
Showing
97 changed files
with
44,826 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
# Byte-compiled / optimized / DLL files | ||
model/ | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ | ||
|
||
*.swp | ||
|
||
|
||
diffusers | ||
|
||
*/*.png | ||
|
||
tests/data | ||
|
||
wandb | ||
|
||
.vscode | ||
*.zip | ||
*.npz | ||
*.tar.gz | ||
*.pyc | ||
*.pb | ||
*.pkl | ||
*.npz | ||
ignored_cache | ||
|
||
*.jpg | ||
*.png |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Improved Distribution Matching Distillation for Fast Image Synthesis | ||
|
||
Few-step Text-to-Image Generation. | ||
|
||
![image/jpeg](docs/teaser.jpg) | ||
|
||
> [**Improved Distribution Matching Distillation for Fast Image Synthesis**](https://tianweiy.github.io/dmd2/dmd2.pdf), | ||
> Tianwei Yin, Michaël Gharbi, Taesung Park, Richard Zhang, Eli Shechtman, Frédo Durand, William T. Freeman | ||
> *arXiv technical report ([arXiv xxxx.xxxxx](https://arxiv.org/abs/xxxx.xxxxx))* | ||
## Contact | ||
|
||
Feel free to contact us if you have any questions about the paper! | ||
|
||
Tianwei Yin [[email protected]](mailto:[email protected]) | ||
|
||
## Abstract | ||
|
||
Recent approaches have shown promises distilling diffusion models into | ||
efficient one-step generators. Among them, Distribution Matching Distillation | ||
(DMD) produces one-step generators that match their teacher in distribution, | ||
without enforcing a one-to-one correspondence with the sampling trajectories of | ||
their teachers. However, to ensure stable training, DMD requires an additional | ||
regression loss computed using a large set of noise-image pairs generated by | ||
the teacher with many steps of a deterministic sampler. This is costly for | ||
large-scale text-to-image synthesis and limits the student's quality, tying it | ||
too closely to the teacher's original sampling paths. We introduce DMD2, a set | ||
of techniques that lift this limitation and improve DMD training. First, we | ||
eliminate the regression loss and the need for expensive dataset construction. | ||
We show that the resulting instability is due to the fake critic not estimating | ||
the distribution of generated samples accurately and propose a two time-scale | ||
update rule as a remedy. Second, we integrate a GAN loss into the distillation | ||
procedure, discriminating between generated samples and real images. This lets | ||
us train the student model on real data, mitigating the imperfect real score | ||
estimation from the teacher model, and enhancing quality. Lastly, we modify the | ||
training procedure to enable multi-step sampling. We identify and address the | ||
training-inference input mismatch problem in this setting, by simulating | ||
inference-time generator samples during training time. Taken together, our | ||
improvements set new benchmarks in one-step image generation, with FID scores | ||
of 1.28 on ImageNet-64x64 and 8.35 on zero-shot COCO 2014, surpassing the | ||
original teacher despite a 500X reduction in inference cost. Further, we show | ||
our approach can generate megapixel images by distilling SDXL, demonstrating | ||
exceptional visual quality among few-step methods. | ||
|
||
## Environment Setup | ||
|
||
```.bash | ||
# In conda env | ||
conda create -n dmd2 python=3.8 -y | ||
conda activate dmd2 | ||
|
||
pip install --upgrade anyio | ||
pip install torch==2.0.1 torchvision==0.15.2 | ||
pip install --upgrade diffusers wandb lmdb transformers accelerate==0.23.0 lmdb datasets evaluate scipy opencv-python matplotlib imageio piq==0.7.0 safetensors gradio | ||
python setup.py develop | ||
``` | ||
|
||
## Inference Example | ||
|
||
To reproduce our ImageNet results, run: | ||
|
||
```.bash | ||
python demo/imagenet_example.py --checkpoint_path IMAGENET_CKPT_PATH | ||
``` | ||
|
||
To try our text-to-image generation demo, run: | ||
|
||
```.bash | ||
python demo/text_to_image_sdxl.py --checkpoint_path SDXL_CKPT_PATH | ||
``` | ||
|
||
Pretrained models can be found in [ImageNet](experiments/imagenet/README.md) and [SDXL](experiments/sdxl/README.md). | ||
|
||
## Training and Evaluation | ||
|
||
### ImageNet-64x64 | ||
|
||
Please refer to [ImageNet-64x64](experiments/imagenet/README.md) for details. | ||
|
||
### SDXL | ||
|
||
Please refer to [SDXL](experiments/sdxl/README.md) for details. | ||
|
||
### SDv1.5 | ||
|
||
Please refer to [SDv1.5](experiments/sdv1.5/README.md) for details. | ||
|
||
## License | ||
|
||
Improved Distribution Matching Distillation is released under [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](LICENSE.md). | ||
|
||
## Known Issues | ||
|
||
- [ ] Current FSDP for SDXL training is really slow; help is greatly appreciated! | ||
|
||
## Citation | ||
|
||
If you find DMD2 useful or relevant to your research, please kindly cite our papers: | ||
|
||
```bib | ||
@article{yin2024improved, | ||
title={Improved Distribution Matching Distillation for Fast Image Synthesis}, | ||
author={Yin, Tianwei and Gharbi, Micha{\"e}l and Park, Taesung and Zhang, Richard and Shechtman, Eli and Durand, Fredo and Freeman, William T}, | ||
journal={arXiv:xxxx.xxxxx}, | ||
year={2024} | ||
} | ||
@inproceedings{yin2024onestep, | ||
title={One-step Diffusion with Distribution Matching Distillation}, | ||
author={Yin, Tianwei and Gharbi, Micha{\"e}l and Zhang, Richard and Shechtman, Eli and Durand, Fr{\'e}do and Freeman, William T and Park, Taesung}, | ||
booktitle={CVPR}, | ||
year={2024} | ||
} | ||
``` | ||
|
||
## Third-part Code | ||
|
||
[EDM](https://github.com/NVlabs/edm/tree/main) for [dnnlib](dnnlib), [torch_utils](torch_utils) and [edm](third_party/edm) folders. | ||
|
||
## Acknowledgments | ||
|
||
This work was done while Tianwei Yin was a full-time student at MIT. It was developed based on our reimplementation of the original DMD paper. This work was supported by the National Science Foundation under Cooperative Agreement PHY-2019786 (The NSF AI Institute for Artificial Intelligence and Fundamental Interactions, http://iaifi.org/), by NSF Grant 2105819, by NSF CISE award 1955864, and by funding from Google, GIST, Amazon, and Quanta Computer. |
Oops, something went wrong.