Add a Distribution.infer_shapes() method to statically infer shapes #2739
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.
Addresses pyro-ppl/funsor#412
Requires pytorch/pytorch#50547 and pytorch/pytorch#50581
This adds a
TorchDistribution.infer_shapes()
method to statically compute(batch_shape, event_shape)
for use in Funsor. This method inputs*args,**kwargs
with the same signature as.__init__()
but inputting shapes rather than tensors. The following should be equivalent:The default implementation uses new
.support.event_dim
logic from pytorch/pytorch#50547, so I've included backports in this PR (we can delete next time PyTorch is released).Tested
.support.is_discrete
.support.event_dim
.infer_shapes()