Metadata-Version: 2.5
Name: diffusion-model-framework
Version: 1.2.0-rc.3
Project-URL: Documentation, https://www.sachahu.com/docs/diffusion-model-framework/latest/index.html
Project-URL: Repository, https://github.com/sachahu1/Diffusion-Model-Framework
Author-email: Sacha Hu <sachahu@mindsparkai.com>
Requires-Python: <3.13,>=3.10
Requires-Dist: numpy<3,>=2.1.3
Requires-Dist: pillow<12,>=11.0.0
Requires-Dist: torch<3,>=2.5.1
Requires-Dist: torchvision<0.21,>=0.20.1
Requires-Dist: tqdm<5,>=4.66.2
Provides-Extra: evaluation
Requires-Dist: click<9,>=8.1; extra == 'evaluation'
Requires-Dist: hydra-core<2,>=1.3.2; extra == 'evaluation'
Requires-Dist: hydra-zen<1,>=0.14; extra == 'evaluation'
Requires-Dist: torchmetrics[image]<2,>=1.5; extra == 'evaluation'
Provides-Extra: inference
Requires-Dist: click<9,>=8.1; extra == 'inference'
Requires-Dist: hydra-core<2,>=1.3.2; extra == 'inference'
Requires-Dist: hydra-zen<1,>=0.14; extra == 'inference'
Provides-Extra: training
Requires-Dist: click<9,>=8.1; extra == 'training'
Requires-Dist: hydra-core<2,>=1.3.2; extra == 'training'
Requires-Dist: hydra-zen<1,>=0.14; extra == 'training'
Requires-Dist: tensorboard<3,>=2.18.0; extra == 'training'
Requires-Dist: transformers<5,>=4.46.1; extra == 'training'
Description-Content-Type: text/markdown

