Skip to content

Conversation

@fritzo
Copy link
Collaborator

@fritzo fritzo commented Jul 24, 2019

This modernizes distributions code by replacing a few uses of .contiguous().view() with .reshape(), fixing a sample bug in the Categorical distribution.

The bug is exercised by the following test:

batch_shape = (1, 2, 1, 3, 1)
sample_shape = (4,)
cardinality = 2
logits = torch.randn(batch_shape + (cardinality,))
dist.Categorical(logits=logits).sample(sample_shape)
# RuntimeError: invalid argument 2: view size is not compatible with
#   input tensor's size and stride (at least one dimension spans across
#   two contiguous subspaces). Call .contiguous() before .view().
#   at ../aten/src/TH/generic/THTensor.cpp:203

I have verified this works locally, but I have not added this as a regression test because it is unlikely to regress (the code is now simpler).

@fritzo fritzo added the module: distributions Related to torch.distributions label Jul 24, 2019
@fritzo fritzo requested a review from neerajprad July 24, 2019 19:58
Copy link
Contributor

@neerajprad neerajprad left a comment

Choose a reason for hiding this comment

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

Thanks for fixing and simplifying this!

@apaszke
Copy link
Contributor

apaszke commented Jul 26, 2019

@pytorchbot merge this please

@pytorchbot pytorchbot added the merge-this-please Was marked for merge with @pytorchbot merge this please label Jul 26, 2019
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.

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

@facebook-github-bot
Copy link
Contributor

@colesbury merged this pull request in 06762b4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-this-please Was marked for merge with @pytorchbot merge this please Merged module: distributions Related to torch.distributions open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants