Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expand_dims #56774

Open
asi1024 opened this issue Apr 23, 2021 · 4 comments
Open

Support expand_dims #56774

asi1024 opened this issue Apr 23, 2021 · 4 comments
Labels
function request A request for a new function or the addition of new arguments/modes to an existing function. module: numpy Related to numpy support, and also numpy compatibility of our operators module: python array api Issues related to the Python Array API triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@asi1024
Copy link
Contributor

asi1024 commented Apr 23, 2021

馃殌 Feature

Support torch.expand_dims.
(cc: @mruberry, @rgommers, @emcastillo and @kmaehashi)

Motivation and Pitch

To enhance the compatibility with NumPy鈥檚 interface (c.f. #38349).

Currently PyTorch supports the same functionality with a different function name: torch.unsqueeze, but I would like to support an alias to improve compatibility with NumPy and Python array API standard (#54581).

References

cc @mruberry @rgommers @heitorschueroff @pmeier

@ezyang ezyang added enhancement Not as big of a feature, but technically not a bug. Should be easy to fix module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Apr 23, 2021
@rgommers
Copy link
Collaborator

Thanks @asi1024. +1 for adding expand_dims as an alias to unsqueeze. It's a nicer name too imho, since unsqueeze isn't actually the inverse of squeeze.

The one question I have is whether it should be a Tensor method too.

@mruberry mruberry added function request A request for a new function or the addition of new arguments/modes to an existing function. and removed enhancement Not as big of a feature, but technically not a bug. Should be easy to fix labels Apr 24, 2021
@mruberry
Copy link
Collaborator

Thanks @asi1024. +1 for adding expand_dims as an alias to unsqueeze. It's a nicer name too imho, since unsqueeze isn't actually the inverse of squeeze.

Adding an alias is straightforward, too. See the note in native_functions.yaml. If unsqueeze doesn't already have an OpInfo I'd first submit a PR adding an OpInfo for it, since OpInfos are how we test aliasing now.

The one question I have is whether it should be a Tensor method too.

Most functions in the torch namespace have both a function and method variant. unsqueeze has a method variant, too, so for consistency I suggest we make this both a function and a method.

@asi1024
Copy link
Contributor Author

asi1024 commented Apr 26, 2021

@mruberry

If unsqueeze doesn't already have an OpInfo I'd first submit a PR adding an OpInfo for it, since OpInfos are how we test aliasing now.

unsqueeze doesn't have an OnInfo currently. I can submit a PR for it if I just have to add ShapeFuncInfo to op_db!

@mruberry
Copy link
Collaborator

unsqueeze doesn't have an OnInfo currently. I can submit a PR for it if I just have to add ShapeFuncInfo to op_db!

You can just add it as a regular OpInfo ;)

facebook-github-bot pushed a commit that referenced this issue Apr 27, 2021
Summary:
This PR is ready for #56774.

(cc: mruberry, emcastillo, kmaehashi)

Pull Request resolved: #56924

Reviewed By: H-Huang

Differential Revision: D28026529

Pulled By: mruberry

fbshipit-source-id: 3afb33bb2999110c565728cd761d3e7d9d3fc82b
crcrpar pushed a commit to crcrpar/pytorch that referenced this issue May 7, 2021
Summary:
This PR is ready for pytorch#56774.

(cc: mruberry, emcastillo, kmaehashi)

Pull Request resolved: pytorch#56924

Reviewed By: H-Huang

Differential Revision: D28026529

Pulled By: mruberry

fbshipit-source-id: 3afb33bb2999110c565728cd761d3e7d9d3fc82b
krshrimali pushed a commit to krshrimali/pytorch that referenced this issue May 19, 2021
Summary:
This PR is ready for pytorch#56774.

(cc: mruberry, emcastillo, kmaehashi)

Pull Request resolved: pytorch#56924

Reviewed By: H-Huang

Differential Revision: D28026529

Pulled By: mruberry

fbshipit-source-id: 3afb33bb2999110c565728cd761d3e7d9d3fc82b
@pmeier pmeier added the module: python array api Issues related to the Python Array API label Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function request A request for a new function or the addition of new arguments/modes to an existing function. module: numpy Related to numpy support, and also numpy compatibility of our operators module: python array api Issues related to the Python Array API triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants