Bridging the Gap between Variational Inference and Stochastic Gradient MCMC in Function Space

Mengjing Wu, Junyu Xuan, Jie LuICLR 2025

TL;DR

This paper introduces FVIMC (Functional Variational Inference MCMC), a hybrid framework that performs Bayesian inference for neural networks directly in function space. By alternating between fast variational optimization and flexible stochastic gradient sampling, it captures complex, multi-modal distributions that traditional methods miss, leading to better predictive accuracy and more reliable uncertainty estimates.

The Challenge of Parameter-Space Inference

Bayesian Neural Networks (BNNs) are powerful because they provide a distribution of possible answers rather than a single point estimate, allowing us to quantify "uncertainty." Traditionally, this inference is performed in parameter space (the weights and biases). However, this approach faces severe challenges:

  • Deep models have millions of parameters, creating "pathological" landscapes that are hard to navigate.
  • It is nearly impossible to define a "meaningful" prior for weights that translates into a sensible prior for the actual function the network represents.

To solve this, researchers have recently moved to function-space inference, focusing on the output of the model rather than specific weights. There are two primary methods for this:

  1. Functional Variational Inference (fVI): Fast and computationally efficient, but it imposes rigid assumptions about the shape of the distribution, often leading to underestimated uncertainty.
  2. Functional MCMC (fMCMC): Theoretically exact and highly flexible, but painfully slow to converge (slow "mixing") in high-dimensional spaces.

The authors identify a critical gap: the field needs a method that is as fast as VI but as flexible and "honest" about uncertainty as MCMC.

FVIMC: A Hybrid Approach

The authors propose a novel hybrid approach called FVIMC. It operates through an alternating three-stage process designed to inherit the complementary benefits of both fVI and fMCMC:

  • V-Stage (Variational): The process begins with a quick optimization step (fVI) to push the model toward high-probability regions of the function space. This provides a crucial "warm start."
  • M-Stage (MCMC): It then runs a functional version of Stochastic Gradient Langevin Dynamics (fSGLD). This "shakes" the model, allowing it to explore multiple modes and non-parametric shapes that a simple Gaussian assumption would miss.
  • T-Stage (Transformation): This acts as the "bridge." Because MCMC produces raw, implicit samples and VI requires an explicit mathematical formula, the authors use invertible bijective transformations (like Linear, Tanh, or Sigmoid functions) to map the MCMC samples back into an explicit form for the next V-Stage.

Crucially, the authors provide a theoretical proof using Wasserstein gradient flows, demonstrating that fVI and fMCMC actually follow the same evolutionary path toward the posterior. This ensures that switching between the two methods is mathematically sound.

Key Insights

  • Function Space is the Right Abstraction: By using Gaussian Process (GP) priors in function space, the model can encode high-level properties like "smoothness" or "periodicity" much more effectively than weight-space priors.
  • The Power of Alternating: The V-Stage acts like a scout finding the general area of interest, while the M-Stage acts like a surveyor mapping out the complex terrain. This prevents the "variance collapse" (overconfidence) typical of pure VI.

Key Results

The authors evaluated FVIMC across several diverse benchmarks, including synthetic extrapolation, UCI regression, contextual bandits, and image classification (MNIST/FashionMNIST).

Superior Uncertainty Quantification

In a 1-D synthetic extrapolation task, the goal was to test how well the model handles "unseen" data ranges.

fVI posterior

As seen above, pure functional Variational Inference (fVI) often struggles to capture the true uncertainty in the "gaps" between training data clusters, leading to overconfident or poorly fitted predictions.

FVIMC posterior

In contrast, FVIMC correctly identified high uncertainty in these gaps. The wide uncertainty bands (shaded regions) perfectly encapsulate the true function where data is missing, demonstrating the flexibility gained from the MCMC stage.

Accuracy and Convergence

  • Superior Accuracy: In UCI regression tasks, FVIMC achieved the lowest RMSE in 6 out of 7 datasets compared to both parameter-space and function-space baselines.
  • Faster Convergence: Thanks to the V-Stage "warm start," the MCMC component reached a stationary state much faster than pure fMCMC (e.g., 400 iterations vs. 2000+).
  • OOD Detection: On image datasets, FVIMC showed highly competitive performance in identifying "alien" (Out-of-Distribution) data, outperforming standard BNN baselines.

Limitations and Future Work

While FVIMC represents a significant step forward, it has a few limitations:

  • Transformation Complexity: The auto-selection mechanism for transformations (Linear/Tanh/Sigmoid) relies on relatively simple functions. Future work could explore using more complex Normalizing Flows to bridge the stages.
  • Computational Cost: Although faster than pure MCMC, the hybrid approach remains more computationally expensive than a single MAP estimate or simple VI.
  • Scaling to Large Vision Models: The experiments focused on fully connected networks and smaller image datasets. Testing the scalability of function-space gradients on massive architectures like Transformers remains an open challenge.

Summary updated

BibTeX
@inproceedings{wu2025bridging,
  author = {Mengjing Wu and Junyu Xuan and Jie Lu},
  title = {{Bridging the Gap between Variational Inference and Stochastic Gradient MCMC in Function Space}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=bNVbOS3lrl},
}
Figure