Welcome to the repository for the Diffusion Models Minicourse presented at the Simpósio Brasileiro de Banco de Dados (SBBD) 2025.
The Diffusion Models Minicourse will be presented at SBBD (Simpósio Brasileiro de Banco de Dados) 2025. This 4-hour session includes a written paper (currently awaiting publication) and a slide-based presentation.
- Published chapter: https://books-sol.sbc.org.br/index.php/sbc/catalog/view/179/791/1547
- Slides: https://docs.google.com/presentation/d/1obWOI-vrOl7_5cF3OsFMdRx_SCOhu-veGGYFOEHgj1o/edit?usp=sharing
The main content of this repository is to provide the hands-on part of the minicourse. You will find practical Jupyter Notebooks that guide you through the implementation and experimentation with diffusion models.
This repository contains three main notebooks:
- From Scratch: Denoising Diffusion Probabilistic Model
- Step-by-step implementation of a denoising diffusion probabilistic model (DDPM) from scratch.
- From Scratch: Score-Based Model
- Step-by-step implementation of a score-based generative model from scratch.
- Inference Implementation with Diffusers
- Practical usage of diffusion models using the Hugging Face
diffusers
library.
- Practical usage of diffusion models using the Hugging Face
- Python: 3.13 or higher
- GPU: CUDA-compatible GPU recommended for faster training (CUDA 12.9 support included)
- Memory: At least 8GB RAM (16GB+ recommended for larger models)
This project uses uv as the package manager for faster and more reliable dependency management.
-
Install uv (if not already installed):
# On Windows (PowerShell) powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" # On macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | sh
-
Clone this repository:
git clone https://github.com/InsightLab/diffusion_models_course.git cd diffusion_models_course
-
Install dependencies:
uv sync
-
Activate the environment:
# On Windows .venv\Scripts\activate # On macOS/Linux source .venv/bin/activate
If you prefer using traditional Python tools:
-
Clone this repository:
git clone https://github.com/InsightLab/diffusion_models_course.git cd diffusion_models_course
-
Create a virtual environment:
python -m venv venv # Activate it # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install PyTorch with CUDA support:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu129
-
Install other dependencies:
pip install matplotlib seaborn tqdm
-
Start Jupyter:
# Make sure your environment is activated jupyter notebook # or jupyter lab
-
Open and run the notebooks:
ddpm_from_scratch.ipynb
- DDPM implementation from scratchncsn_from_scratch.ipynb
- Score-based model from scratchhugging_face_diffusers.ipynb
- High-level inference implementation with Diffusers
-
Follow the instructions in each notebook to run the code and explore diffusion models.
diffusion_models_course/
├── models/ # Model implementations
│ ├── ddpm.py # DDPM model architecture
│ └── ncsn.py # NCSN model architecture
├── weights/ # Pre-trained model weights
├── samples/ # Generated sample images
├── data/ # Dataset storage (MNIST)
├── pyproject.toml # Project metadata and dependencies
└── *.ipynb # Jupyter notebooks
The project is configured to use CUDA 12.9. If you have a different CUDA version or want CPU-only execution:
- For different CUDA versions, modify the PyTorch installation command
- For CPU-only: remove the
--index-url
parameter when installing PyTorch
- CUDA issues: Ensure your GPU drivers are up to date
- Memory issues: Reduce batch sizes in the notebooks if you encounter OOM errors
- uv not found: Make sure uv is properly installed and added to your PATH
See the LICENSE file for details.