Skip to main content

Hackable diffusion

Hackable Diffusion is a modular toolbox written in Jax to experiment and educate around Diffusion modeling.

Philosophy

The core philosophy of this library is hackability. It is designed from the ground up to be modular, composable, and easy to modify, enabling rapid experimentation with new research ideas. Key principles include:

  • Composition over Configuration: Build models and training loops by composing small, well-defined Python objects.
  • Clear Separation of Concerns: The codebase is organized into logical sub-libraries for architecture, corruption, inference, loss, and sampling.
  • Native Multimodality: The library has first-class support for handling multimodal data (e.g., images and text) through a consistent "Nested" component pattern that applies different diffusion parameters to different parts of the data.

Tutorials

The notebooks/ directory contains several tutorials to get you started:

  • 2d_training.ipynb: A minimal example on a 2D toy dataset.
  • mnist.ipynb: Standard image diffusion on MNIST.
  • mnist_discrete.ipynb: An example of discrete diffusion.
  • mnist_multimodal.ipynb: A showcase of the multimodal capabilities, generating images and labels jointly.

Training configs

The kdiff/configs/ directory contains example configurations for training:

  • mnist_unet.py: Standard diffusion training configuration on MNIST.

To run a config locally, create a small launcher script (e.g. train.py):

import os
os.environ["XLA_PYTHON_CLIENT_PREALLOCATE"] = "false"

import multiprocessing
from kauldron import konfig

def main():
    import importlib.util
    spec = importlib.util.spec_from_file_location(
        "config", "kdiff/configs/mnist_unet.py"
    )
    config_module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(config_module)

    cfg = config_module.get_config()
    cfg.workdir = "/tmp/mnist_workdir"
    trainer = konfig.resolve(cfg)
    trainer.train()

if __name__ == "__main__":
    multiprocessing.set_start_method("spawn", force=True)
    main()

Note: XLA_PYTHON_CLIENT_PREALLOCATE=false must be set before importing JAX to prevent GPU memory preallocation conflicts with data loading workers. The if __name__ == "__main__" guard is required for multiprocessing compatibility.

Installation

To install the necessary dependencies, you can use pip with the provided pyproject.toml file:

pip install -e .

To install development dependencies (for running tests), use:

pip install -e .[dev]

This will install libraries such as JAX, Flax, and other utilities required to run the code.

Disclaimer

Copyright 2025 Google LLC
All software is licensed under the Apache License, Version 2.0 (Apache 2.0); you may not use this file except in compliance with the Apache 2.0 license. You may obtain a copy of the Apache 2.0 license at: https://www.apache.org/licenses/LICENSE-2.0 All other materials are licensed under the Creative Commons Attribution 4.0 International License (CC-BY). You may obtain a copy of the CC-BY license at: https://creativecommons.org/licenses/by/4.0/legalcode Unless required by applicable law or agreed to in writing, all software and materials distributed here under the Apache 2.0 or CC-BY licenses are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the licenses for the specific language governing permissions and limitations under those licenses. This is not an official Google product.

Citing Hackable Diffusion

If Hackable Diffusion was helpful for a publication, please cite this repository: (authors are included in the alphabetical order by the last name)

@software{hackable_diffusion2026github,
  author = {Crepy, Clement and De Bortoli, Valentin and Galashov, Alexandre and Greff, Klaus and Korshunova, Ira},
  title = {{Hackable Diffusion}: A modular toolbox written in Jax to experiment and educate around Diffusion modeling.},
  url = {https://github.com/google/hackable_diffusion},
  version = {1.0.1},
  year = {2026},
  note = {Authors listed in alphabetical order by the last name},
}

This is not an officially supported Google product.

Metadata

Release files for hackable-diffusion 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hackable-diffusion 1.0.1
File Size Uploaded Provenance Actions
hackable_diffusion-1.0.1.tar.gz 3.8 MB Without provenance Details for hackable_diffusion-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hackable-diffusion 1.0.1
File Interpreter ABI Platform Actions
hackable_diffusion-1.0.1-py3-none-any.whl Python 3 none any Details for hackable_diffusion-1.0.1-py3-none-any.whl

Total release size: 7.7 MB

Release files / hackable_diffusion-1.0.1.tar.gz

Download URL hackable_diffusion-1.0.1.tar.gz
Size 3.8 MB
Tags Source
SHA-256 checksum
How to use checksums
900910626fb68f60c683740df36765ee5a375efb4d3e279401e27404076f037e
BLAKE2b-256 checksum
How to use checksums
81fb219affe0638c0f8476d8e451a838e6dcf377bc930189b82ed82cc0b05aa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / hackable_diffusion-1.0.1-py3-none-any.whl

Download URL hackable_diffusion-1.0.1-py3-none-any.whl
Size 3.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f79c0f10b6c16978ac038becb66c92f7d03750032f8f95aef3d92a8bd697a16c
BLAKE2b-256 checksum
How to use checksums
dbc60a1fc498fd7a2743d3cc2b0adcc464c310c73098471a24a1321469fd6366
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for hackable-diffusion 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page