Diagnosing Variational Inference (PSIS k-hat and VSBC)
Summary
“While it’s always possible to compute a variational approximation to a posterior distribution, it can be difficult to discover problems with this approximation” (Yao, Vehtari, Simpson & Gelman 2018). The ELBO cannot tell you: it lives on an uninterpretable, parameterization-dependent scale. The paper proposes two complementary checks. PSIS k^: treat q as an importance-sampling proposal for the posterior, fit a generalized Pareto distribution to the largest ratios p(θs,y)/q(θs), and read the shape k^ as a measure of joint discrepancy; k^<0.5 good, 0.5-0.7 usable, >0.7 unreliable. When k^ is small, the same smoothed weights correct the VI estimate. VSBC: a simulation-based-calibration variant that tests whether VI point estimates are unbiased on average over the prior, via the symmetry of calibration-probability histograms.
Overview
There are two levels of VI diagnostics (Sec. 1). The first is convergence of the optimizer to a local optimum, assessed by monitoring ELBO changes or held-out predictive density. The second, the subject of this note, is whether the converged q∗(θ) “is close enough to the true posterior p(θ∣y) to be used in its place.” VI can be flawed through “slow convergence of the optimization problem, the inability of the approximation family to capture the true posterior, the asymmetry of the true distribution, the fact that the direction of the KL divergence under-penalizes approximation with too-light tails, or all these reasons.”
The two diagnostics answer different questions:
PSIS k^
VSBC
Target
the joint approximation, for the observed data set
marginal point estimates, averaged over data sets from the prior predictive
Cost
one VI fit + S joint-density evaluations
M simulated data sets and M VI fits
Passing means
q is a usable importance proposal; VI estimates can be corrected
centre of q is unbiased on average (if model is well specified)
Blind to
modes that q never visits
failures specific to the realized data; model misspecification
Main Content
PSIS as a diagnostic
With draws θ1,…,θS∼q, define ratios and a family of estimators
(Eqs. 2-3). ws≡1 is the plain VI estimate: low variance, biased “to an unknown extent and inconsistent.” ws=rs is importance sampling: consistent, but with possibly infinite variance, because a reverse-KL q “has a lighter tail than p(θ∣y) as a result of entropy penalization, which lead[s] to a heavy right tail of rs.”
Pareto smoothed importance sampling ^def-psis
Fit a generalized Pareto distribution to the M=min(S/5,3S) largest ratios, report the estimated shape k^, replace those M ratios “by their expected value under the fitted generalized Pareto distribution,” leave the rest unchanged, and truncate all weights at the raw maximum. The smoothed weights ws give lower mean squared error than plain or truncated IS (Sec. 2.1; Vehtari et al. 2017). This is the same PSIS used for leave-one-out cross-validation in Cross Validation Checking, with the variational q in place of the full-data posterior as the proposal.
What k measures
A generalized Pareto with shape k has finite moments up to order 1/k, so k^ estimates
where Dα(p∥q)=α−11log∫pαq1−αdθ is the Renyi divergence (Eq. 4). Hence:
k>0.5: the χ2 divergence is infinite (IS variance infinite);
k>1: D1(p∥q)=KL(p∥q)=∞, “indicating a disastrous VI approximation, despite the fact that KL(q,p) is always minimized among the variational family”;
k<1/3: Berry-Esseen gives an even faster approach to normality.
Theoretically k<1 always (since Eq[p(θ∣y)/q(θ)] is finite), but finite-sample k^ can exceed 1. k^ is invariant to multiplicative constants, which is why the unnormalized p(θ,y) suffices.
PSIS diagnostic (Yao et al., Algorithm 1) ^alg-psis-diagnostic
Run VI to obtain q(θ); draw θs∼q, s=1,…,S.
Compute rs=p(θs,y)/q(θs) (in practice logrs).
Fit the generalized Pareto to the M largest rs; report k^.
If k^<0.5:q is close to the posterior; use PSIS weights to refine estimates. If 0.5<k^<0.7: “not perfect but still useful”; use PSIS weights. If k^>0.7: unreliable; tune VI (reparameterize, more iterations, larger minibatch, smaller learning rate) or use MCMC.
Invariance (Sec. 2.3). Under a smooth bijection ξ=T(θ) the Jacobians cancel in p(ξ)/q(ξ)=p(θ)/q(θ), so k^ does not depend on the coordinates it is computed in. But a reparameterization that changes the family (e.g. centered vs non-centered, or a different ADVI transform) changes q∗ and hence k^, so k^ “can guide the choice of re-parametrization.”
Marginal k^ is misleading (Proposition 1)
If Eq[(p(θ)/q(θ))α]<∞ for some α>1, then Eq[(p(θi)/q(θi))α]<∞ for every margin i: marginal ki≤ joint k. So joint k^ grows with dimension, which “accurately reflects the quality of the variational approximation to the joint posterior.” Marginal k^i should nonetheless not be used: the true marginal density is unknown, and when VI over-disperses a margin, k^i is small even though the estimate is bad (Sec. 2.4).
VSBC
VSBC marginal diagnostic (Yao et al., Algorithm 2) ^alg-vsbc
For j=1,…,M: draw θj(0)∼p(θ); simulate y(j)∼p(y∣θj(0)) of the same size as the real data; run VI to get qj; for each margin i compute
pij=Pr(θij(0)<θi∗θ∗∼qj).
For each i, test whether {pij}j=1M is symmetric about 0.5 (histogram, or a Kolmogorov-Smirnov test comparing pi: with 1−pi:). Rejection means the VI approximation is biased in margin i.
This adapts Cook, Gelman & Rubin (2006), the precursor of SBC. Full SBC demands uniform histograms, a test that an approximate method like VI will essentially always fail, as ADVI does in SBC Case Studies. VSBC deliberately weakens the requirement to symmetry, asking only whether the centre is right.
Proposition 2 ^thm-vsbc-symmetry
For a one-dimensional parameter, if both the VI approximation q and the true posterior are symmetric and VI is unbiased, Eqθ=Ep(θ∣y)θ, then the distribution of VSBC p-values is symmetric. If VI is positively (negatively) biased, the distribution is right (left) skewed.
Reading shape as in Interpreting SBC Histograms: skew indicates bias; a symmetric U-shape indicates under-dispersion; a symmetric hump indicates over-dispersion.
Interpret conservatively: failing VSBC means VI “will not perform well on the model in question”; passing does not guarantee good behaviour on the actual data, and says nothing under misspecification (Sec. 3.2).
Experiments (all mean-field ADVI in Stan)
Four case studies (Sec. 4) ^ex-yao-cases
Linear regression, n=10000, K=100, βi∼N(0,1), σ∼Gamma(0.5,0.5), M=1000 VSBC replications. KS test not rejected for β1 (p=0.27), β2 (p=0.08); rejected for logσ, which is over-estimated. “The under-estimation of posterior variance is reflected by the U-shaped distributions.” On one data set k^=0.61 with relative tolerance 10−5, but k^=4.4 at the default 10−2: “a fake convergence” that k^ catches and the ELBO rule does not (Figs. 1-2).
Logistic regression with design correlation ρ∈[0,0.99]. Posterior correlation rises with ρ, mean-field fits worse, k^ rises. Held-out log predictive density of VI improves with ρ, “misleadingly suggesting better fit”; the discrepancy between VI and true lpd jumps sharply near k^=0.7. First- and second-moment RMSE grow with k^, and “PSIS adjustment always shrinks the VI estimation errors” (Figs. 3-4).
Eight schools (Hierarchical Models). Centered: joint k^=1.00; the Gaussian family cannot capture the funnel between τ and θ. Here ADVI over-estimates the posterior sd of every θj: the posterior mode is at τ=0, entropy pushes q away from it, τ is over-estimated, and that inflates the θj. Marginal k^i are “misleadingly small.” Non-centered (θj=μ+τθj∗): joint k^=0.64, smaller bias in means and sds. VSBC: θ1 symmetric; τ right-skewed (over-estimated) when centered and left-skewed (under-estimated) when non-centered (Figs. 5-6). “VI posteriors can be both over-dispersed and under-dispersed, depending crucially on the true parameter dependencies.”
Regularized-horseshoe logistic regression, leukemia microarray, D=7129, n=72. ADVI runs in minutes versus hours for MCMC, but k^=9.8: “not even close.” The Gaussian family misses the right-hand mode of logλj, collapsing the corresponding βj to a spike at zero; VSBC shows λ biased down and the global scale τ biased up to compensate (Figs. 7-8). Compare Regularized Horseshoe (Finnish Horseshoe) and The Horseshoe Prior.
Limitations (Sec. 5)
Both diagnostics are local. If the posterior is 0.8N(0,0.2)+0.2N(3,0.2) and q sits on one mode, the ratio is the constant 0.8 or 0.2 on the sampled region and k=0: “any divergence measure based on samples from the approximation such as KL(q,p) is local.” Remedies: multiple over-dispersed initializations; estimating KL(p,q) through PSIS with h=log(q/p); and VSBC itself, which draws truths from the prior and so can land in the missed mode. In practice “a marginal missing mode will typically lead to large joint discrepancy that is still detectable by k^,” as in the horseshoe example.
Examples
Computing k^ for a PyMC or Stan VI fit
import numpy as np, arviz as az# theta: (S, K) draws from q in the UNCONSTRAINED space# logp_joint(theta_s): log p(theta_s, y) incl. Jacobian; logq(theta_s): log q densitylog_r = np.array([logp_joint(t) - logq(t) for t in theta])log_w, khat = az.psislw(log_r) # smoothed log weights, Pareto shapeprint(f"k-hat = {float(khat):.2f}")if khat < 0.7: # PSIS-corrected posterior mean w = np.exp(log_w - log_w.max()); w /= w.sum() post_mean = (w[:, None] * theta).sum(0)
Both densities must be evaluated in the same coordinates; by the invariance result either space is fine as long as the Jacobian is included consistently. CmdStan’s variational output includes log_p__ (log joint) and log_g__ (log approximation) columns that can be differenced to form logrs.
A decision rule for applied work. For a media mix or geo-hierarchical model fitted by ADVI: (i) rerun with tolerance ≤10−4 and several seeds; (ii) compute joint k^; (iii) if k^>0.7, non-center, centre and scale predictors, try full-rank, then fall back to NUTS; (iv) never infer interval quality from good out-of-sample prediction, which case 2 shows can improve while the posterior approximation degrades. If the production system must use VI for speed, run VSBC once per model structure offline to learn which parameters (typically scales such as τ and σ) are systematically biased.