# Diffusion Model Playground

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/sachahu1/Diffusion-Model-Framework/run-tests.yaml?branch=main&label=Tests)
![GitHub Release](https://img.shields.io/github/v/release/sachahu1/Diffusion-Model-Framework)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/diffusion-model-framework)
![GitHub Repo stars](https://img.shields.io/github/stars/sachahu1/Diffusion-Model-Framework)

This is a simplified framework to train and run diffusion models.
![](https://github.com/sachahu1/Diffusion-Model-Framework/blob/main/assets/sampling-small.gif?raw=true)

## Getting Started
To get started, simply install the python package from PyPI:
```shell
pip install diffusion-model-framework
```
The base install only has what the models and samplers need. Extras add more:

| Extra | Adds | For |
| --- | --- | --- |
| `inference` | click, hydra | the `diffusion-models infer` CLI |
| `training` | `inference` + tensorboard, transformers | training |
| `evaluation` | `inference` + torchmetrics | FID / KID |

```shell
pip install "diffusion-model-framework[inference]"
```
Then, you're ready to start setting up your own training process. For help 
getting started with that, have a look at some of the [examples](https://github.com/sachahu1/Diffusion-Model-Framework/blob/main/examples).

### Installing the package
Thanks to uv, installing this package is very simple and can be done in a single command. Simply run:
```shell
uv sync
```
That's it, the package is installed. Move to the next section to learn how to use this package.

## Conditional generation
A model trained with a `conditioning` config (preset `latent_celeba_f4c4_cond`)
generates faces from a list of attributes typed as text:
```shell
diffusion-models infer checkpoint=<final.pt> attributes="glasses, blond, man, no beard" \
  guidance_scale=3 eta=1.0 steps=100 number_of_images=16 seed=0
```
Terms are separated by commas, semicolons or "and". Prefix a term with `no`, `not`,
`without` or `non-` to ask for its absence (`no glasses`). Attributes you leave out
stay free. A term is either one of the words below or the exact name of a CelebA
attribute (case and `_` vs space do not matter). A misspelt term suggests the
closest ones, and a contradiction (`glasses, no glasses`) is an error.

| Attribute (CelebA name) | Everyday words that select it |
| --- | --- |
| `5_o_Clock_Shadow` | `stubble`, `shadow` |
| `Arched_Eyebrows` | — |
| `Attractive` | `attractive` |
| `Bags_Under_Eyes` | — |
| `Bald` | `bald` |
| `Bangs` | `bangs`, `fringe` |
| `Big_Lips` | — |
| `Big_Nose` | — |
| `Black_Hair` | `black hair`, `dark hair` |
| `Blond_Hair` | `blond`, `blonde`, `blond hair` |
| `Blurry` | `blurry` |
| `Brown_Hair` | `brunette`, `brown hair` |
| `Bushy_Eyebrows` | — |
| `Chubby` | `chubby` |
| `Double_Chin` | — |
| `Eyeglasses` | `glasses`, `spectacles` |
| `Goatee` | `goatee` |
| `Gray_Hair` | `gray hair`, `grey hair`, `gray`, `grey` |
| `Heavy_Makeup` | `makeup` |
| `High_Cheekbones` | — |
| `Male` | `man`, `men`, `boy`, `male`, `woman (absent)`, `women (absent)`, `girl (absent)`, `female (absent)`, `lady (absent)` |
| `Mouth_Slightly_Open` | `open mouth` |
| `Mustache` | `mustache`, `moustache` |
| `Narrow_Eyes` | — |
| `No_Beard` | `beard (absent)`, `bearded (absent)`, `clean shaven`, `shaved` |
| `Oval_Face` | — |
| `Pale_Skin` | `pale` |
| `Pointy_Nose` | — |
| `Receding_Hairline` | — |
| `Rosy_Cheeks` | — |
| `Sideburns` | `sideburns` |
| `Smiling` | `smile`, `smiling` |
| `Straight_Hair` | `straight`, `straight hair` |
| `Wavy_Hair` | `wavy`, `wavy hair` |
| `Wearing_Earrings` | `earrings` |
| `Wearing_Hat` | `hat` |
| `Wearing_Lipstick` | `lipstick` |
| `Wearing_Necklace` | `necklace` |
| `Wearing_Necktie` | `tie`, `necktie` |
| `Young` | `young`, `old (absent)`, `elderly (absent)` |

"Absent" words select the opposite: `woman` is "not `Male`". `No_Beard` is a CelebA
attribute that is set when the face has no beard, so `no beard` selects it and `beard`
asks for its absence. The full list is `diffusion_models.diffusion.conditioning.CELEBA_ATTRIBUTES`.

## Building from source
### Installing uv
This tool uses [uv](https://docs.astral.sh/uv/). If you already have uv installed,
please skip to the next section. Otherwise, run:
```shell
curl -LsSf https://astral.sh/uv/install.sh | sh
```
You can find out more about uv installation [here](https://docs.astral.sh/uv/getting-started/installation/).

That's it, uv is set up.
### Installing and building locally
Installing the package via uv is very simple. Simply run:
```shell
uv sync
```
You can now start using the package to train your diffusion model. For example, try running:
```shell
uv run diffusion-models train diffuser
```

Tab completion for commands, config groups (`model=<TAB>`), presets
(`+config=<TAB>`) and config keys is available for bash, zsh and fish. For bash:
```shell
eval "$(uv run diffusion-models completion bash)"   # add to ~/.bashrc
diffusion-models configs list diffuser               # groups, options, presets
```
Completion reads a cached snapshot of the registered configs (in
`~/.cache/diffusion-models`), rebuilt automatically whenever the code changes, so
it stays fast.

Building a wheel is also possible via:
```shell
uv build
```

## Building the documentation
First you will need to install the dependency group used for documentation.
```shell
uv sync --group documentation
```
Now you can build the documentation using Sphinx by running:
```shell
uv run sphinx-build -M html docs/source/ docs/build
```
