# Denoising Diffusion Probabilistic Models (DDPM)

Implementation of [Denoising Diffusion Probabilistic Models](https://arxiv.org/abs/2006.11239) (Ho, Jain, Abbeel, 2020).

## What this implements

The DDPM training and sampling procedure — a class of generative models that learn to reverse a gradual noising process. The core contribution is the training objective (simplified variational bound) and the reverse sampling algorithm, NOT the U-Net architecture (which is adapted from prior work). This implementation covers the forward diffusion process, the simplified training objective (L_simple), the noise schedule, and the reverse sampling algorithm from Algorithm 1 and Algorithm 2.

## Quick start

```bash
pip install -r requirements.txt
```

```python
from src.model import UNet, UNetConfig
from src.loss import DDPMLoss
from src.utils import linear_noise_schedule

config = UNetConfig()
model = UNet(config)
noise_schedule = linear_noise_schedule(timesteps=1000)

# Example: predict noise from noisy image at timestep t
import torch
x_t = torch.randn(2, 3, 32, 32)    # noisy image
t = torch.randint(0, 1000, (2,))    # timesteps
predicted_noise = model(x_t, t)
print(predicted_noise.shape)  # (2, 3, 32, 32)
```

## File structure

```
ddpm/
├── README.md                 # This file
├── REPRODUCTION_NOTES.md     # Ambiguity audit — what's specified vs. assumed
├── requirements.txt          # Dependencies
├── src/
│   ├── model.py              # U-Net noise prediction network (§3.3, Appendix B)
│   ├── loss.py               # DDPM simplified loss L_simple (§3.4, Eq. 14)
│   ├── data.py               # Dataset skeleton for image data
│   ├── train.py              # Training loop — Algorithm 1
│   ├── evaluate.py           # FID score computation
│   └── utils.py              # Noise schedule, forward process, sampling (Algorithm 2)
├── configs/
│   └── base.yaml             # All hyperparameters from §4 and Appendix B
└── notebooks/
    └── walkthrough.ipynb     # Paper sections → code → sanity checks
```

## Important: Read REPRODUCTION_NOTES.md

This implementation flags every choice that the paper does not specify.
Before using this code for research, read [REPRODUCTION_NOTES.md](REPRODUCTION_NOTES.md)
to understand which implementation details are from the paper and which are our choices.

## Citation

```bibtex
@article{ho2020denoising,
  title={Denoising diffusion probabilistic models},
  author={Ho, Jonathan and Jain, Ajay and Abbeel, Pieter},
  journal={Advances in neural information processing systems},
  volume={33},
  pages={6840--6851},
  year={2020}
}
```

---

*Generated by [paper2code](https://github.com/PrathamLearnsToCode/paper2code) — citation-anchored paper implementation.*
