-
Notifications
You must be signed in to change notification settings - Fork 247
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
Add more tests for collapse handler #809
base: master
Are you sure you want to change the base?
Conversation
@@ -245,6 +246,20 @@ def process_message(self, msg): | |||
msg['stop'] = True | |||
|
|||
|
|||
def _eager_expand_fn(fn): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that this function eliminates lazy ExpandedDistribution
s and replaces them with eagerly tree_map
-expanded distributions, and that this is needed because Funsor distributions do not support Expanded distributions? If so could you add a commend explaining that?
I guess an alternative would be to support ExpandedDistribution
s in Funsor, or to do this conversion in the funsor layer. @eb8680 does that seem possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is. I'll add a comment for clarity. I thought from our last discussion, this stuff should be treated in Pyro/NumPyro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess an alternative would be to support ExpandedDistributions in Funsor, or to do this conversion in the funsor layer.
We could certainly implement an equivalent of .expand
. I think the easiest thing to do to address this case would be to add a to_funsor
pattern for ExpandedDistribution
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a
to_funsor
pattern forExpandedDistribution
Yeah, it seems that you both agree to do this. I can take an effort for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would basically be the same as what you have here, plus a final step that calls to_funsor
on the eagerly expanded result.
Originally, this is used to test for funsor PR: pyro-ppl/funsor#392. But I found that we need more tests when updating the code to match Pyro version.
To pass some tests, I need to eagerly expand an ExpandedDistribution using
_eager_expand_fn
so that:Normal(0, 1).expand([10])
is still a Normal instance. This is not needed in Pyro becausefn.expand(...)
returns a new instance oftype(fn)
.I added some failing tests for discussions. Addressing them can be deferred to a follow-up PR in funsor.