A Variational Perspective on Generative Flow Networks

Heiko Zimmermann, Fredrik Lindsten, Jan-Willem van de Meent, Christian A. Naesseth

Abstract

Generative flow networks (GFNs) are a class of probabilistic models for sequential sampling of composite objects, proportional to a target distribution that is defined in terms of an energy function or a reward. GFNs are typically trained using a flow matching or trajectory balance objective, which matches forward and backward transition models over trajectories. In this work we introduce a variational objective for training GFNs, which is a convex combination of the reverse- and forward KL divergences, and compare it to the trajectory balance objective when sampling from the forward- and backward model, respectively. We show that, in certain settings, variational inference for GFNs is equivalent to minimizing the trajectory balance objective, in the sense that both methods compute the same score-function gradient. This insight suggests that in these settings, control variates, which are commonly used to reduce the variance of score-function gradient estimates, can also be used with the trajectory balance objective. We evaluate our findings and the performance of the proposed variational objective numerically by comparing it to the trajectory balance objective on two synthetic tasks.

Introduction

Generative Flow Networks (GFNs) have emerged as a powerful framework for sampling complex, composite objects—such as molecules or graphs—with probabilities proportional to a given reward function. Unlike traditional generative models that might output a whole object at once, GFNs construct objects through a sequence of discrete actions. However, training GFNs remains challenging. The standard approach, Trajectory Balance (TB), often suffers from high gradient variance and poor credit assignment, making convergence slow or unstable.

This work addresses these challenges by establishing a formal link between GFN training and classical Variational Inference (VI). By framing GFNs within a variational context, we can leverage a rich history of variance reduction techniques to improve training stability and efficiency.

The GFN Trajectory Framework

GFNs operate by defining a forward policy $P_F$ that constructs an object through a sequence of states $s_0, s_1, \dots, s_n, s_f$. To ensure the model samples according to the desired reward, a backward policy $P_B$ is also defined. The Trajectory Balance objective aims to maintain consistency between these forward and backward paths.

Trajectory structure of a GFN, showing forward and backward transition probabilities across states $s_0$ to $s_f$.

Methods: A Variational Objective for GFNs

We introduce the $\alpha$KL objective, a convex combination of the Reverse KL Divergence (RKL) and the Forward KL Divergence (FKL). RKL is typically used in VI to pull a model toward a target distribution, while FKL is used in maximum likelihood estimation to ensure broad mode coverage.

A key contribution of this research is the proof that the gradient of the Trajectory Balance objective is mathematically equivalent to the score-function gradient of this $\alpha$KL objective. This equivalence allows us to treat GFN training as a variational problem.

Comparison of gradients for KL and Trajectory Balance (TB) objectives under different sampling regimes ($\alpha=0$ for forward, $\alpha=1$ for backward).

Variance Reduction

Since score-function gradients are notoriously noisy, we apply several control variate techniques from the VI literature:

  • Learned Baselines: Neural networks that predict a baseline value to reduce reward variance.
  • Optimal Scalings: Constants that minimize the variance of gradient estimates.
  • Leave-One-Out (LOO) Estimators: Utilizing batch samples to create unbiased baselines.

Key Insights

  • TB is VI in Disguise: The "learned $Z$" (normalizing constant) in the Trajectory Balance objective actually functions as a learned control variate.
  • Unified Framework: This perspective suggests that GFNs aren't a totally new species of model, but rather a specific way of parameterizing and training hierarchical variational models.
  • The Role of $\alpha$: The $\alpha$ parameter allows for a flexible mixture of sampling from the forward model ($\alpha=0$, like standard GFNs) or the backward model ($\alpha=1$, like maximum likelihood).

Experimental Results

The proposed variational approach was tested on synthetic 2D densities (2spirals, 8gaussians) and a $15 \times 15$ Ising model.

  • Equivalence in Practice: On 2D tasks, $\alpha$KL and $\alpha$TB performed nearly identically for $\alpha=0$, validating the theoretical derivation.
  • Robustness: The variational $\alpha$KL objective remained stable even when $\alpha=1$, where standard TB performance often degrades.
  • Convergence Speed: In the Ising model, using optimal vector control variates significantly accelerated early-stage training convergence compared to standard GFN methods.

Conclusion

By bridging the gap between GFNs and Variational Inference, this work provides a more robust theoretical foundation for training sequential generative models. The ability to use standard VI variance reduction "tricks" makes GFNs more practical for complex sampling tasks. Future work may explore more advanced VI techniques, such as Variational Sequential Monte Carlo, to further enhance GFN performance in high-dimensional spaces.

Summary updated

BibTeX
@article{zimmermann2023variational,
  author = {Heiko Zimmermann and Fredrik Lindsten and Jan-Willem van de Meent and Christian A. Naesseth},
  title = {{A Variational Perspective on Generative Flow Networks}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2023},
  url = {https://openreview.net/forum?id=czWsYxYbn1},
}
Figure