-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add aten mkldnn transpose #21943
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
Closed
Closed
Add aten mkldnn transpose #21943
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1987,10 +1987,22 @@ | |
| variants: function, method | ||
| device_guard: False | ||
|
|
||
| - func: mkldnn_transpose(Tensor self, int dim0, int dim1) -> Tensor | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this part of the public API? If you want to have helper functions prepend an underscore to their name! |
||
| device_guard: False | ||
| requires_tensor: True | ||
| dispatch: | ||
| MkldnnCPU: mkldnn_transpose | ||
|
|
||
| - func: transpose_(Tensor(a!) self, int dim0, int dim1) -> Tensor(a!) | ||
| variants: method | ||
| device_guard: False | ||
|
|
||
| - func: mkldnn_transpose_(Tensor(a!) self, int dim0, int dim1) -> Tensor(a!) | ||
| device_guard: False | ||
| requires_tensor: True | ||
| dispatch: | ||
| MkldnnCPU: mkldnn_transpose_ | ||
|
|
||
| - func: one_hot(Tensor self, int num_classes=-1) -> Tensor | ||
| python_module: nn | ||
| variants: function | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Hmm if new shapes are as same as the old shapes,
ideep::tensor::reshapewill not create a copy and thus y will share the same memory as x. This could be messy since then there will be two aten opaque tensors sharing the same underlying ideep tensor.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.
@bddppq We wanted to keep the semantics of
reshapeas much as possible here, i.e. do shallow copy on plain-format MKL-DNN tensor (layout of which is contiguous) and do deep copy otherwise (see https://github.com/intel/ideep/blob/d7304e0345c3f0647cb020a71682d680b9f0424a/include/ideep/tensor.hpp#L1100). For the shallow copy case,ideep::tensor y{x}would makeycopy the metadata ofxwhile share its underlying storage. This is the same semantics as the shallow copy of a native CPU tensor. So this should work fine here.Uh oh!
There was an error while loading. Please reload this page.
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.
@jgong5 It's fine to follow the semantics of cpu tensor to return the input tensor as output if the shapes are the same, but it's not fine to let two different aten opaque tensors to hold the same underlying ideep tensor.
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.
@bddppq But
yandxare two differentideep::tensorobject, right? They just share the same underlying storage while hold their own metadata. It is similar to how two CPU tensors share the same underlying storage while have their own metatdata. Make sense?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.
@bddppq @XiaobingSuper OK. Sounds like we should call
y.set_descriptor(x.get_descriptor())explicitly afterideep::tensor y{x}in order to guaranteeyuses a new MKL-DNN descriptor while sharing the underlying buffer ofx. We should have wrapped an explicit shallow copy API in ideep to do such a thing actually.Uh oh!
There was an error while loading. Please reload this page.
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.
@jgong5 @XiaobingSuper I would say just add the following lines at the beginning of this function :-)
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.
Yes, I will change it. Thanks!
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.
@bddppq, @jgong5 , changed it, thanks!
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.
@bddppq
y.reshapewould create a new descriptor by callingset_descriptor()so additionaly.set_descriptor(x.get_descriptor())is not necessary here. With the recent change of @XiaobingSuper , the behavior ofmkldnn_reshapelooks like below, mimicking the semantics ofreshapeof native CPU tensor:self, returnselfdirectly.selfand copies all metadata ofselfwith the new shape.selfwith the new shape.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.
@jgong5 @XiaobingSuper This sounds good to me.