modular-diffusion

Python library for designing and training your own Diffusion Models with PyTorch

https://github.com/cabralpinto/modular-diffusion

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.8%) to scientific vocabulary

Keywords

audio-generation deep-learning diffusion-models image-generation machine-learning modular-design python pytorch text-generation transformer u-net
Last synced: 4 months ago · JSON representation ·

Repository

Python library for designing and training your own Diffusion Models with PyTorch

Basic Info
Statistics
  • Stars: 287
  • Watchers: 8
  • Forks: 14
  • Open Issues: 12
  • Releases: 1
Topics
audio-generation deep-learning diffusion-models image-generation machine-learning modular-design python pytorch text-generation transformer u-net
Created over 2 years ago · Last pushed 7 months ago
Metadata Files
Readme Contributing License Code of conduct Citation

README.md

Modular Diffusion

PyPI version Documentation MIT license Discord

⚠️ This project is currently unmaintained.
I'm no longer able to actively maintain this repository due to other commitments. If you’re interested in taking over as a maintainer and helping the project grow, please open an issue or reach out with a brief overview of your background and interest.

Modular Diffusion provides an easy-to-use modular API to design and train custom Diffusion Models with PyTorch. Whether you're an enthusiast exploring Diffusion Models or a hardcore ML researcher, this framework is for you.

Features

  • ⚙️ Highly Modular Design: Effortlessly swap different components of the diffusion process, including noise type, schedule type, denoising network, and loss function.
  • 📚 Growing Library of Pre-built Modules: Get started right away with our comprehensive selection of pre-built modules.
  • 🔨 Custom Module Creation Made Easy: Craft your own original modules by inheriting from a base class and implementing the required methods.
  • 🤝 Integration with PyTorch: Built on top of PyTorch, Modular Diffusion enables you to develop custom modules using a familiar syntax.
  • 🌈 Broad Range of Applications: From generating high-quality images to implementing non-autoregressive text synthesis pipelines, the possiblities are endless.

Installation

Modular Diffusion officially supports Python 3.10+ and is available on PyPI:

bash pip install modular-diffusion

You also need to install the correct PyTorch distribution for your system.

Note: Although Modular Diffusion works with later Python versions, we currently recommend using Python 3.10. This is because torch.compile, which significantly improves the speed of the models, is not currently available for versions above Python 3.10.

Usage

With Modular Diffusion, you can build and train a custom Diffusion Model in just a few lines. First, load and normalize your dataset. We are using the dog pictures from AFHQ.

python x, _ = zip(*ImageFolder("afhq", ToTensor())) x = resize(x, [h, w], antialias=False) x = torch.stack(x) * 2 - 1

Next, build your custom model using either Modular Diffusion's prebuilt modules or your custom modules.

python model = diffusion.Model( data=Identity(x, batch=128, shuffle=True), schedule=Cosine(steps=1000), noise=Gaussian(parameter="epsilon", variance="fixed"), net=UNet(channels=(1, 64, 128, 256)), loss=Simple(parameter="epsilon"), )

Now, train and sample from the model.

python losses = [*model.train(epochs=400)] z = model.sample(batch=10) z = z[torch.linspace(0, z.shape[0] - 1, 10).long()] z = rearrange(z, "t b c h w -> c (b h) (t w)") save_image((z + 1) / 2, "output.png")

Finally, marvel at the results.

Modular Diffusion teaser 

Check out the Getting Started Guide to learn more and find more examples here.

Contributing

We appreciate your support and welcome your contributions! Please feel free to submit pull requests if you found a bug or typo you want to fix. If you want to contribute a new prebuilt module or feature, please start by opening an issue and discussing it with us. If you don't know where to begin, take a look at the open issues. Please read our Contributing Guide for more details.

License

This project is licensed under the MIT License.

Owner

  • Name: João Cabral Pinto
  • Login: cabralpinto
  • Kind: user

Citation (CITATION.cff)

authors:
  - family-names: Cabral Pinto
    given-names: João
cff-version: 1.2.0
message: "If you use this library, please cite it using these metadata."
title: "Modular Diffusion"

GitHub Events

Total
  • Issues event: 1
  • Watch event: 22
  • Push event: 1
  • Pull request event: 1
  • Fork event: 2
Last Year
  • Issues event: 1
  • Watch event: 22
  • Push event: 1
  • Pull request event: 1
  • Fork event: 2

Issues and Pull Requests

Last synced: 5 months ago

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 68 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 4
  • Total maintainers: 1
pypi.org: modular-diffusion

Modular Diffusion

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 68 Last month
Rankings
Dependent packages count: 7.3%
Average: 29.6%
Forks count: 30.4%
Stargazers count: 39.3%
Dependent repos count: 41.5%
Maintainers (1)
Last synced: 5 months ago