Add more tests for collapse handler#809
Conversation
| msg['stop'] = True | ||
|
|
||
|
|
||
| def _eager_expand_fn(fn): |
There was a problem hiding this comment.
Do I understand correctly that this function eliminates lazy ExpandedDistributions 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 ExpandedDistributions in Funsor, or to do this conversion in the funsor layer. @eb8680 does that seem possible?
There was a problem hiding this comment.
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.
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.
add a
to_funsorpattern 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.
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_fnso 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.