Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling sampling with intermediates for ExpandedDistribution #909

Merged
merged 2 commits into from
Feb 11, 2021

Conversation

lumip
Copy link
Contributor

@lumip lumip commented Feb 10, 2021

Currently, ExpandedDistribution blocks intermediate values from the base distribution in sample_with_intermediates, i.e., intermediate values cannot be retrieved from sampling and traces when ExpandedDistribution and, by extension, the plate primitive is used.
The pull request implements ExpandedDistribution.sample_with_intermediates under the assumption that batch_shape of intermediate values expands in the same way as for the main sampled value.

As of yet, there are not additional tests to verify correctness of the intermediates, though.

It involved some elaborate shuffling in sample/batch dimensions
that is unneccessary (due to independence in these dimensions)
and didn't mitigate the need for a reshape in the end,
which achieves the same results all on its own.
Assuming that intermediates are batched similarly to direct samples.
shape is correct: This implicitly replaces the interstitial dims
of size 1 in the original batch_shape of base_dist with those
in the expanded dims. While it somewhat 'shuffles' over batch
dimensions, we don't care because they are considered independent."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. The change looks great but let me think a bit more to see if I miss something.

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @lumip! The change looks great. I believe this would be pretty useful for costly transformed distributions under plate.

@fehiepsi fehiepsi merged commit aee9458 into pyro-ppl:master Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants