Models¶
This is the heart of Pythae. In here you will find implementations of Autoencoder-based models along with some Normalizing Flows used for improving Variational Inference in the VAE or sampling and Neural Nets to perform benchmark comparison.
Available Autoencoders¶
Base class for Autoencoder based models. |
|
Utils class allowing to reload any |
|
Vanilla Autoencoder model. |
|
Vanilla Variational Autoencoder model. |
|
\(\beta\)-VAE model. |
|
Variational Auto Encoder with linear Normalizing Flows model. |
|
Variational Auto Encoder with Inverse Autoregressive Flows ( |
|
Disentangled \(\beta\)-VAE model. |
|
FactorVAE model. |
|
\(\beta\)-TCVAE model. |
|
Importance Weighted Autoencoder model. |
|
Combination Importance Weighted Autoencoder model. |
|
Multiply Importance Weighted Autoencoder model. |
|
Partially Importance Weighted Autoencoder model. |
|
VAE using perseptual similarity metrics model. |
|
Wasserstein Autoencoder model. |
|
Info Variational Autoencoder model. |
|
Variational Mixture of Posteriors (VAMP) VAE model |
|
\(\mathcal{S}\)-VAE model. |
|
Poincaré Variational Autoencoder model. |
|
Adversarial Autoencoder model. |
|
Variational Autoencoder using Adversarial reconstruction loss model. |
|
Vector Quantized-VAE model. |
|
Hamiltonian VAE. |
|
Regularized Autoencoder with gradient penalty model. |
|
Regularized Autoencoder with L2 decoder params regularization model. |
|
Riemannian Hamiltonian VAE model. |
Available Normalizing Flows¶
Base Class from Normalizing flows |
|
Planar Flow model. |
|
Radial Flow model. |
|
Masked Autoencoder model |
|
Masked Autoregressive Flow. |
|
Inverse Autoregressive Flow. |
|
Pixel CNN model. |
Basic Example¶
To launch a model training, you only need to set up your BaseTrainerConfig
,
BaseAEConfig
build the model and trainer accordingly and then call a TrainingPipeline
instance.
>>> from pythae.pipelines import TrainingPipeline
>>> from pythae.models import VAE, VAEConfig
>>> from pythae.trainers import BaseTrainerConfig
>>> # Set up the training configuration
>>> my_training_config = BaseTrainerConfig(
... output_dir='my_model',
... num_epochs=50,
... learning_rate=1e-3,
... per_device_train_batch_size=200,
... per_device_eval_batch_size=200,
... steps_saving=None,
... optimizer_cls="AdamW",
... optimizer_params={"weight_decay": 0.05, "betas": (0.91, 0.995)},
... scheduler_cls="ReduceLROnPlateau",
... scheduler_params={"patience": 5, "factor": 0.5}
... )
>>> # Set up the model configuration
>>> my_vae_config = model_config = VAEConfig(
... input_dim=(1, 28, 28),
... latent_dim=10
... )
>>> # Build the model
>>> my_vae_model = VAE(
... model_config=my_vae_config
... )
>>> # Build the Pipeline
>>> pipeline = TrainingPipeline(
... training_config=my_training_config,
... model=my_vae_model
... )
>>> # Launch the Pipeline
>>> pipeline(
... train_data=your_train_data, # must be torch.Tensor or np.array
... eval_data=your_eval_data # must be torch.Tensor or np.array
... )
Distributed Training with Pythae¶
As of v0.1.0, Pythae now supports distributed training using PyTorch’s DDP. It allows you to train your favorite VAE faster and on larger dataset using multi-node and/or multi-gpu training.
To do so, you can built a python script that will then be launched by a launcher (such as srun on a cluster). The only thing that is needed in the script is to specify some elements relative to the environment (such as the number of nodes/gpus) directly in the training configuration as follows
>>> training_config = BaseTrainerConfig(
... num_epochs=10,
... learning_rate=1e-3,
... per_device_train_batch_size=64,
... per_device_eval_batch_size=64,
... dist_backend="nccl", # distributed backend
... world_size=8 # number of gpus to use (n_nodes x n_gpus_per_node),
... rank=5 # process/gpu id,
... local_rank=1 # node id,
... master_addr="localhost" # master address,
... master_port="1
See this example script that defines a multi-gpu VQVAE training. Be carefull, the way the environnement (world_size, rank …) may be specific to the cluster and launcher you use.
Benchmark¶
Below are indicated the training times for a Vector Quantized VAE (VQ-VAE) with Pythae for 100 epochs on MNIST on V100 16GB GPU(s), for 50 epochs on FFHQ (1024x1024 images) and for 20 epochs on ImageNet-1k on V100 32GB GPU(s).
Dataset |
Data type (train size) |
1 GPU |
4 GPUs |
2x4 GPUs |
---|---|---|---|---|
MNIST |
28x28 images (50k) |
221.01s |
60.32s |
34.50s |
FFHQ |
1024x1024 RGB images (60k) |
19h 1min |
5h 6min |
2h 37min |
ImageNet-1k |
128x128 RGB images (~ 1.2M) |
6h 25min |
1h 41min |
51min 26s |