Amortized inference

On this page 7

Amortized inference is an approach to approximate Bayesian inference in which a learned function, usually a neural network, maps each observation directly to the parameters of an approximate posterior distribution, instead of solving a separate optimization or sampling problem for every data point. In probabilistic models with latent variables, it spreads the cost of inference over a one-time training phase, so later queries cost only a single forward pass.

The idea underlies the variational autoencoder, modern simulation-based inference and many deep generative models. Its central trade-off is speed against fidelity: the shared network is fast, but it may produce less accurate posteriors than inference tuned to each data point.

How amortized inference replaces per-datapoint optimization

Amortized inference works by learning the inference procedure itself. In classical variational inference, each observation x receives its own variational parameters, which are optimized separately until the evidence lower bound stops improving. With N observations, that means N independent optimization problems.

An amortized method instead trains an inference network, also called an encoder or recognition model, with shared weights phi. Given x, the network outputs the parameters of q(z | x), for example the mean and variance of a Gaussian. Training maximizes the expected ELBO across the dataset, typically with stochastic gradients and the reparameterization trick.

The table below contrasts the two regimes on the properties that matter most in practice.

PropertyPer-datapoint inferenceAmortized inference
ParametersOne set per observationOne shared network
Cost for a new observationFull optimization runOne forward pass
Memory growthLinear in dataset sizeConstant in dataset size
Posterior accuracyBest achievable within the familyLimited by network capacity
GeneralizationNone to unseen dataApplies to new observations
Per-datapoint and amortized variational inference

The amortization gap and the approximation gap

The error of an amortized posterior has two distinct components. The approximation gap arises because the variational family, such as a diagonal Gaussian, cannot represent the true posterior exactly. The amortization gap arises because the shared network does not output the best member of that family for each individual observation.

Both gaps lower the ELBO and bias the learned generative model. Empirical studies of variational autoencoders have found that the amortization gap can dominate when the encoder is small or poorly trained, which means that a richer variational family alone does not fix the problem.

Error sourceCauseTypical remedy
Approximation gapVariational family too simpleNormalizing flows, mixtures, full covariance
Amortization gapEncoder cannot fit each posterior wellLarger encoder, semi-amortized refinement
Optimization errorTraining stopped early or unstableLearning rate tuning, warm-up schedules
Posterior collapseDecoder ignores latent variablesKL annealing, free bits, weaker decoder
Sources of inference error and typical remedies

Main families of amortized methods

Amortization appears in several branches of probabilistic modeling, from latent variable models to likelihood-free scientific inference. The ideas share a structure, a network trained once and then reused, but they differ in what the network predicts and how it is trained.

MethodWhat the network outputsTypical use
Helmholtz machine and wake-sleepApproximate posterior over hidden unitsEarly unsupervised learning
Variational autoencoderGaussian posterior parametersRepresentation learning, generation
Semi-amortized inferenceInitialization refined by gradient stepsReducing the amortization gap
Iterative amortized inferenceLearned updates to posterior parametersSequential and hierarchical models
Neural posterior estimationConditional density of parametersSimulation-based scientific inference
Amortized importance samplingProposal distributionProbabilistic programming
Representative amortized inference methods

In simulation-based inference, the model is a simulator with no tractable likelihood. A conditional density estimator, often a conditional normalizing flow, is trained on simulated pairs of parameters and data and then returns a posterior for real observations within milliseconds.

When amortization pays off in practice

Amortization is worthwhile when many inference queries share one model, so that the training cost is recovered over repeated use. It is less attractive for a single dataset analyzed once, where a dedicated sampler such as Hamiltonian Monte Carlo is often more accurate per unit of effort.

SituationRecommended approachReason
Millions of observations, one modelAmortized variational inferenceConstant cost per new observation
Real-time inference requirementAmortized encoderForward pass fits latency budgets
Single dataset, high-stakes estimatesMCMC or per-datapoint VIHigher posterior accuracy
Expensive simulator, many experimentsNeural posterior estimationSimulation budget is reused
Accuracy and speed both criticalSemi-amortized inferenceFast start plus local refinement
Choosing between amortized and non-amortized inference

Limitations and failure modes

The most serious limitation is poor behavior outside the training distribution. An encoder trained on one population of observations can return confident but wrong posteriors for unusual inputs, and nothing in a single forward pass signals the failure.

Practitioners therefore treat an amortized posterior as a fast first estimate that must be validated. Common safeguards include comparing a sample of encoder outputs with per-datapoint optimization, measuring the gap between amortized and refined ELBO values, and flagging inputs whose features lie far from the training data. When the gap is large, a few gradient steps started from the encoder output often recover most of the lost accuracy at modest cost.

  • Overconfident posteriors: Gaussian encoders often underestimate variance, which weakens uncertainty quantification.
  • Miscalibration in simulation-based inference: coverage tests such as simulation-based calibration should be run before trusting results.
  • Hidden amortization gap: a good average ELBO can mask poor posteriors for specific data points.
  • Retraining cost: any change to the prior or likelihood usually requires training the network again.

A plain-language summary

Many statistical models need to work out hidden causes from what they observe. Doing this from scratch for every new observation is slow.

Amortized inference trains a network once to make that guess instantly. It is like an experienced doctor who has seen thousands of patients. The doctor does not run a new study for each patient. Years of practice let the doctor form a good first judgment in seconds.

The price is that quick guesses are sometimes less precise. Careful checking still matters for unusual cases.

An example from practice

An astrophysics team studies gravitational-wave signals from merging black holes. Their physical simulator produces realistic signals, but estimating the masses and spins behind one real detection with standard sampling can take many hours of computation.

The team generates several million simulated signals with known parameters and trains a conditional normalizing flow that maps a signal to a posterior over the source parameters. Training takes several days on GPUs. After that, each new detection receives a full posterior in well under a minute.

Before relying on the network, the team runs calibration tests on held-out simulations and compares selected events with a traditional sampler. The result is rapid parameter estimates for alerts to telescope operators, with slower reference analyses reserved for the most unusual events.