A collection of generative algorithms and techniques implemented in Python.
This work is part of the Xecs TASTI project, nr. 2022005.
You will need:
python(seepyproject.tomlfor full version)Gituv- a
.secretsfile with the required secrets and credentials - load environment variables from
.env NVIDIA Drivers(mandatory) andCUDA >= 12.1(mandatory if Docker/Apptainer is not used)Weights & Biasesaccount
Clone this repository (requires git ssh keys)
git clone --recursive [email protected]:caetas/GenerativeZoo.git
cd GenerativeZoo
Create the environment and install the dependencies:
uv sync --python3.12
You can activate the environment with:
source .venv/bin/activate
You might be required to run the following command once to setup the automatic activation of the conda environment and the virtualenv:
direnv allow
Feel free to edit the .envrc file if you prefer to activate the environments manually.
You can activate the environment with:
.venv-dev/Scripts/Activate.ps1
Create a .secrets file and add your Weights & Biases API Key:
WANDB_API_KEY = <your-wandb-api-key>
Create the image using the provided Dockerfile
docker build --tag generativezoo .
Or download it from the Hub:
docker pull docker://ocaetas/generativezoo
Then run the script job_docker.sh that will execute main.sh:
cd scripts
bash job_docker.sh
To access the shell, please run:
docker run --rm -it --gpus all --ipc=host --env-file .env -v $(pwd)/:/app/ generativezoo bash
Convert the Docker Image to a .sif file:
apptainer pull generativezoo.sif docker://ocaetas/generativezoo
Then run the script job_apptainer.sh that will execute main.sh:
cd scripts
bash job_apptainer.sh
To access the shell, please run:
apptainer shell --nv --env-file .env --bind $(pwd)/:/app/ generativezoo.sif
Add the flag --nvccli if you are using WSL.
Note: Edit the main.sh script if you want to train a different model.
The listed models are already implemented and fully integrated in the model zoo. Models with 🚀 support Multi-GPU and Mixed Precision training using Accelerate. Models with 📦 support a latent space implementation with the flag --latent.
- Vanilla VAE
Paper|Code1 |Script|Documentation - Conditional VAE
Paper|Code1 |Script|Documentation - Hierarchical VAE
Paper|Code2 |Script|Documentation
- Adversarial VAE
Paper|Code1 |Script|Documentation - DC-GAN
Paper|Code3 |Script|Documentation - Conditional GAN
Paper|Code3 |Script|Documentation - CycleGAN
Paper|Code4 |Script|Documentation - Prescribed GAN
Paper|Code5 |Script|Documentation - Wasserstein GAN with Gradient Penalty
Paper|Code6 |Script|Documentation - VQ-GAN
Paper|Code24 |Script|Documentation
- DDPM🚀📦
Paper|Code7,8,9,21 |Script|Documentation - Conditional DDPM🚀📦
Paper|Code10,21 |Script|Documentation - Diffusion AE
Paper|Code11 |Script|Documentation
- SGM🚀📦
Paper|Code12,21 |Script|Documentation - NCSNv2
Paper|Code13 |Script|Documentation
- GPT
Paper|Code22 |Script|Documentation - MaskGiT
Paper|Code23 |Script|Documentation - PixelCNN
Paper|Code14 |Script|Documentation
- Vanilla Flow
Paper|Code14 |Script|Documentation - RealNVP
Paper|Code15 |Script|Documentation - Glow
Paper|Code16 |Script|Documentation - Flow++
Paper|Code17 |Script|Documentation
- Flow Matching🚀📦
Paper|Code18,21 |Script|Documentation - Conditional Flow Matching🚀📦
Paper|Code18,21 |Script|Documentation - Rectified Flows🚀📦
Paper|Code19 |Script|Documentation
- Stable Diffusion + LoRA🚀
Paper|Code20 |Script|Documentation - ControlNet🚀
Paper|Code20 |Script|Documentation - InstructPix2Pix🚀
Paper|Code20 |Script|Documentation
Accelerate should be configured for your hardware setup using:
accelerate config
The models that support these features should be launched with:
accelerate launch --multi_gpu --mixed_precision=fp16 --num_processes=2 {script_name.py} {--arg1} {--arg2} ...
The following datasets are ready to be used to train and sample from the provided models. They are automatically downloaded when you try to use them for the first time.
- MNIST
Source - FashionMNIST
Source - ChestMNIST++
Source - OctMNIST++
Source - PneumoniaMNIST++
Source - TissueMNIST++
Source
- CIFAR-10
Source - CIFAR-100
Source - SVHN
Source - Places365
Source - DTD
Source - TinyImageNet
SourceMANUAL DOWNLOAD REQUIREDLink - Horse2Zebra
SourceMANUAL DOWNLOAD REQUIREDLink - ImageNet-1k
Source - CelebA
Source
The code examples are setup to use Weights & Biases as a tool to track your training runs. Please refer to the full documentation if required or follow the following steps:
-
Create an account in Weights & Biases
-
If you have installed the requirements you can skip this step. If not, activate the conda environment and the virtualenv and run:
pip install wandb
-
Run the following command and insert you
API keywhen prompted:wandb login
If you want to fully disable Weights & Biases during training, use the flag --no_wandb.
If you want to turn off syncing with the server but want to retain the local copy, run:
wandb offline Full documentation is available here: docs/.
See the Developer guidelines for more information.
Contributions of any kind are welcome. Please read CONTRIBUTING.md for details and the process for submitting pull requests to us.
Please read MODELRULES.md for details on how you should build your models for this repository.
Thank you for improving the security of the project, please see the Security Policy for more information.
This project is licensed under the terms of the CC-BY-4.0 license.
See LICENSE for more details.
All the repositories used to generate this code are mentioned in each of the corresponding files and referenced in Implemented Models:
- PyTorch-VAE
- nvae
- conditional-GAN
- PyTorch-GAN
- PresGANs
- wgan-gp
- minDiffusion
- DenoisingDiffusionProbabilisticModels
- ddim
- Conditional_Diffusion_MNIST
- Generative Models
- SGM Tutorial
- score_sde_pytorch
- uvadlc_notebooks
- real-nvp
- Glow-PyTorch
- flowplusplus
- conditional-flow-matching
- minRF
- diffusers
- guided-diffusion
- nanoGPT
- Halton-MaskGIT
- taming-transformers
If you publish work that uses GenerativeZoo, please cite GenerativeZoo as follows:
@misc{GenerativeZoo,
author = {Francisco Caetano},
title = {A collection of generative algorithms and techniques implemented in Python.},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/caetas/GenerativeZoo}},
year = {2024},
}