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

Added dim keyword arg #2472

Merged
merged 12 commits into from
May 22, 2020
Merged

Added dim keyword arg #2472

merged 12 commits into from
May 22, 2020

Conversation

stefanwebb
Copy link
Contributor

This adds a dim keyword to the transforms.Permute and transform.AffineCoupling to define which dimension these transforms operate on. As discussed in #2464 this extra flexibility is useful when dealing with matrix/tensor/etc. valued random variables

Copy link
Member

@fritzo fritzo left a comment

Choose a reason for hiding this comment

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

LGTM after one nit

fritzo
fritzo previously approved these changes May 12, 2020
We need to take `self.dim` into account at the end of `_call`, `_inverse`, and `log_abs_det_jacobian`.

As a clarification, the changes to `log_abs_det_jacobian` are needed to perform an "elementwise" summation, where the elements are the samples/batches. This ensures that the transform works with things like `TransformedDistribution` that use the transform's `event_dim` to sum log probabilities from different transformations.
Use of `event_dim` in `log_abs_det_jacobian` allows `Permute` to be compatible with modules such as `TransformedDistribution` that sum log probabilities.
@stefanwebb
Copy link
Contributor Author

@akern40 has found a few bugs in how the dimensions are handled, I'll make the changes plus Fritz' requests

Additional use of `self.dim`
@stefanwebb stefanwebb requested a review from fritzo May 12, 2020 16:55
@stefanwebb
Copy link
Contributor Author

Made the requested changes!

Copy link
Member

@fritzo fritzo left a comment

Choose a reason for hiding this comment

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

Could we add some simple smoke tests to ensure shapes are handled correctly with dim= -1, -2, -3?

@akern40
Copy link
Contributor

akern40 commented May 12, 2020

Could we add some simple smoke tests to ensure shapes are handled correctly with dim= -1, -2, -3?

@stefanwebb do you want to handle that, or I can?

@stefanwebb
Copy link
Contributor Author

@fritzo @akern40 In the process of adding tests I discovered a number of issues with adding a dim keyword to these classes... I had to rethink how tests were handled for event_dim>1 classes and add in some NN resizing.

I think in an interface redesign I would make the helper functions to create transforms take an event_shape rather than an input_dim, or perhaps they could input a distribution or random variable that already has an event_shape.

All tests pass now!

fritzo
fritzo previously approved these changes May 22, 2020
@fritzo fritzo merged commit d3510f8 into pyro-ppl:dev May 22, 2020
@stefanwebb stefanwebb deleted the add_dim_to_coupling branch May 23, 2020 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants