-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Fix CPU torch.multinomial with noncontiguous prob tensor #5093
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
Conversation
soumith
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor typo changes needed.
code looks good and correct
aten/src/TH/generic/THTensor.h
Outdated
| TH_API void THTensor_(expand)(THTensor *r, THTensor *tensor, THLongStorage *size); | ||
| TH_API void THTensor_(expandNd)(THTensor **rets, THTensor **ops, int count); | ||
|
|
||
| // resize* methods simplit resize the storage. So they may not retain the current data at current indices. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/TH/generic/THTensor.h
Outdated
|
|
||
| // resize* methods simplit resize the storage. So they may not retain the current data at current indices. | ||
| // This is especially likely to happen when the tensor is not contiguous. In general, if you still need the | ||
| // values, unless you are doing some size and stride tricks, do not use reize*. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/THC/generic/THCTensor.h
Outdated
| THC_API void THCTensor_(expand)(THCState *state, THCTensor *r, THCTensor *tensor, THLongStorage *sizes); | ||
| THC_API void THCTensor_(expandNd)(THCState *state, THCTensor **rets, THCTensor **ops, int count); | ||
|
|
||
| // resize* methods simplit resize the storage. So they may not retain the current data at current indices. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
neerajprad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the doc fixes, and adding on the unbatched params tests. Looks great!
The CPU code previously uses
resize2dwhich does not safely preserve data when input is not contiguous. This PR changes it tounsqueeze1din both CPU and GPU functions, and add strided support for the two functions. As a result,distributions.Categoricalnow doesn't need to callcontiguous()when the probabilities are not batched.Also in this PR are
torch.multinomial,distrbutions.OneHotCategoricalanddistrbutions.Categorical, anddistrbutions.OneHotCategoricalanddistrbutions.Categoricalin unbatched mode.Fixes #5062
cc @neerajprad @alicanb for
distributions.*changes review.