-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implemented non-named version of unflatten #42563
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
Implemented non-named version of unflatten #42563
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 011eb2b (more details on the Dr. CI page):
ci.pytorch.org: 1 failedThis comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 47 times. |
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.
Other than reviews from @zou3519
Two things want to confirm here @zou3519 @heitorschueroff :
- This is not really a bc breaking change, but it breaks bc CI test, I think this is one time breaking after checking the check_backward_compatibility.py, but need to confirm.
- I think unflatten should be added into _overrides.py here like flatten:
Line 314 in 206db5c
torch.flatten: lambda input, start_dim=0, end_dim=-1: -1,
I'm pretty confident no one has serialized the above operators because they literally don't work in TorchScript (we've banned named tensors in TorchScript). So I wouldn't worry about the BC-breakage. I remember there was a way to "approve" a change to the backwards compatibility test so the PR doesn't break anything when it gets merged. cc @houseroad -- how does one do that again? |
Update: No need to add unflatten into _overrides.py, since we don't support torch.unflatten. |
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. [ghstack-poisoned]
@heitorschueroff Per @houseroad , please add unflatten function here https://fburl.com/lsb7ah1y |
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. [ghstack-poisoned]
|
@heitorschueroff |
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. [ghstack-poisoned]
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. [ghstack-poisoned]
glaringlee
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.
This LGTM now
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.
@zou3519
Agree unflatten(Tensor, int, namedshape) should be handled.
Just curious, how we handle unflatten(Tensor, str, namedshape)? if input tensor is not named, will user pass str?
@heitorschueroff I think we should add back unflatten(Tensor, int, namedshape)` support
On master that errors out, so I'd expect it to give a nice error after this PR |
glaringlee
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.
per above comments
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. Differential Revision: [D23030301](https://our.internmc.facebook.com/intern/diff/D23030301) [ghstack-poisoned]
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. Differential Revision: [D23030301](https://our.internmc.facebook.com/intern/diff/D23030301) [ghstack-poisoned]
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. Differential Revision: [D23030301](https://our.internmc.facebook.com/intern/diff/D23030301) [ghstack-poisoned]
zou3519
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.
LGTM, thanks for addressing all the comments!
I had some minor nits left, feel free to address (or not)
aten/src/ATen/native/TensorShape.cpp
Outdated
| dim, " (", self.size(dim), ") in the input tensor"); | ||
| } | ||
|
|
||
| auto shape = self.sizes().vec(); |
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.
nit: Using a DimVector gives better performance because it avoids dynamic allocations on the heap when the tensor has <= 5 dimensions:
pytorch/aten/src/ATen/core/DimVector.h
Line 11 in 4afbf39
| using DimVector = SmallVector<int64_t, kDimVectorStaticSize>; |
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.
IIRC the usage would be: DimVector shape(self.sizes().begin(), self.sizes().end());
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. Differential Revision: [D23030301](https://our.internmc.facebook.com/intern/diff/D23030301) [ghstack-poisoned]
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic. Differential Revision: [D23030301](https://our.internmc.facebook.com/intern/diff/D23030301) [ghstack-poisoned]
|
@heitorschueroff merged this pull request in 62bd2dd. |
Stack from ghstack:
Moved logic for non-named unflatten from python nn module to aten/native to be reused by the nn module later. Fixed some inconsistencies with doc and code logic.
Differential Revision: D23030301