Small portfolio project: train a noise-predicting U-Net on MNIST with a linear beta schedule (DDPM-style), save weights, and generate digits interactively in a second marimo app.
diffusion-mnist-pytorch/
βββ trainingdiffusion.py # Marimo: train DiffUNet, plots, save checkpoint
βββ inferencediffusion.py # Marimo: load weights, DDPM sampling, UI
βββ environment.yml # Conda: Python 3.12
βββ requirements.txt # pip / uv
βββ LICENSE # MIT
βββ README.md
βββ data/ # MNIST (downloaded on first run; gitignored)
Default checkpoint path: trained_diffusion_model.pth (used by both apps).
Conda for Python 3.12; install dependencies into that env (e.g. with uv pip):
conda env create -f environment.yml
conda activate dmnist
uv pip install -r requirements.txtWithout Conda: uv venv --python 3.12 .venv, activate it, then uv pip install -r requirements.txt.
Training (interactive editor):
marimo edit trainingdiffusion.pyOr one-shot: uv run marimo run trainingdiffusion.py
Inference / sampling:
marimo edit inferencediffusion.py| Item | Value |
|---|---|
| Architecture | deepinv.models.DiffUNet, 1β1 channels |
| Input size | 32Γ32 grayscale (resize from MNIST) |
| Schedule | Linear Ξ² from 1eβ4 to 0.02, T = 1000 |
| Objective | MSE on predicted noise |
| Optimizer | Adam, lr = 1eβ4 |
VRAM: Increase or decrease mainly via batch_size and image_size in trainingdiffusion.py (see the configuration cell).
noisy_imgs = (
sqrt_alphas_cumprod[t, None, None, None] * imgs
+ sqrt_one_minus_alphas_cumprod[t, None, None, None] * noise
)MIT. You may replace the copyright line in LICENSE with your name if this is a personal repo.