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
Posterior methods give internal errors for theta of the wrong shape #2136
The fix for issue #2125 checks x against the shape of one observation when it enters a posterior. Theta has no such check: a theta with the wrong number of parameters fails deep inside the potential with an error that does not name theta.
posterior.log_prob(torch.zeros(4, 3), x=x_o) # prior has 2 parameters# RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 1
Fix direction: check theta against the event shape of the prior in potential() and log_prob(), next to the check of x, and raise a ValueError such as "theta has 3 entries per row, but the prior has 2".
Related: bound with x_is_iid=False and a single x, the NPE potential pairs that x with every theta, while the NLE and NRE potentials raise because the batch sizes differ. They should behave the same.
Hey @janfb! Quick update—I went ahead and put together the fix following your suggestion.
I added checks right at the entry points of DirectPosterior.log_prob() and NeuralPosterior.potential() to validate incoming theta against self._theta_dim. Now it throws a clean ValueError upfront when shapes don't match instead of letting PyTorch blow up deep down with cryptic expansion errors.
I also added a regression test (test_direct_posterior_shape_validation) in tests/posterior_sampler_test.py and everything passes cleanly locally.
Could you assign this issue to me? Let me know if this approach looks good to you and I'll open up a PR for review!
Hello @janfb ,
Thanks for merging #2120! Just following up briefly on #2136 —I have the fix and test ready locally, so let me know if it's okay to open the PR.
Activity
Ashwini8686 commentedon Nov 13, 2026
Hey @janfb! Quick update—I went ahead and put together the fix following your suggestion.
I added checks right at the entry points of DirectPosterior.log_prob() and NeuralPosterior.potential() to validate incoming theta against self._theta_dim. Now it throws a clean ValueError upfront when shapes don't match instead of letting PyTorch blow up deep down with cryptic expansion errors.
I also added a regression test (test_direct_posterior_shape_validation) in tests/posterior_sampler_test.py and everything passes cleanly locally.
Could you assign this issue to me? Let me know if this approach looks good to you and I'll open up a PR for review!
Ashwini8686 commentedon Nov 15, 2026
Hello @janfb ,
Thanks for merging #2120! Just following up briefly on #2136 —I have the fix and test ready locally, so let me know if it's okay to open the PR.