Skip to content

Added support for Dim operation in ONNX export #31928

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

Closed
wants to merge 4 commits into from
Closed

Added support for Dim operation in ONNX export #31928

wants to merge 4 commits into from

Conversation

bpstark
Copy link

@bpstark bpstark commented Jan 8, 2020

While ONNX does not currently directly support the Dim operation on a
tensor, we can provide the same functionality with two ONNX operations.
This allows us to support Dim for all opsets. It may be adventageous to
add support for Dim into a future ONNX opset, and use that for more
efficient code.
While testing dim op found that there is an issue with empty blocks
withing if statements. Modified graph generation to prevent generation
of empty if blocks.

Fixes #27569

@bpstark bpstark requested a review from apaszke as a code owner January 8, 2020 00:13
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jan 8, 2020
@kostmo
Copy link
Member

kostmo commented Jan 8, 2020

💊 CircleCI build failures summary and remediations

As of commit bce520a:

Commit bce520a was recently pushed. Waiting for builds...


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.

This comment has been revised 6 times.

@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jan 9, 2020
@bpstark bpstark requested a review from BowenBao January 10, 2020 16:29
Brian Stark added 4 commits January 10, 2020 10:27
While ONNX does not currently directly support the Dim operation on a
tensor, we can provide the same functionality with two ONNX operations.
This allows us to support Dim for all opsets. It may be adventageous to
add support for Dim into a future ONNX opset, and use that for more
efficient code.
While testing dim op found that there is an issue with empty blocks
withing if statements. Modified graph generation to prevent generation
of empty if blocks.
Copy link
Collaborator

@BowenBao BowenBao left a comment

Choose a reason for hiding this comment

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

LGTM

@bpstark
Copy link
Author

bpstark commented Jan 13, 2020

@houseroad can you please take a look at this it should be ready for review now.

Thanks

Copy link
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
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.

Thanks

for (Block* block : node->blocks()) {
FixupONNXIfs(block);
if (block->nodes().begin() == block->nodes().end()) {
//ONNX does not support empty blocks, must use some op which does nothing
Copy link
Member

Choose a reason for hiding this comment

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

Nit: space after //

using namespace ::c10::onnx;
}

void FixupONNXIfs(Block* block) {
Copy link
Member

Choose a reason for hiding this comment

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

Add comment, why we need this pass?

if (node->kind() == ::c10::onnx::If) {
auto* if_node = node;
auto* graph = if_node->owningGraph();
for (Block* block : node->blocks()) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: block is shadowed by inner variable.

}
}
else {
for (Block* block : node->blocks()) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: block is shadowed by inner variable.

@houseroad
Copy link
Member

Feel free to create another PR to address nits :-)

@facebook-github-bot
Copy link
Contributor

@houseroad merged this pull request in a472f02.

@bpstark bpstark deleted the dimsupport branch January 14, 2020 20:54
wuhuikx pushed a commit to wuhuikx/pytorch that referenced this pull request Jan 30, 2020
Summary:
While ONNX does not currently directly support the Dim operation on a
tensor, we can provide the same functionality with two ONNX operations.
This allows us to support Dim for all opsets. It may be adventageous to
add support for Dim into a future ONNX opset, and use that for more
efficient code.
While testing dim op found that there is an issue with empty blocks
withing if statements. Modified graph generation to prevent generation
of empty if blocks.

Fixes pytorch#27569
Pull Request resolved: pytorch#31928

Reviewed By: hl475

Differential Revision: D19376602

Pulled By: houseroad

fbshipit-source-id: 111682b058a5341f5cca6c1a950c83ae412a4c6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged oncall: jit Add this issue/PR to JIT oncall triage queue 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 from TorchScript to ONNX: torch.onnx.symbolic_opset9.dim does not exist
9 participants