TL;DR
The authors introduce posteriors, a new PyTorch-based library designed to make Bayesian learning accessible and scalable for large-scale machine learning, including Large Language Models (LLMs). By unifying optimization and sampling into a single "tempered" framework, the library allows researchers to easily swap between standard training and Bayesian inference to achieve better generalization, robust online learning, and superior uncertainty quantification.
The Challenge of Modern Bayesian Deep Learning
While Bayesian learning is theoretically superior for handling uncertainty and preventing overfitting, it has historically struggled to scale to the "modern" regime of deep learning—characterized by millions or billions of parameters and massive datasets. Standard Bayesian tools are often too slow, difficult to integrate with existing PyTorch or Hugging Face pipelines, or restricted to small-scale problems.
This gap often forces practitioners to rely on point-estimate optimization (like Stochastic Gradient Descent, SGD). Unfortunately, point estimates can lead to "catastrophic forgetting" in continual learning and overconfident, incorrect predictions when faced with out-of-distribution (OOD) data. The paper addresses this by providing a library that is "minibatch-first" and functionally compatible with the modern ML ecosystem.
Methods: The posteriors Library
The core of the paper is the posteriors library, which adopts a functional, extensible approach. Key methodological contributions include:
- Tempered SGMCMC Framework: The authors formalize Stochastic Gradient Markov Chain Monte Carlo (SGMCMC) using a temperature parameter $T$. This elegantly shows that standard optimization (SGD) is simply the "low-temperature" limit ($T \to 0$) of Bayesian sampling.
- Bayesian Deep Ensembles: They unveil a minor but critical modification to standard deep ensembles. By adding a specific amount of noise during training, they transform a standard ensemble into a "parallel SGMCMC" that is asymptotically unbiased for the true Bayesian posterior.
- Scalable Approximations: The library supports a variety of methods including Laplace approximations (using Empirical Fisher or Generalized Gauss-Newton matrices), Variational Inference (VI), and various SGMCMC flavors (SGLD, SGHMC, SGNHT).
Key Insights
- Optimization and Sampling are Two Sides of the Same Coin: By framing both as part of a tempered Stochastic Differential Equation (SDE), the library allows users to transition seamlessly from training a model to sampling from its posterior with minimal code changes.
- The "Cold Posterior" Might Be an Artifact: The authors find that the "cold posterior effect" (where models perform better when the posterior is artificially sharpened) is prominent in Gaussian approximations like Laplace or VI, but nearly disappears in non-Gaussian SGMCMC. This suggests the effect may be a result of crude approximations rather than a flaw in Bayesian theory itself.
- Deep Ensembles Can Be "Fixed": Standard deep ensembles find different modes but lack "within-mode" uncertainty. Parallel SGMCMC provides the best of both worlds, capturing both diverse modes and local uncertainty.
Experiments and Results
The authors evaluate their library across several diverse tasks, demonstrating its versatility and scale:
- Mitigating Catastrophic Forgetting (PG19 Dataset): In a continual learning task with Llama 2 (7B) reading sequential books, the Laplace approximation maintained low loss across tasks. In contrast, standard SGD quickly "forgot" previous books as it moved to new ones.
- Superior OOD Detection (TQA Dataset): Using parallel SGHMC on Llama 3 (8B), the authors achieved an AUROC of 0.95 for detecting out-of-distribution language (Samoan vs. English text), significantly outperforming standard SGD (0.80).
- Uncertainty Decomposition: They demonstrate that epistemic uncertainty (uncertainty in the model parameters) is a much clearer indicator of OOD data than total uncertainty, which can be muddied by natural data noise (aleatoric uncertainty).
- Competitive Performance (Pima Indians Diabetes): On smaller benchmarks, posteriors matched the accuracy of gold-standard NUTS samplers (like Pyro) while offering significant speedups through parallelization and minibatching.
- Investigating the Cold Posterior Effect (IMDB): Used a CNN-LSTM model to show the divergence in performance between Gaussian approximations and SGMCMC at varying temperatures.
Limitations and Future Work
- Model-Aware Techniques: Currently, the library does not support techniques like K-FAC (Kronecker-factored Approximate Curvature), which are highly efficient for certain neural network architectures. The authors identify this as a high priority for future development.
- Memory Constraints: Storing large ensembles of models (required for SGMCMC and deep ensembles) remains a memory bottleneck for the very largest models, though the library provides sub-spacing tools to help mitigate this.
- Convergence Diagnostics: While the library composes well with Pyro for diagnostics, it does not yet host its own suite of MCMC convergence checks.
Summary updated