File size: 2,845 Bytes
256c9c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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.*