Skip to content

Adding .expand method for TransformedDistribution#11607

Closed
neerajprad wants to merge 3 commits intopytorch:masterfrom
neerajprad:transdist-expand
Closed

Adding .expand method for TransformedDistribution#11607
neerajprad wants to merge 3 commits intopytorch:masterfrom
neerajprad:transdist-expand

Conversation

@neerajprad
Copy link
Contributor

This PR:

  • adds a .expand method for TransformedDistribution along the lines of Add .expand() method to distribution classes #11341.
  • uses this method to simplify .expand in distribution classes that subclass off of TransformedDistribution.
  • restores testing of TransformedDistribution fixtures.
  • fixes some bugs wherein we were not setting certain attributes in the expanded instances, and adds tests for .mean and .variance which use these attributes.

Motivation:

There are many cases where users directly use TransformedDistribution rather than subclassing off it. In such cases, it seems rather inconvenient to have to write a separate class just to define a .expand method. The default implementation should suffice in these cases.

cc. @fritzo, @vishwakftw, @alicanb

super(RelaxedBernoulli, new).__init__(base_dist, SigmoidTransform(), validate_args=False)
new._validate_args = self._validate_args
return new
batch_shape = torch.Size(batch_shape)

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Collaborator

@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, nice simplification! Feel free to ignore or address my nit as you like.

Copy link
Collaborator

@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.

Looks great!

@soumith
Copy link
Collaborator

soumith commented Sep 13, 2018

@pytorchbot retest this please

@neerajprad
Copy link
Contributor Author

Should be good to merge.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

soumith is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

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.

5 participants