Skip to content

Add ONNX Export Support to empty and empty_like #24166

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 3 commits into from

Conversation

lara-hdr
Copy link
Contributor

Empty and empty_like return uninitialized tensors with specific sizes.
The values in the tensor cannot be predicted, that's why tests in test_pytorch_onnx_onnxruntime.py and test_pytorch_onnx_caffe2.py are not added.
The tests in test_operators.py verify the onnx graph and output shape.

@pytorchbot pytorchbot added the module: onnx Related to torch.onnx label Aug 11, 2019
@jerryzh168 jerryzh168 requested a review from houseroad August 12, 2019 22:47
@jerryzh168 jerryzh168 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 12, 2019
@@ -1157,6 +1157,19 @@ def _unique2(g, input, sorted, return_inverse, return_counts):
globals()[name] = parse_args('v', 'i')(partial(sym_help._cast_func_template, v))


@parse_args('v', 'i', 'v', 'v', 'v', 'v')
def empty(g, sizes, dtype, layout, device, pin_memory=False, memory_format=None):
return g.op("ConstantOfShape", sizes,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks exactly the same as zeros/zeros_like. Consider reusing the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, thanks!

Copy link

@spandantiwari spandantiwari left a comment

Choose a reason for hiding this comment

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

Overall this looks good. Here's a minor point to think about. torch.empty does not guarantee anything about the data in the output tensor, so exporting with zeros is not incorrect. But I am wondering if exporting with some random distribution (RandomNormal or RandomUniform) would be slightly better. Zeros are kind of special in that they are known to create issues. Use of zeros is not wrong in this context, but if it is the same, maybe we can consider using some other generator op for export.

@bddppq
Copy link
Contributor

bddppq commented Aug 15, 2019

@pytorchbot rebase this please

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.

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

Copy link
Contributor

@bddppq bddppq left a comment

Choose a reason for hiding this comment

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

LGTM

@facebook-github-bot
Copy link
Contributor

@bddppq merged this pull request in 50161f3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged module: onnx Related to torch.onnx 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.

9 participants