Abstract
With the recent rapid progress in the study of deep generative models (DGMs), there is a need for a framework that can implement them in a simple and generic way. In this research, we focus on two features of DGMs: (1) deep neural networks are encapsulated by probability distributions, and (2) models are designed and learned based on an objective function. Taking these features into account, we propose a new Python library to implement DGMs called Pixyz. This library adopts a step-by-step implementation method with three APIs, which allows us to implement various DGMs more concisely and intuitively. In addition, the library introduces memoization to reduce the cost of duplicate computations in DGMs to speed up the computation. We demonstrate experimentally that this library is faster than existing probabilistic programming languages in training DGMs.
Introduction
Deep Generative Models (DGMs), such as Variational Autoencoders (VAEs) and Generative Adversarial Networks (GANs), have become central to modern machine learning. However, implementing these models cleanly remains a challenge. Existing Probabilistic Programming Languages (PPLs) like Pyro or TensorFlow Probability often struggle with DGMs because they do not always treat deep neural networks (DNNs) as integral components of a probability distribution. Furthermore, many PPLs are optimized for traditional Bayesian inference rather than the end-to-end optimization of complex objective functions required by DGMs. Pixyz addresses these issues by providing a framework specifically designed for the hierarchical nature of deep generative modeling.
System Architecture
Pixyz introduces a "step-by-step" implementation scheme through three hierarchical APIs that separate the concerns of distribution definition, objective function construction, and model training.
- Distribution API: This core layer allows users to define probability distributions where parameters (e.g., mean and variance) are the outputs of PyTorch neural networks. It supports a "product" operator, enabling users to define joint distributions by multiplying conditional distributions (e.g., $p(x, z) = p(x|z)p(z)$).
- Loss API: This layer enables the definition of objective functions as mathematical expressions. Users can write code that directly reflects expectations or KL divergences.
- Model API: This top-level API integrates distributions and loss functions with optimizers to manage the training loop.
Implementation and API Design
A key insight of Pixyz is that code should mirror mathematical notation to improve readability and debuggability. By allowing the multiplication of distribution objects and the direct expression of loss terms, the transition from a graphical model to a working script is nearly seamless.
Beyond API design, Pixyz implements memoization. In models like VAEs, the same inference result is often required for multiple parts of an objective function. Pixyz automatically caches these results using an internal graph management system, preventing redundant forward passes through the neural network and reclaiming performance lost in standard implementations.
Key Results
The authors evaluated Pixyz against standard benchmarks, including MNIST for VAEs and the Polyphonic Music Dataset for Deep Markov Models (DMMs).
- Training Speed: In VAE experiments, Pixyz consistently outperformed Pyro. By utilizing analytical calculations and memoization, Pixyz achieved a 20–26% speed improvement over Pyro. While still slightly slower than "pure" PyTorch due to the abstraction layer, the performance gap remains stable as model complexity increases.
- Conciseness: For complex architectures like the DMM, Pixyz significantly reduced code redundancy. Unlike Pyro, which requires manual variable renaming and complex loops to track samples across time steps, Pixyz handles these operations automatically.
Conclusion
Pixyz provides a powerful, intuitive framework for developing DGMs by aligning code structure with mathematical theory. While currently focused on ancestral sampling and amortized variational inference, future work aims to expand the library to support iterative generative models like Diffusion and Score-based models, as well as traditional Bayesian methods like MCMC.
Summary updated