AI Glossary / Probabilistic machine learning / Advanced
Amortized variational inference
Definition
Amortized variational inference learns a shared function that maps observations or other relevant context to parameters of approximate posterior distributions. Instead of separately solving an optimization problem from scratch for every case, it reuses this learned inference procedure. The cost of learning the function is spread across many subsequent inference tasks, which is the sense in which inference is amortized.
What it means
A probabilistic model describes how observed data might arise from hidden variables. Inferring those variables often requires a posterior distribution that is difficult to compute exactly. Variational inference replaces that distribution with a tractable approximation.
With amortization, a shared model predicts the approximation's parameters. For example, it may output a mean and variance for each observation. Different inputs can produce different distributions even though the same function processes them. Sharing an inference function does not mean assigning every observation the same posterior, and producing a distribution does not make that distribution exact.
How it works
An inference model, often a neural network, receives an input and outputs valid parameters for a chosen variational family. Training commonly maximizes an evidence lower bound, or ELBO, across observations. In a variational autoencoder, this inference model is trained alongside a generative model.
For a fixed generative model and observation, the gap between log evidence and the ELBO can be decomposed into an approximation gap and an amortization gap. The first reflects limitations of the variational family; the second compares the shared model's result with the best member of that family for that observation.
The inference function must receive sufficient context for the task. Adding capacity alone cannot necessarily repair an input representation that omits information needed for the posterior approximation.
Three practical examples
- An image model uses an encoder to produce a latent Gaussian distribution for each image. Repeated inference uses the shared encoder rather than a new optimization run for every image.
- A document model estimates hidden topic-related variables from observed text. The team compares fast shared inference with more expensive local refinement on selected documents.
- A simulation-based research workflow trains an inference function across many generated observations. Evaluation checks performance on new observations and on settings that differ from those represented during training.
Think of it this way
Think of training an experienced estimator to handle a recurring class of problems. Initial practice is expensive, but familiar cases can then be processed quickly. The estimator may still make systematic errors, especially on unfamiliar cases, and its standard answer format may itself be too limited to express the right answer.
Worked example
Consider an original teaching example for one fixed observation. Suppose its true posterior is a normal distribution with mean two and variance one. Restrict the variational family to normal distributions with any mean m but fixed variance four. Write N(m,4), using the second argument for variance rather than standard deviation.
The reverse KL divergence from N(m,4) to N(2,1) is one half of [4 + (m − 2)² − 1 − log(4)], using natural logarithms. The best mean in this family is two, because the squared term is minimized at zero.
The approximation gap is therefore 0.5 × [3 − log(4)], approximately 0.80685. It remains positive even at the best mean because the family cannot represent variance one.
Now suppose the shared inference function outputs mean three. Its divergence is 0.5 × [4 − log(4)], approximately 1.30685. The amortization gap is the difference, 1.30685 − 0.80685 = 0.5. The total gap equals approximation gap plus amortization gap.
Refining the mean from three to two removes the latter gap but leaves the variance mismatch. Expanding the family to permit variance one could remove that restriction, although successful optimization would still be required. These are exact calculations for stipulated distributions, not evidence that a trained system will achieve either optimum.
Illustrative case study
Fictional document-analysis company LatentLedger builds a shared inference model for a probabilistic document representation. Processing is fast, but unusual technical documents produce less satisfactory approximations than ordinary correspondence. The team investigates whether the inference model, the variational family, or missing context explains the problem.
For selected cases, it holds the generative model fixed and compares the encoder output with local optimization within the same family. Improvement shows room for better inference on those cases; remaining error motivates a separate investigation of the approximation family. This fictional scenario illustrates diagnosis and reports no measured deployment result or guaranteed solution.
Common misconceptions and mistakes
Amortization is not automatically exact inference, and a larger encoder does not necessarily eliminate every gap. The best distribution in a restricted family may still differ substantially from the posterior. Conversely, making the family more expressive does not guarantee that the inference network will find its best parameters.
Another mistake is comparing gap estimates after changing the generative model without acknowledging that the target posterior changed too. Empirical local optimization may also fail to reach the family optimum, so its result is not automatically the exact approximation gap. Training cost, inference cost, and approximation quality should be reported separately.
Business use
This approach can be useful when many related inference requests justify an upfront training investment. Evaluate the full cost over the expected workload, including retraining and monitoring, rather than measuring one fast forward pass alone. Use held-out cases that reflect the intended operating conditions, and compare important uncertainty summaries with a stronger reference where feasible. Consider selective refinement for difficult cases when latency permits and the additional computation improves decision-relevant accuracy.
People also ask
Does it require a neural network?
No. The defining feature is a shared learned inference function, although neural networks are common.
Is it the same as variational inference?
It is a way to share the work of variational inference across cases, rather than a synonym for the entire field.
Can local optimization follow the shared prediction?
Yes. Hybrid or semi-amortized approaches can use the prediction as a starting point for refinement.
Check your understanding
Why is the worked example's approximation gap positive?
Answer: Its family fixes variance at four, while the posterior variance is one.
What creates the additional gap of 0.5?
Answer: The inference function returns mean three instead of the family-optimal mean two.
Would merely refining the mean make inference exact?
Answer: No; the restricted variance would still be wrong.
Related terms
- Variational autoencoder
- Variational inference
- inference network
- recognition model
- evidence lower bound
- approximation gap
- amortization gap
- semi-amortized inference
Learn next
Study the ELBO identity and the difference between model parameters and variational parameters. Then compare improving an inference network, enriching a variational family, and refining individual cases as distinct ways to address inference error.
More in Probabilistic machine learning
- Adaptive resampling - Adaptive resampling, in sequential Monte Carlo and particle filtering, means deciding whether to resample a population of weighted particles using its...
- Advantage actor-critic - Advantage actor-critic is a reinforcement-learning approach in which an actor learns a policy and a critic helps estimate whether an action performed better...
- Alpha divergence - Alpha divergence is a parameterized family of measures for comparing probability distributions. Changing alpha changes how discrepancies are penalized.
- Annealed importance sampling - Annealed importance sampling, or AIS, estimates quantities associated with a difficult probability distribution by moving through a sequence of intermediate...
- ARD kernel - An ARD kernel is a covariance function with separate relevance-related parameters for different input dimensions.
- Asymptotic normality of the maximum likelihood estimator - Asymptotic normality of the maximum likelihood estimator is a large-sample result stating that, under suitable conditions, the estimator's centered and...
Sources
Cremer, Li and Duvenaud, Inference Suboptimality in Variational Autoencoders, 2018: https://proceedings.mlr.press/v80/cremer18a/cremer18a.pdf Margossian and Blei, Amortized Variational Inference: When and Why?, 2024, author abstract: https://proceedings.mlr.press/v244/margossian24a.html
Previous: Amorphous computing Next: Amplification Bias