Skip to content

De-prioritise Dimname and DimnameList in python overload resolution#51350

Closed
peterbell10 wants to merge 10 commits intogh/peterbell10/48/basefrom
gh/peterbell10/48/head
Closed

De-prioritise Dimname and DimnameList in python overload resolution#51350
peterbell10 wants to merge 10 commits intogh/peterbell10/48/basefrom
gh/peterbell10/48/head

Conversation

@peterbell10
Copy link
Copy Markdown
Collaborator

@peterbell10 peterbell10 commented Jan 29, 2021

Stack from ghstack:

None being a valid Dimname is awkward for optional dim arguments, as found
on NumPy's reduction functions like std and var. In these cases dim=None
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix FunctionParameter::check to actually check the first
element of INT_LIST arguments and reject non-int types. Otherwise, the dim
names end up calling the int[] overload and fail.

Differential Revision: D26756208

`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In this cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
@peterbell10 peterbell10 requested a review from mruberry January 29, 2021 14:57
@peterbell10 peterbell10 added module: codegen Issues related to the codegen for Aten and Autograd open source labels Jan 29, 2021
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jan 29, 2021

💊 CI failures summary and remediations

As of commit cc322e2 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This 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 to the (internal) Dr. CI Users group.

…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
@mruberry
Copy link
Copy Markdown
Collaborator

mruberry commented Feb 1, 2021

@bhosmer I think you're the correct reviewer for this change?

Copy link
Copy Markdown

@bhosmer bhosmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the awkwardness of Dimname scooping up None values, this seems like a reasonable solution for the eager binding layer. I think we'll need to do something similar for the JIT though. cc @eellison for confirmation - Elias, do we support Dimname overloads on the JIT side?

Comment thread torch/csrc/utils/python_arg_parser.cpp Outdated
PySequence_GetItem(obj, 0));
// NOTE: JIT tracer allows arbitrary scalar tensors to act as ints
// in an intlist argument Even float or complex scalars
return (THPVariable_Check(item.ptr()) || THPUtils_checkIndex(item.ptr()));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be good to factor this out now that it's nontrivial, a la is_float_or_complex_list() just below

Copy link
Copy Markdown

@bhosmer bhosmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the awkwardness of Dimname scooping up None values, this seems like a reasonable solution for the eager binding layer. I think we'll need to do something similar for the JIT though. cc @eellison for confirmation - Elias, do we support Dimname overloads on the JIT side?

…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
@eellison
Copy link
Copy Markdown
Contributor

eellison commented Feb 2, 2021

@bhosmer i dont think dimname is supported, the schemas with dimname dont get attempted to be matched to in JIT. it probably wouldnt be too hard to add just no one has done it :/

@bhosmer
Copy link
Copy Markdown

bhosmer commented Feb 2, 2021

@bhosmer i dont think dimname is supported, the schemas with dimname dont get attempted to be matched to in JIT. it probably wouldnt be too hard to add just no one has done it :/

Ah got it. Well, I don't think observing this overload ordering will add any difficulty once someone does, at least. Thanks for the info!

Copy link
Copy Markdown

@bhosmer bhosmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
@peterbell10 peterbell10 requested a review from albanD as a code owner February 8, 2021 19:02
…esolution"


`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mruberry merged this pull request in 70d0aab.

@facebook-github-bot facebook-github-bot deleted the gh/peterbell10/48/head branch March 6, 2021 15:17
aocsa pushed a commit to Quansight/pytorch that referenced this pull request Mar 15, 2021
…ytorch#51350)

Summary:
Pull Request resolved: pytorch#51350

`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D26756208

Pulled By: mruberry

fbshipit-source-id: 44221ca0f4822ec2c1f62b092466fd4f779eb45a
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
…ytorch#51350)

Summary:
Pull Request resolved: pytorch#51350

`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D26756208

Pulled By: mruberry

fbshipit-source-id: 44221ca0f4822ec2c1f62b092466fd4f779eb45a
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…ytorch#51350)

Summary:
Pull Request resolved: pytorch#51350

`None` being a valid `Dimname` is awkward for optional `dim` arguments, as found
on NumPy's reduction functions like `std` and `var`. In these cases `dim=None`
should mean an all-reduction, but instead you get an error
"Please look up dimensions by name".

I've also had to fix `FunctionParameter::check` to actually check the first
element of `INT_LIST` arguments and reject non-int types. Otherwise, the dim
names end up calling the `int[]` overload and fail.

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D26756208

Pulled By: mruberry

fbshipit-source-id: 44221ca0f4822ec2c1f62b092466fd4f779eb45a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed Merged module: codegen Issues related to the codegen for Aten and Autograd open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants