Train once, infer forever: Bayesian networks without backend lock-in
BayesFlow trains neural networks to amortize Bayesian inference over repeated simulations, then stays out of your way by running on JAX, PyTorch, or TensorFlow via Keras 3.

What it does
BayesFlow provides a high-level Python API for amortized Bayesian workflows. You train a neural network on simulated data upfront; afterward, the network estimates parameters, compares models, or validates findings on fresh observations instantly—no per-dataset MCMC reruns. It is built for simulation-based inference where the likelihood function is unknown or annoying to write, though traditional statistical models are also fair game. The whole stack sits on Keras 3.
The interesting bit
Version 2 is a ground-up rewrite that replaced its TensorFlow-only foundation with a multi-backend Keras 3 core, so you can point the same workflow at JAX, PyTorch, or TensorFlow depending on which ecosystem you already inhabit. The library also folds in modern generative estimators like diffusion and consistency models alongside more conventional density networks.
Key highlights
- One-shot training amortizes inference across unlimited new datasets.
- Backend flexibility via Keras 3: JAX (currently documented as fastest), PyTorch, or TensorFlow.
- Generative estimators include diffusion and consistency models, not just standard flows.
- Explicitly targets simulation-based inference where closed-form likelihoods do not exist.
- NumFOCUS affiliated, with tutorials covering SIR modeling, Bayesian experimental design, and multimodal data fusion.
Caveats
- Requires installing a separate deep-learning backend; the library will not import without one.
- Backend environment variables can be silently ignored by some IDEs, leading to cryptic import errors unless you set them inside the script itself.
Verdict
A strong candidate if you repeatedly fit Bayesian models to simulated data and want to escape per-dataset MCMC. If your models have tractable likelihoods and your current Stan or PyMC pipeline is already fast enough, this is probably overkill.
Frequently asked
- What is bayesflow-org/bayesflow?
- BayesFlow trains neural networks to amortize Bayesian inference over repeated simulations, then stays out of your way by running on JAX, PyTorch, or TensorFlow via Keras 3.
- Is bayesflow open source?
- Yes — bayesflow-org/bayesflow is open source, released under the MIT license.
- What language is bayesflow written in?
- bayesflow-org/bayesflow is primarily written in Python.
- How popular is bayesflow?
- bayesflow-org/bayesflow has 695 stars on GitHub.
- Where can I find bayesflow?
- bayesflow-org/bayesflow is on GitHub at https://github.com/bayesflow-org/bayesflow.