[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-9709":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":18,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":16,"starSnapshotCount":16,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},9709,"denoising-diffusion-pytorch","lucidrains\u002Fdenoising-diffusion-pytorch","lucidrains","Implementation of Denoising Diffusion Probabilistic Model in Pytorch","",null,"Python",10604,1283,35,147,0,3,12,54,44.33,"MIT License",false,"main",true,[26,27,28,29],"artificial-intelligence","deep-learning","generative-model","score-matching","2026-06-12 02:02:11","\u003Cimg src=\".\u002Fimages\u002Fdenoising-diffusion.png\" width=\"500px\">\u003C\u002Fimg>\n\n## Denoising Diffusion Probabilistic Model, in Pytorch\n\nImplementation of \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2006.11239\">Denoising Diffusion Probabilistic Model\u003C\u002Fa> in Pytorch. It is a new approach to generative modeling that may \u003Ca href=\"https:\u002F\u002Fajolicoeur.wordpress.com\u002Fthe-new-contender-to-gans-score-matching-with-langevin-sampling\u002F\">have the potential\u003C\u002Fa> to rival GANs. It uses denoising score matching to estimate the gradient of the data distribution, followed by Langevin sampling to sample from the true distribution.\n\nThis implementation was inspired by the official Tensorflow version \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fhojonathanho\u002Fdiffusion\">here\u003C\u002Fa>\n\nYoutube AI Educators - \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=W-O7AZNzbzQ\">Yannic Kilcher\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=344w5h24-h8\">AI Coffeebreak with Letitia\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=HoKDTa5jHvg\">Outlier\u003C\u002Fa>\n\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fyiyixuxu\u002Fdenoising-diffusion-flax\">Flax implementation\u003C\u002Fa> from \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fyiyixuxu\">YiYi Xu\u003C\u002Fa>\n\n\u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fblog\u002Fannotated-diffusion\">Annotated code\u003C\u002Fa> by Research Scientists \u002F Engineers from \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002F\">🤗 Huggingface\u003C\u002Fa>\n\nUpdate: Turns out none of the technicalities really matters at all | \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2208.09392\">\"Cold Diffusion\" paper\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fmuse-model.github.io\u002F\">Muse\u003C\u002Fa>\n\n\u003Cimg src=\".\u002Fimages\u002Fsample.png\" width=\"500px\">\u003Cimg>\n\n[![PyPI version](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fdenoising-diffusion-pytorch.svg)](https:\u002F\u002Fbadge.fury.io\u002Fpy\u002Fdenoising-diffusion-pytorch)\n\n## Install\n\n```bash\n$ pip install denoising_diffusion_pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom denoising_diffusion_pytorch import Unet, GaussianDiffusion\n\nmodel = Unet(\n    dim = 64,\n    dim_mults = (1, 2, 4, 8),\n    flash_attn = True\n)\n\ndiffusion = GaussianDiffusion(\n    model,\n    image_size = 128,\n    timesteps = 1000    # number of steps\n)\n\ntraining_images = torch.rand(8, 3, 128, 128) # images are normalized from 0 to 1\nloss = diffusion(training_images)\nloss.backward()\n\n# after a lot of training\n\nsampled_images = diffusion.sample(batch_size = 4)\nsampled_images.shape # (4, 3, 128, 128)\n```\n\nOr, if you simply want to pass in a folder name and the desired image dimensions, you can use the `Trainer` class to easily train a model.\n\n```python\nfrom denoising_diffusion_pytorch import Unet, GaussianDiffusion, Trainer\n\nmodel = Unet(\n    dim = 64,\n    dim_mults = (1, 2, 4, 8),\n    flash_attn = True\n)\n\ndiffusion = GaussianDiffusion(\n    model,\n    image_size = 128,\n    timesteps = 1000,           # number of steps\n    sampling_timesteps = 250    # number of sampling timesteps (using ddim for faster inference [see citation for ddim paper])\n)\n\ntrainer = Trainer(\n    diffusion,\n    'path\u002Fto\u002Fyour\u002Fimages',\n    train_batch_size = 32,\n    train_lr = 8e-5,\n    train_num_steps = 700000,         # total training steps\n    gradient_accumulate_every = 2,    # gradient accumulation steps\n    ema_decay = 0.995,                # exponential moving average decay\n    amp = True,                       # turn on mixed precision\n    calculate_fid = True              # whether to calculate fid during training\n)\n\ntrainer.train()\n```\n\nSamples and model checkpoints will be logged to `.\u002Fresults` periodically\n\n## Multi-GPU Training\n\nThe `Trainer` class is now equipped with \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Faccelerate\u002Faccelerator\">🤗 Accelerator\u003C\u002Fa>. You can easily do multi-gpu training in two steps using their `accelerate` CLI\n\nAt the project root directory, where the training script is, run\n\n```python\n$ accelerate config\n```\n\nThen, in the same directory\n\n```python\n$ accelerate launch train.py\n```\n\n## Miscellaneous\n\n### 1D Sequence\n\nBy popular request, a 1D Unet + Gaussian Diffusion implementation.\n\n```python\nimport torch\nfrom denoising_diffusion_pytorch import Unet1D, GaussianDiffusion1D, Trainer1D, Dataset1D\n\nmodel = Unet1D(\n    dim = 64,\n    dim_mults = (1, 2, 4, 8),\n    channels = 32\n)\n\ndiffusion = GaussianDiffusion1D(\n    model,\n    seq_length = 128,\n    timesteps = 1000,\n    objective = 'pred_v'\n)\n\ntraining_seq = torch.rand(64, 32, 128) # features are normalized from 0 to 1\n\nloss = diffusion(training_seq)\nloss.backward()\n\n# Or using trainer\n\ndataset = Dataset1D(training_seq)  # this is just an example, but you can formulate your own Dataset and pass it into the `Trainer1D` below\n\ntrainer = Trainer1D(\n    diffusion,\n    dataset = dataset,\n    train_batch_size = 32,\n    train_lr = 8e-5,\n    train_num_steps = 700000,         # total training steps\n    gradient_accumulate_every = 2,    # gradient accumulation steps\n    ema_decay = 0.995,                # exponential moving average decay\n    amp = True,                       # turn on mixed precision\n)\ntrainer.train()\n\n# after a lot of training\n\nsampled_seq = diffusion.sample(batch_size = 4)\nsampled_seq.shape # (4, 32, 128)\n\n```\n\n`Trainer1D` does not evaluate the generated samples in any way since the type of data is not known.\n\nYou could consider adding a suitable metric to the training loop yourself after doing an editable install of this package\n`pip install -e .`.\n\n## Citations\n\n```bibtex\n@inproceedings{NEURIPS2020_4c5bcfec,\n    author      = {Ho, Jonathan and Jain, Ajay and Abbeel, Pieter},\n    booktitle   = {Advances in Neural Information Processing Systems},\n    editor      = {H. Larochelle and M. Ranzato and R. Hadsell and M.F. Balcan and H. Lin},\n    pages       = {6840--6851},\n    publisher   = {Curran Associates, Inc.},\n    title       = {Denoising Diffusion Probabilistic Models},\n    url         = {https:\u002F\u002Fproceedings.neurips.cc\u002Fpaper\u002F2020\u002Ffile\u002F4c5bcfec8584af0d967f1ab10179ca4b-Paper.pdf},\n    volume      = {33},\n    year        = {2020}\n}\n```\n\n```bibtex\n@InProceedings{pmlr-v139-nichol21a,\n    title       = {Improved Denoising Diffusion Probabilistic Models},\n    author      = {Nichol, Alexander Quinn and Dhariwal, Prafulla},\n    booktitle   = {Proceedings of the 38th International Conference on Machine Learning},\n    pages       = {8162--8171},\n    year        = {2021},\n    editor      = {Meila, Marina and Zhang, Tong},\n    volume      = {139},\n    series      = {Proceedings of Machine Learning Research},\n    month       = {18--24 Jul},\n    publisher   = {PMLR},\n    pdf         = {http:\u002F\u002Fproceedings.mlr.press\u002Fv139\u002Fnichol21a\u002Fnichol21a.pdf},\n    url         = {https:\u002F\u002Fproceedings.mlr.press\u002Fv139\u002Fnichol21a.html},\n}\n```\n\n```bibtex\n@inproceedings{kingma2021on,\n    title       = {On Density Estimation with Diffusion Models},\n    author      = {Diederik P Kingma and Tim Salimans and Ben Poole and Jonathan Ho},\n    booktitle   = {Advances in Neural Information Processing Systems},\n    editor      = {A. Beygelzimer and Y. Dauphin and P. Liang and J. Wortman Vaughan},\n    year        = {2021},\n    url         = {https:\u002F\u002Fopenreview.net\u002Fforum?id=2LdBqxc1Yv}\n}\n```\n\n```bibtex\n@article{Karras2022ElucidatingTD,\n    title   = {Elucidating the Design Space of Diffusion-Based Generative Models},\n    author  = {Tero Karras and Miika Aittala and Timo Aila and Samuli Laine},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2206.00364}\n}\n```\n\n```bibtex\n@article{Song2021DenoisingDI,\n    title   = {Denoising Diffusion Implicit Models},\n    author  = {Jiaming Song and Chenlin Meng and Stefano Ermon},\n    journal = {ArXiv},\n    year    = {2021},\n    volume  = {abs\u002F2010.02502}\n}\n```\n\n```bibtex\n@misc{chen2022analog,\n    title   = {Analog Bits: Generating Discrete Data using Diffusion Models with Self-Conditioning},\n    author  = {Ting Chen and Ruixiang Zhang and Geoffrey Hinton},\n    year    = {2022},\n    eprint  = {2208.04202},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```\n\n```bibtex\n@article{Salimans2022ProgressiveDF,\n    title   = {Progressive Distillation for Fast Sampling of Diffusion Models},\n    author  = {Tim Salimans and Jonathan Ho},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2202.00512}\n}\n```\n\n```bibtex\n@article{Ho2022ClassifierFreeDG,\n    title   = {Classifier-Free Diffusion Guidance},\n    author  = {Jonathan Ho},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2207.12598}\n}\n```\n\n```bibtex\n@article{Sunkara2022NoMS,\n    title   = {No More Strided Convolutions or Pooling: A New CNN Building Block for Low-Resolution Images and Small Objects},\n    author  = {Raja Sunkara and Tie Luo},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs\u002F2208.03641}\n}\n```\n\n```bibtex\n@inproceedings{Jabri2022ScalableAC,\n    title   = {Scalable Adaptive Computation for Iterative Generation},\n    author  = {A. Jabri and David J. Fleet and Ting Chen},\n    year    = {2022}\n}\n```\n\n```bibtex\n@article{Cheng2022DPMSolverPlusPlus,\n    title   = {DPM-Solver++: Fast Solver for Guided Sampling of Diffusion Probabilistic Models},\n    author  = {Cheng Lu and Yuhao Zhou and Fan Bao and Jianfei Chen and Chongxuan Li and Jun Zhu},\n    journal = {NeuRips 2022 Oral},\n    year    = {2022},\n    volume  = {abs\u002F2211.01095}\n}\n```\n\n```bibtex\n@inproceedings{Hoogeboom2023simpleDE,\n    title   = {simple diffusion: End-to-end diffusion for high resolution images},\n    author  = {Emiel Hoogeboom and Jonathan Heek and Tim Salimans},\n    year    = {2023}\n}\n```\n\n```bibtex\n@misc{https:\u002F\u002Fdoi.org\u002F10.48550\u002Farxiv.2302.01327,\n    doi     = {10.48550\u002FARXIV.2302.01327},\n    url     = {https:\u002F\u002Farxiv.org\u002Fabs\u002F2302.01327},\n    author  = {Kumar, Manoj and Dehghani, Mostafa and Houlsby, Neil},\n    title   = {Dual PatchNorm},\n    publisher = {arXiv},\n    year    = {2023},\n    copyright = {Creative Commons Attribution 4.0 International}\n}\n```\n\n```bibtex\n@inproceedings{Hang2023EfficientDT,\n    title   = {Efficient Diffusion Training via Min-SNR Weighting Strategy},\n    author  = {Tiankai Hang and Shuyang Gu and Chen Li and Jianmin Bao and Dong Chen and Han Hu and Xin Geng and Baining Guo},\n    year    = {2023}\n}\n```\n\n```bibtex\n@misc{Guttenberg2023,\n    author  = {Nicholas Guttenberg},\n    url     = {https:\u002F\u002Fwww.crosslabs.org\u002Fblog\u002Fdiffusion-with-offset-noise}\n}\n```\n\n```bibtex\n@inproceedings{Lin2023CommonDN,\n    title   = {Common Diffusion Noise Schedules and Sample Steps are Flawed},\n    author  = {Shanchuan Lin and Bingchen Liu and Jiashi Li and Xiao Yang},\n    year    = {2023}\n}\n```\n\n```bibtex\n@inproceedings{dao2022flashattention,\n    title   = {Flash{A}ttention: Fast and Memory-Efficient Exact Attention with {IO}-Awareness},\n    author  = {Dao, Tri and Fu, Daniel Y. and Ermon, Stefano and Rudra, Atri and R{\\'e}, Christopher},\n    booktitle = {Advances in Neural Information Processing Systems},\n    year    = {2022}\n}\n```\n\n```bibtex\n@article{Bondarenko2023QuantizableTR,\n    title   = {Quantizable Transformers: Removing Outliers by Helping Attention Heads Do Nothing},\n    author  = {Yelysei Bondarenko and Markus Nagel and Tijmen Blankevoort},\n    journal = {ArXiv},\n    year    = {2023},\n    volume  = {abs\u002F2306.12929},\n    url     = {https:\u002F\u002Fapi.semanticscholar.org\u002FCorpusID:259224568}\n}\n```\n\n```bibtex\n@article{Karras2023AnalyzingAI,\n    title   = {Analyzing and Improving the Training Dynamics of Diffusion Models},\n    author  = {Tero Karras and Miika Aittala and Jaakko Lehtinen and Janne Hellsten and Timo Aila and Samuli Laine},\n    journal = {ArXiv},\n    year    = {2023},\n    volume  = {abs\u002F2312.02696},\n    url     = {https:\u002F\u002Fapi.semanticscholar.org\u002FCorpusID:265659032}\n}\n```\n\n```bibtex\n@article{Li2024ImmiscibleDA,\n    title   = {Immiscible Diffusion: Accelerating Diffusion Training with Noise Assignment},\n    author  = {Yiheng Li and Heyang Jiang and Akio Kodaira and Masayoshi Tomizuka and Kurt Keutzer and Chenfeng Xu},\n    journal = {ArXiv},\n    year    = {2024},\n    volume  = {abs\u002F2406.12303},\n    url     = {https:\u002F\u002Fapi.semanticscholar.org\u002FCorpusID:270562607}\n}\n```\n\n```bibtex\n@article{Chung2024CFGMC,\n    title   = {CFG++: Manifold-constrained Classifier Free Guidance for Diffusion Models},\n    author  = {Hyungjin Chung and Jeongsol Kim and Geon Yeong Park and Hyelin Nam and Jong Chul Ye},\n    journal = {ArXiv},\n    year    = {2024},\n    volume  = {abs\u002F2406.08070},\n    url     = {https:\u002F\u002Fapi.semanticscholar.org\u002FCorpusID:270391454}\n}\n```\n\n```bibtex\n@inproceedings{Sadat2024EliminatingOA,\n    title   = {Eliminating Oversaturation and Artifacts of High Guidance Scales in Diffusion Models},\n    author  = {Seyedmorteza Sadat and Otmar Hilliges and Romann M. Weber},\n    year    = {2024},\n    url     = {https:\u002F\u002Fapi.semanticscholar.org\u002FCorpusID:273098845}\n}\n```\n","该项目实现了基于PyTorch的去噪扩散概率模型，这是一种新的生成模型方法。其核心功能是通过去噪分数匹配来估计数据分布的梯度，并使用Langevin采样从真实分布中进行采样。该模型在某些场景下可能与GANs相媲美。技术特点包括易于使用的API和对Flash Attention的支持，以提高训练效率。适用于需要高质量图像生成的应用场景，如艺术创作、图像修复以及数据增强等任务。",2,"2026-06-11 03:24:21","top_topic"]