-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Conversation
💊 CircleCI build failures summary and remediationsAs 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. |
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.
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.
LGTM
@houseroad can you please take a look at this it should be ready for review now. Thanks |
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.
@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
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 |
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.
Nit: space after //
using namespace ::c10::onnx; | ||
} | ||
|
||
void FixupONNXIfs(Block* block) { |
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.
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()) { |
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.
Nit: block
is shadowed by inner variable.
} | ||
} | ||
else { | ||
for (Block* block : node->blocks()) { |
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.
Nit: block
is shadowed by inner variable.
Feel free to create another PR to address nits :-) |
@houseroad merged this pull request in a472f02. |
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
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