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
Make ensemble observation shape independent of component order #2199
On main, EnsemblePotential.x_event_shape in sbi/inference/posteriors/ensemble_posterior.py uses only the first component potential's event shape. This makes observation processing depend on component order.
For example, put a custom potential whose x_event_shape is None first and a direct posterior whose condition shape is (2, 3) second. process_x() leaves one (2, 3) observation two-dimensional, and EnsemblePosterior.sample() interprets its leading dimension as two observations and rejects it. Reversing the components gives the ensemble a known event shape, so process_x() adds a batch dimension and the ensemble's observation-count check accepts it.
Requested change
Resolve the ensemble event shape from all declared component event shapes. Use the agreed known shape when other components have an unknown shape, and report an explicit error when known shapes conflict. Preserve the existing unknown-shape behavior when no component declares a shape.
Acceptance criteria
A single (2, 3) observation is treated as one observation regardless of whether the component with unknown shape comes first or second.
Conflicting known component event shapes produce an explicit error.
Add regression tests for both component orders, conflicting known shapes, and all-unknown shapes.
This is a follow-up to review of PR #2193, not a change requested in that PR. Requested by @BHARATH0153.
@BHARATH0153 thanks, I can confirm this on main: with a custom potential first, a single (2, 3) observation is rejected as two observations; with the direct posterior first, it passes.
An ensemble should have exactly one observation shape. So please check the shapes when the ensemble is built: take the shape its components declare, skip components with an unknown shape, and raise if two known shapes differ. Batching then stays in the existing x processing.
This also fixes issue #2198: no component can then reject an x that the ensemble accepted.
Please add the fix for both issues to PR #2193 instead of opening a new PR. Small fast tests are enough: both component orders, conflicting shapes, and a rejected x that leaves the old default in place.
done in PR #2193 (commit 7e10777), superseding my earlier no-need comment. EnsemblePotential now resolves x_event_shape from all components at build time: components with an unknown shape are skipped, known shapes must agree, and conflicting known shapes raise a ValueError. When no component declares a shape, the previous unknown-shape behavior is preserved. Batching stays in the existing x processing. Added fast tests for both component orders, conflicting shapes, and all-unknown shapes. The set_default_x() atomicity fix for #2198 is in the same PR.
Activity
BHARATH0153 commentedon Nov 19, 2026
@coderabbitai please close it for now
coderabbitai commentedon Nov 19, 2026
Analysis chain
Script executed:
Length of output: 1909
@BHARATH0153Your repository permission is read-only, so I could not close#2199. A repository member with write access can close it.You are interacting with an AI system.
janfb commentedon Nov 19, 2026
@BHARATH0153 thanks, I can confirm this on
main: with a custom potential first, a single(2, 3)observation is rejected as two observations; with the direct posterior first, it passes.An ensemble should have exactly one observation shape. So please check the shapes when the ensemble is built: take the shape its components declare, skip components with an unknown shape, and raise if two known shapes differ. Batching then stays in the existing
xprocessing.This also fixes issue #2198: no component can then reject an
xthat the ensemble accepted.Please add the fix for both issues to PR #2193 instead of opening a new PR. Small fast tests are enough: both component orders, conflicting shapes, and a rejected
xthat leaves the old default in place.We will review PR #2193 next week.
thanks, Jan
BHARATH0153 commentedon Nov 19, 2026
done in PR #2193 (commit 7e10777), superseding my earlier no-need comment.
EnsemblePotentialnow resolvesx_event_shapefrom all components at build time: components with an unknown shape are skipped, known shapes must agree, and conflicting known shapes raise aValueError. When no component declares a shape, the previous unknown-shape behavior is preserved. Batching stays in the existingxprocessing. Added fast tests for both component orders, conflicting shapes, and all-unknown shapes. The set_default_x() atomicity fix for #2198 is in the same PR.BHARATH0153 commentedon Nov 20, 2026
#2193 fixed in
test: keep the tests that catch silent regressions, move ensemble tests
test: keep the tests that catch silent regressions, move ensemble tests
fix!: amortized VI sample() and log_prob() take one observation (sbi-…