-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Added names= arg for some creation functions #21919
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
- empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci]
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
|
||
- func: scalar_tensor(Scalar s, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor | ||
|
||
- func: rand(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> 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.
I think everything after the *
is optional and kwarg only, is there a reason we can't just provide a default None value and merge this with the existing interface below?
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, there is a reason and it is complicated. The short answer is that this is the easiest way to implement it.
Long answer: We've got two rand declarations in native_functions.yaml (without the Generator arg):
- func: rand(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- func: rand(int[] size, *, Tensor(a!) out) -> Tensor(a!)
These get merged together to produce one scheme string for the python arg parser:
"rand(IntArrayRef size, *, Tensor out=None, ScalarType dtype=None, Layout layout=torch.strided, Device device=None, bool pin_memory=False, bool requires_grad=False)",
Now, my claim is that it doesn't make sense to add a names=
argument when an out
tensor is provided. If there were such an arg, it could either
- (1) check that the
out
tensor has the correctnames
. In this case, the user would always have to specify the correct names which is bad because it's verbose and unnecessary. - (2) override the
names
of theout
tensor: this is weird, especially ifnames=None
by default.
Because it doesn't make sense, rand(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
should be a separate schema that isn't combined with an out=
argument.
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.
ah weird, OK
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.
It's weird and I don't like it because it means we need 2x the schemas and that it's easy for the schemas to go out of sync. But I don't know of how else we can do this.
#ifdef NAMEDTENSOR_ENABLED | ||
Tensor ones( | ||
IntArrayRef size, | ||
at::optional<DimnameList> names, |
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.
I know we don't plan to support an ordered-dict option because of python2, but is there any chance we'll want to support an option to construct named tensors in C++ using an ordered map? or would the syntax be just as unwieldy as python2?
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.
There are no plans for named tensor support in C++ in the near future.
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Added names= arg for some creation functions - empty, ones, zeros, rand, randn Test Plan - new tests [namedtensor ci] gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Closing because I want to do this another way. |
Stack from ghstack:
abs
. #22151 Named inference rule forabs
.Test Plan
gh-metadata: pytorch pytorch 21919 gh/zou3519/56/head
Differential Revision: D15940549