You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NPE with several iid observations fails in the importance, rejection and VI posteriors #2122
With NPE, an x with several rows fails in the importance, rejection and VI posteriors, and in potential() of every posterior. Only log_prob() and sample() of the MCMC posterior treat the rows as iid observations.
The NPE potential supports iid observations since PR #1810 (issue #1804). PR #1813 made the MCMC posterior bind x with x_is_iid=True in log_prob() and sample(). All other posterior methods bind x without this flag. The NPE potential then defaults to x_is_iid=False: it treats the rows as separate observations and asserts that theta and x have the same batch size.
The fix: these methods bind x with x_is_iid=True, as the MCMC posterior does. NLE and NRE potentials already default to x_is_iid=True, so their results stay the same. A test checks for each posterior that potential() with several rows equals the potential bound with x_is_iid=True, and that sampling runs.
Found in PR #2107, where CodeRabbit raised it for the importance posterior.
@janfb I'd like to take this one. The failing calls all bind x without the flag so the NPE potential falls back to x_is_iid=False:importance log_prob/sample,rejection log_prob/sample, VI train, and the shared potential() (which is also where
estimate_normalization_constant lands) Plan is to pass x_is_iid=True at those spots, the same way MCMC does in
mlog_prob/sample, and keep it False where each theta is deliberately paired with its own x (VI train_amortized, MCMC sample_batched). One thing I'd like your call on:
doing it in the base potential() also affects FMPE/NPSE, whose VectorFieldPotential
defaults to False. but tell me if you'd
rather scope this to the NPE family.
Test would be parametrized over the four posteriors: potential() with a 3-row x must
match the potential bound with x_is_iid=True, and sample() must run
Tracked together with issue #2125: the NPE potential first has to count the iid trials correctly, then all posteriors can bind several rows of x as iid. Closing in favour of issue #2125.
Understood, and sorry for getting ahead of the scope question on #2122 — I should have waited for an answer before opening this, as we agreed on #2083.
Thanks for the pointer to #2125. Agreed that binding x as iid in more posteriors would spread the wrong trial count, so this and the reduced-trial correction should land together rather than as a separate change. I'll leave #2122 to your internal fix and won't push further on it.
The branch stays as-is if the test setup is useful as a reference, but I won't open anything else on it.
I'll keep focusing on #2123 and stay within that scope.
Activity
BHARATH0153 commentedon Oct 29, 2026
@janfb I'd like to take this one. The failing calls all bind x without the flag so the NPE potential falls back to x_is_iid=False:importance log_prob/sample,rejection log_prob/sample, VI train, and the shared potential() (which is also where
estimate_normalization_constant lands) Plan is to pass x_is_iid=True at those spots, the same way MCMC does in
mlog_prob/sample, and keep it False where each theta is deliberately paired with its own x (VI train_amortized, MCMC sample_batched). One thing I'd like your call on:
doing it in the base potential() also affects FMPE/NPSE, whose VectorFieldPotential
defaults to False. but tell me if you'd
rather scope this to the NPE family.
Test would be parametrized over the four posteriors: potential() with a 3-row x must
match the potential bound with x_is_iid=True, and sample() must run
janfb commentedon Oct 31, 2026
Tracked together with issue #2125: the NPE potential first has to count the iid trials correctly, then all posteriors can bind several rows of
xas iid. Closing in favour of issue #2125.Thanks, Jan
BHARATH0153 commentedon Nov 1, 2026
Understood, and sorry for getting ahead of the scope question on #2122 — I should have waited for an answer before opening this, as we agreed on #2083.
Thanks for the pointer to #2125. Agreed that binding
xas iid in more posteriors would spread the wrong trial count, so this and the reduced-trial correction should land together rather than as a separate change. I'll leave #2122 to your internal fix and won't push further on it.The branch stays as-is if the test setup is useful as a reference, but I won't open anything else on it.
I'll keep focusing on #2123 and stay within that scope.
Thanks for the review and the clear explanation.
test: VI fits NPE posteriors to several observations with every VI me…
fix: count iid trials by the observation shape, and combine iid obser…