SVI¶
Stochastic variational inference (SVI) fits a guide by gradient steps on a sampled estimate of a variational objective, such as the evidence lower bound (ELBO), IWAE, Rényi, or VR-IWAE bound (Hoffman et al., 2013; Blei et al., 2017; Pyro Developers, n.d.-g). For a model of a coin's bias, for instance, the guide may be a Beta distribution whose two shape parameters the optimization adjusts. Posterior predictive draws then show which observations the fitted approximation predicts.
svi
¶
Stochastic Variational Inference (SVI) training loop.
SVI optimizes a quivers.inference.objectives.Objective
(the ELBO, IWAE, Rényi, or VR-IWAE bound) by taking gradient
steps on the guide and model parameters. The objective
parameter accepts any Objective subclass.
INITIAL_ATTEMPTS
module-attribute
¶
How many times SVI.run draws the objective of its first step before it
reports a non-finite start, the budget MCMC gives an initial position.
SVI
¶
SVI(model: MonadicProgram, guide: Guide, optim: Optimizer | None, objective: Objective)
Stochastic Variational Inference optimizer.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Generative model.
TYPE:
|
guide
|
Variational guide.
TYPE:
|
optim
|
Optimizer for model and guide parameters. None is valid only when neither has trainable parameters; steps then evaluate the objective without constructing phantom parameters or taking a gradient step.
TYPE:
|
objective
|
Variational objective (ELBO, IWAEBound, RenyiBound, VRIWAEBound, …).
TYPE:
|
Source code in src/quivers/inference/svi.py
step
¶
One SVI step.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Program input. Shape
TYPE:
|
observations
|
Observed variable values + host data (the
non-site keys are exposed to the trace via the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Scalar loss for this step. |
Source code in src/quivers/inference/svi.py
run
¶
run(x: Tensor, observations: Mapping[str, Tensor] | Callable[[int], Mapping[str, Tensor]], *, num_steps: int, callback: Callable[[int, float], None] | None = None) -> tuple[float, ...]
Optimize one posterior and retain its finite loss history.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Model execution input.
TYPE:
|
observations
|
Fixed bindings, or a step-indexed supplier that recomputes differentiable predictors for the current parameter values.
TYPE:
|
num_steps
|
Nonnegative optimization budget. Zero retains initialization without evaluating the objective or updating parameters.
TYPE:
|
callback
|
Receives each zero-based step index and its scalar loss.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, ...]
|
Losses in optimization order. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the budget is invalid or an objective is nonfinite. The first
step's objective is drawn up to |
Source code in src/quivers/inference/svi.py
A parameter-free model and guide may use optim=None. SVI still evaluates the
requested finite objectives and invokes callbacks, but has no gradient update to
perform. The source and formula fitting adapters select this policy when their
combined trainable parameter set is empty; frozen parameters do not create an
optimizer. Omitting the optimizer while trainable parameters exist is an error.
Cited sources¶
Matthew D. Hoffman, David M. Blei, Chong Wang, and John Paisley. Stochastic Variational Inference. Journal of Machine Learning Research, 14(40):1303–1347, 2013. URL: https://www.jmlr.org/papers/v14/hoffman13a.html.
David M. Blei, Alp Kucukelbir, and Jon D. McAuliffe. Variational Inference: A Review for Statisticians. Journal of the American Statistical Association, 112(518):859–877, 2017. URL: https://doi.org/10.1080/01621459.2017.1285773, doi:10.1080/01621459.2017.1285773.
Pyro Developers. SVI part I: an introduction to stochastic variational inference in Pyro. Pyro Tutorials, version 1.9.1, n.d.-g. URL: https://pyro.ai/examples/svi_part_i.html (visited on 2026-11-06).