MCPcopy Index your code
hub / github.com/crowsonkb/k-diffusion

github.com/crowsonkb/k-diffusion @v0.1.1.post1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.1.post1 ↗ · + Follow
344 symbols 794 edges 20 files 68 documented · 20% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

k-diffusion

An implementation of Elucidating the Design Space of Diffusion-Based Generative Models (Karras et al., 2022) for PyTorch, with enhancements and additional features, such as improved sampling algorithms and transformer-based diffusion models.

Installation

k-diffusion can be installed via PyPI (pip install k-diffusion) but it will not include training and inference scripts, only library code that others can depend on. To run the training and inference scripts, clone this repository and run pip install -e <path to repository>.

Training

To train models:

$ ./train.py --config CONFIG_FILE --name RUN_NAME

For instance, to train a model on MNIST:

$ ./train.py --config configs/config_mnist_transformer.json --name RUN_NAME

The configuration file allows you to specify the dataset type. Currently supported types are "imagefolder" (finds all images in that folder and its subfolders, recursively), "cifar10" (CIFAR-10), and "mnist" (MNIST). "huggingface" Hugging Face Datasets is also supported.

Multi-GPU and multi-node training is supported with Hugging Face Accelerate. You can configure Accelerate by running:

$ accelerate config

then running:

$ accelerate launch train.py --config CONFIG_FILE --name RUN_NAME

Enhancements/additional features

  • k-diffusion has support for training transformer-based diffusion models (like DiT but improved).

  • k-diffusion supports a soft version of Min-SNR loss weighting for improved training at high resolutions with less hyperparameters than the loss weighting used in Karras et al. (2022).

  • k-diffusion has wrappers for v-diffusion-pytorch, OpenAI diffusion, and CompVis diffusion models allowing them to be used with its samplers and ODE/SDE.

  • k-diffusion implements DPM-Solver, which produces higher quality samples at the same number of function evalutions as Karras Algorithm 2, as well as supporting adaptive step size control. DPM-Solver++(2S) and (2M) are implemented now too for improved quality with low numbers of steps.

  • k-diffusion supports CLIP guided sampling from unconditional diffusion models (see sample_clip_guided.py).

  • k-diffusion supports log likelihood calculation (not a variational lower bound) for native models and all wrapped models.

  • k-diffusion can calculate, during training, the FID and KID vs the training set.

  • k-diffusion can calculate, during training, the gradient noise scale (1 / SNR), from An Empirical Model of Large-Batch Training, https://arxiv.org/abs/1812.06162).

To do

  • Latent diffusion

Core symbols most depended-on inside this repo

sigma
called by 29
k_diffusion/sampling.py
to_d
called by 12
k_diffusion/sampling.py
load_state_dict
called by 10
k_diffusion/utils.py
write
called by 10
k_diffusion/utils.py
eps
called by 8
k_diffusion/sampling.py
state_dict
called by 7
k_diffusion/utils.py
get_ancestral_step
called by 7
k_diffusion/sampling.py
apply_wd
called by 7
k_diffusion/models/image_transformer_v1.py

Shape

Method 173
Function 112
Class 59

Languages

Python100%

Modules by API surface

k_diffusion/models/image_transformer_v1.py53 symbols
k_diffusion/utils.py51 symbols
k_diffusion/layers.py47 symbols
k_diffusion/sampling.py46 symbols
k_diffusion/external.py35 symbols
k_diffusion/evaluation.py20 symbols
k_diffusion/models/image_v1.py18 symbols
k_diffusion/models/axial_rope.py14 symbols
k_diffusion/gns.py13 symbols
k_diffusion/augmentation.py12 symbols
sample_clip_guided.py9 symbols
train.py8 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add k-diffusion \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page