Repository navigation
Conversation
ConditionalDensityEstimator.sample_and_log_prob passed samples of shape (*sample_shape, batch, *event) straight to log_prob, which takes a single sample dimension. With a multi-dimensional sample_shape and more than one condition this raised a broadcasting error, e.g. for the MDN with sample_shape (2, 3) and four conditions. With sample_shape () the MNLE, MNPE and categorical estimators returned log probabilities of shape (1, batch) instead of (batch,). Flatten the sample dimensions for log_prob and restore them on the log probabilities, as the nflows, zuko and TabPFN overrides already do. The estimators that inherit the base method get the fix: the MDN, its NPE-A wrapper ProposalCorrectedMDN, the mixed estimator of MNLE and MNPE, and the categorical estimator. Posteriors are unaffected: they draw sample_shape.numel() samples and never call this method with several sample dimensions. The new test runs the inheriting builders (MDN, MNLE, MNPE, categorical) and checks the shapes and that each log probability belongs to its sample; 13 of its 24 cases fail without the fix.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
manuelgloeckler
self-requested a review
November 11, 2026 19:25
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sample_and_log_probreturns wrong shapes or fails for the MDN, the mixed estimator of MNLE and MNPE, and the categorical estimator. These estimators inherit the generic method ofConditionalDensityEstimator. It hands the samples tolog_prob, which accepts a single sample dimension.The fix flattens the sample dimensions for
log_proband restores them on the log probabilities. The nflows, zuko and TabPFN overrides already do this.Posteriors are unaffected: they draw
sample_shape.numel()samples and reshape the result themselves. The bug hits users who call the estimator API directly, for example in their own sampling or training code.Evidence
Shape of the log probabilities with four conditions:
sample_shape=(2, 3)(2, 3, 4)sample_shape=()(1, 4)(4,)The new test runs MDN, MNLE, MNPE and the categorical estimator with sample shapes
(),(3,),(2, 3)and one or four conditions. It checks the shapes and that each log probability belongs to its sample. On main, 13 of its 24 cases fail; on this branch all pass.Merge Danger
Door: two-way
Blast Radius: small
Only the generic method changes. For the MDN, calls with a single sample dimension give the same result as before. Code that relied on the extra leading dimension of MNLE log probabilities with
sample_shape=()sees(batch,)now, as for every other estimator.