Implement named tensor unflatten(dim, namedshape).#25658
Implement named tensor unflatten(dim, namedshape).#25658zou3519 wants to merge 5 commits intogh/zou3519/138/basefrom
unflatten(dim, namedshape).#25658Conversation
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] ghstack-source-id: 4d552f0 Pull Request resolved: #25658
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] Differential Revision: [D17192655](https://our.internmc.facebook.com/intern/diff/D17192655)
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] ghstack-source-id: 5be58c6 Pull Request resolved: #25658
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] Differential Revision: [D17192655](https://our.internmc.facebook.com/intern/diff/D17192655)
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] ghstack-source-id: 3207bd8 Pull Request resolved: #25658
| - func: align_tensors(Tensor[] tensors) -> Tensor[] | ||
| named_guard: False | ||
|
|
||
| - func: unflatten(Tensor self, Dimname dim, int[] sizes, DimnameList names) -> Tensor |
There was a problem hiding this comment.
is there any close equivalent in numpy?
There was a problem hiding this comment.
No, in numpy one would use reshape. I did some research into the naming of this a while back, below is a summary:
In xarray (which is numpy + named axis), they use stack and unstack. The naming is based on pandas arrays' stack and unstack, which work in a similar manner.
In addition, Sasha Rush's namedtensor design uses stack and split.
Finally, salesforce/matchbox (autobatching with pytorch tensors) uses split_dim.
My proposal is to use flatten and unflatten instead of the above names. This is because stack and split already have semantic meaning: in pytorch, stack is an operation that takes a list of tensors and returns a new tensor; split is an operation that takes a tensor and splits it into multiple other tensors. Something like stack_dim and split_dim would make the semantics clearer, but since we already have flatten as a part of the API, unflatten is a reasonable counterpart.
There was a problem hiding this comment.
@zou3519 actually this probably also needs an entry in the docs
There was a problem hiding this comment.
No named tensors docs yet, but they'll come before the release.
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] Differential Revision: [D17192655](https://our.internmc.facebook.com/intern/diff/D17192655)
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] ghstack-source-id: 97f0895 Pull Request resolved: #25658
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] Differential Revision: [D17192655](https://our.internmc.facebook.com/intern/diff/D17192655)
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] ghstack-source-id: 492d90f Pull Request resolved: #25658
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] Differential Revision: [D17192655](https://our.internmc.facebook.com/intern/diff/D17192655)
This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] ghstack-source-id: 74c497c Pull Request resolved: #25658
Summary: Pull Request resolved: pytorch/pytorch#25658 This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] Differential Revision: D17192655 Pulled By: zou3519 fbshipit-source-id: fd9bd2f462c23a4df1c23d66f2aa95076ff1b160
Summary: Pull Request resolved: pytorch#25658 This unflattens `dim` according to the shape specified in `namedshape`. `namedshape` may be either an OrderedDict or an iterable of (name, size) tuples. Future: - It is possible to make it take a dict in Python >= 3.6 because those are ordered by default, but I'll leave that task for the future. Test Plan: - new tests [namedtensor ci] Differential Revision: D17192655 Pulled By: zou3519 fbshipit-source-id: fd9bd2f462c23a4df1c23d66f2aa95076ff1b160
Stack from ghstack:
unflatten(dim, namedshape). #25658 Implement named tensorunflatten(dim, namedshape).This unflattens
dimaccording to the shape specified innamedshape.namedshapemay be either an OrderedDict or an iterable of (name, size)tuples.
Future:
ordered by default, but I'll leave that task for the future.
Test Plan:
Differential Revision: D17192655