Skip to content

[ONNX] Squeeze operator should give an error when trying to apply to a dimension with shape > 1#38476

Closed
yaeldekel wants to merge 17 commits intopytorch:masterfrom
yaeldekel:squeeze
Closed

[ONNX] Squeeze operator should give an error when trying to apply to a dimension with shape > 1#38476
yaeldekel wants to merge 17 commits intopytorch:masterfrom
yaeldekel:squeeze

Conversation

@yaeldekel
Copy link
Copy Markdown

The ONNX spec for the Squeeze operator:

Remove single-dimensional entries from the shape of a tensor. Takes a parameter axes with a list of axes to squeeze. If axes is not provided, all the single dimensions will be removed from the shape. If an axis is selected with shape entry not equal to one, an error is raised.

Currently, as explained in issue #36796, it is possible to export such a model to ONNX, and this results in an exception from ONNX runtime.

Fixes #36796.

@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented May 14, 2020

💊 CI failures summary and remediations

As of commit a0d1116 (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 on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 78 times.

@jerryzh168 jerryzh168 requested a review from houseroad May 15, 2020 20:51
@jerryzh168 jerryzh168 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label May 15, 2020
@neginraoof
Copy link
Copy Markdown
Contributor

You can catch flake8 issues locally using command: flake8 .
Thanks!

@ezyang ezyang requested review from neginraoof and removed request for houseroad May 26, 2020 20:05
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented May 26, 2020

@neginraoof when this is ready to land ping and I can land it

Copy link
Copy Markdown
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Could you rebase to master and make sure all related tests passing?

Copy link
Copy Markdown
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Please make sure all the ci passing:

  1. Lint / flake8-py3 (pull_request)
  2. onnx

Copy link
Copy Markdown
Contributor

@neginraoof neginraoof left a comment

Choose a reason for hiding this comment

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

Thanks! I added a few comments.

Comment thread torch/onnx/utils.py Outdated
Comment thread torch/onnx/symbolic_opset9.py Outdated
Comment thread torch/onnx/symbolic_opset9.py Outdated
Comment thread test/onnx/test_pytorch_onnx_onnxruntime.py Outdated
@houseroad houseroad self-requested a review June 22, 2020 06:02
Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@neginraoof neginraoof left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@neginraoof
Copy link
Copy Markdown
Contributor

@yaeldekel
Test failures don't look related. Can you verify this?

Copy link
Copy Markdown
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Could you reabse to the master and rerun the CI?

Comment thread torch/onnx/utils.py Outdated
Copy link
Copy Markdown
Contributor

@neginraoof neginraoof Jul 10, 2020

Choose a reason for hiding this comment

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

Can we add attributes within the addNode c++ method?

Comment thread torch/onnx/symbolic_opset11.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we directly check the self's size instead of inserting IF-else block?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The size is not always available at export time, so we needed to add an if-else block.

@bzinodev bzinodev self-requested a review July 16, 2020 19:48
@houseroad houseroad self-requested a review July 30, 2020 17:10
Copy link
Copy Markdown
Member

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Please resolve the conflict.

@houseroad
Copy link
Copy Markdown
Member

We still have conflict, could you rebase the PR to master? @yaeldekel

@houseroad
Copy link
Copy Markdown
Member

Could you please resolve the conflicts?

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@houseroad merged this pull request in 3c5e396.

@vadimkantorov
Copy link
Copy Markdown
Contributor

@yaeldekel Could you please explain the new behavior? Does it now emulate PyTorch behavior in ONNX? Does it now prohibit the squeeze(dim) on non-singleton dim from PyTorch?

@troymyname
Copy link
Copy Markdown

So...what's the outcome of this issue?

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…a dimension with shape > 1 (pytorch#38476)

Summary:
The ONNX spec for the Squeeze operator:

> Remove single-dimensional entries from the shape of a tensor. Takes a parameter axes with a list of axes to squeeze. If axes is not provided, all the single dimensions will be removed from the shape. If an axis is selected with shape entry not equal to one, an error is raised.

Currently, as explained in issue pytorch#36796, it is possible to export such a model to ONNX, and this results in an exception from ONNX runtime.

Fixes pytorch#36796.

Pull Request resolved: pytorch#38476

Reviewed By: hl475

Differential Revision: D22158024

Pulled By: houseroad

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

Labels

Merged open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export to ONNX of nop-squeeze errors out in ONNXRT