-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Conversation
torch/onnx/symbolic_opset9.py
Outdated
@@ -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, |
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.
This looks exactly the same as zeros/zeros_like. Consider reusing the code?
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.
updated, 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.
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.
@pytorchbot rebase this please |
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.
@bddppq 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.
LGTM
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.