This is the official implementation of the paper
Artem Lukoianov 1, Β Chenyang Yuan 2, Β Justin Solomon 1, Β Vincent Sitzmann 1
1 Massachusetts Institute of Technology,Β 2 Toyota Research Institute
For any questions please shoot an email to [email protected]
[NOTE:] π Help us improve! We've noticed inconsistent generation on MacOS -- check current issues. If you encounter any bugs, inconsistent behavior, or have suggestions, please open an issue. Your feedback is valuable!
The repository implements several analytical diffusion models:
pca_locality(Main method): Our proposed analytical denoiser that captures locality from data statistics.optimal: The theoretically optimal denoiser (reproduces training images).wiener: Wiener filter-based denoiser.nearest_dataset: Baseline that retrieves the nearest dataset image at each step.
Supported datasets:
mnist: MNIST handwritten digitsfashion_mnist: Fashion-MNISTcifar10: CIFAR-10celeba_hq: CelebA-HQafhq: AFHQv2
Most datasets auto-download.
For celeba_hq and afhq, so please download them manually and place data in data/datasets/.
- Python 3.9 or higher
- uv package manager.
- [Recommended] CUDA-capable GPU -- if you dont have it, make sure to change the device in the config to CPU/MPS
No manual setup required! Just use uv run directly.
Alternative: Manual installation
If you prefer to set up the environment manually:
uv venv
source .venv/bin/activate # On Linux/Mac (.venv\Scripts\activate on Windows)
uv pip install -e .First we need to run this script to download the weights of the UNET models pre-trained for all of the baseline datasets.
It
You can skip this step, but then the metrics wont be available -- make sure to disable baseline_path in the config.
uv run download_baseline_weights.pyNow, run the command below to generate images with our analytical model. UV will automatically create the virtual environment and install all dependencies (including the package in editable mode):
uv run generate.py --config configs/pca_locality/celeba_hq.yamlThe config path can be:
- Relative to
configs/directory:pca_locality/celeba_hq.yaml - Absolute path:
/path/to/config.yaml
Run all baseline-dataset combinations using the provided script:
./run_all_baselines.shThis script iterates over:
- Baselines:
pca_locality,optimal,wiener,nearest_dataset - Datasets:
afhq,celeba_hq,cifar10,fashion_mnist,mnist
It automatically skips missing config files and runs each experiment sequentially.
For quick experimentation, you can use the Jupyter notebook: playground.ipynb
Configuration files use YAML format with OmegaConf's defaults feature for inheritance. Each config inherits from configs/defaults.yaml and can override specific values.
A typical config file (configs/pca_locality/celeba_hq.yaml) looks like:
defaults:
- /defaults.yaml
# Run metadata: name, seed, device, tags
experiment:
run_name: pca_locality_celeba_hq # Name of the run - overwritten in each individual config file
tags: [baseline, pca_locality, celeba_hq] # Tags for experiment organization
seed: 42 # Random seed for reproducibility
device: cuda # Device to run on (cuda/cpu/mps)
# Dataset configuration: name, split, resolution, batch size
dataset:
name: celeba_hq # Dataset name (mnist, cifar10, celeba_hq, afhq, fashion_mnist)
split: train # Dataset split to use
download: false # Whether to auto-download (set false for manual downloads)
batch_size: 256 # Batch size for dataset loading
resolution: 64 # Image resolution (overrides default if specified)
# Model selection and hyperparameters
# Available models: pca_locality, optimal, wiener, nearest_dataset
model:
name: pca_locality # Model to use
params:
temperature: 1.0 # Temperature parameter for softmax weighting
mask_threshold: 0.02 # Threshold for mask binarization
# Generation parameters: number of samples, inference steps
sampling:
num_samples: 8 # Total number of samples to generate
batch_size: 8 # Batch size for generation
num_inference_steps: 10 # Number of diffusion steps
# Output and logging settings: WandB, file saving
metrics:
baseline_path: "data/models/baseline_unet/celeba_hq/ckpt_epoch_200.pt" # Path to baseline UNet checkpoint for comparison
output:
save_final_images: true # Save individual sample images
save_image_grid: true # Save grid of all samples
save_intermediate_images: true # Save intermediate diffusion steps
wandb:
enabled: true # Enable Weights & Biases logging
project: locality-diffusion # WandB project nameYou can override any config value from the command line using dot notation:
uv run generate.py --config configs/pca_locality/celeba_hq.yaml \
sampling.num_samples=16 \
model.params.temperature=0.5\
experiment.device=cpuEach experiment creates a run directory with the following structure:
data/runs/{experiment_name}/{run_name}_{optional:timestamp}/
βββ config.yaml # Saved configuration
βββ grid.png # Grid of generated samples
βββ metrics.json # Computed metrics
βββ logs/
β βββ generate.log # Execution log
βββ artifacts/
β βββ images/ # Individual sample images
β β βββ sample_0000.png
β βββ intermediate_images/ # Intermediate diffusion steps
β β βββ x_t/ # Noisy images at each step
β β βββ x0_pred/ # Predicted clean images at each step
β βββ comparison/ # Comparison grids (if baseline_path set)
βββ code_snapshot/ # Git-tracked code snapshot
WandB logging is enabled by default. Using WandB is convinient for studying generation results, but can slowdown the runs. To disable or configure:
metrics:
wandb:
enabled: false # Disable WandB
mode: offline # Use offline mode
project: my-projectWe welcome contributions to this repository! Here are some ways you can help:
If you encounter bugs or have suggestions for improvements, please open an issue on GitHub. When reporting bugs, please include:
- A clear description of the problem
- Steps to reproduce the issue
- Your environment details (Python version, OS, etc.)
- Relevant error messages or logs
- Fork the repository and create a new branch for your changes
- Follow the code style: The project uses standard Python conventions. Ensure your code is well-documented and follows the existing patterns
- Add tests if applicable (though the current codebase focuses on reproducibility of paper results)
- Update documentation if you add new features or change existing behavior
- Submit a pull request with a clear description of your changes
To add a new analytical diffusion model:
- Create a new file in
src/local_diffusion/models/implementing theBaseDenoiserinterface - Register your model using the
@register_model("model_name")decorator - Add configuration files in
configs/model_name/for each dataset - Update this README to document your model
The project follows a structured layout:
locality-in-diffusion-models/
βββ configs/ # Configuration files
β βββ defaults.yaml # Base configuration with common defaults
β βββ pca_locality/ # Configs for the method proposed in our paper
β βββ optimal/ # Optimal denoiser baseline
β βββ wiener/ # Wiener filter baseline
β βββ nearest_dataset/ # Nearest neighbor baseline
βββ src/
β βββ local_diffusion/ # Main package code
β βββ models/ # Model implementations (pca_locality.py, etc.)
β βββ data/ # Dataset loading utilities
β βββ configuration.py # Config management
β βββ metrics.py # Evaluation metrics
βββ data/ # Data directory (created automatically)
β βββ datasets/ # Dataset storage
β βββ models/ # Precomputed models (Wiener filters, etc.)
β βββ runs/ # Experiment outputs
β βββ wandb/ # Weights & Biases logs
βββ generate.py # Main entry point for experiments
βββ playground.ipynb # Interactive Jupyter notebook for experimentation
βββ run_all_baselines.sh # Batch script to run all experiments
If you find our project useful, please consider citing it:
@inproceedings{lukoianovlocality,
title={Locality in Image Diffusion Models Emerges from Data Statistics},
author={Lukoianov, Artem and Yuan, Chenyang and Solomon, Justin and Sitzmann, Vincent},
booktitle={The Thirty-ninth Annual Conference on Neural Information Processing Systems}
year={2025},
primaryClass={cs.CV},
url={https://locality.lukoianov.com/},
}