When a posterior distribution cannot be sampled or evaluated directly, variational inference uses an approximating distribution and shifts it toward the target. KL divergence quantifies how differently the two distributions behave. section 5.2.3
In the variational autoencoder workflow:
- The guide represents Q(Z|X, is-handwritten, digit), approximating P(Z|image, is-handwritten, digit). section 5.2.3
- Training minimizes KL divergence between Q and P as part of the negative ELBO objective. section 5.2.3
- Stochastic variational inference performs this optimization on randomly selected data batches. section 5.2.3
Listing 5.13 Set up the training procedure
from pyro.infer import SVI, Trace_ELBO
from pyro.optim import Adam
pyro.clear_param_store() #1
vae = VAE() #2
train_loader, test_loader = setup_dataloaders(batch_size=256) #3
svi_adam = Adam({"lr": 1.0e-3}) #4
model = vae.training_model #5
guide = vae.training_guide #5
svi = SVI(model, guide, svi_adam, loss=Trace_ELBO()) #5
A Pyro setup connects the divergence objective to SVI, Adam optimization, and Trace_ELBO. section 5.2.3











