-
Notifications
You must be signed in to change notification settings - Fork 64
Add 2 ops zeros and zeros_like. #251
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
Codecov Report
@@ Coverage Diff @@
## main #251 +/- ##
==========================================
+ Coverage 72.16% 72.20% +0.04%
==========================================
Files 93 93
Lines 8916 8923 +7
==========================================
+ Hits 6434 6443 +9
+ Misses 2482 2480 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
zero = op.Constant(value=0) # type: ignore[arg-type] | ||
else: | ||
zero = op.Cast(0, to=dtype) # type: ignore[arg-type] | ||
return op.ConstantOfShape(size, zero) |
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.
ConstantOfShape takes an attribute as the second argument. You may need to use expand
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.
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.
ConstantOfShape takes an attribute as the second argument. You may need to use expand
Got it, has updated to use a constant of tensor instead.
I guess ConstantOfShape is just like a constant, while Expand may still need to do some computation to broadcast.
Thoughts?
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.
As long as it runs I am for anything that’s more simple. Were you able to run the tests? Expand was what Rama suggested when I initially used ConstantOfShape, because the zero here is not compile time constant.
Remove self because this function doesn't have it as a parameter. Co-authored-by: Justin Chu <[email protected]>
from onnxscript import BOOL, INT64 | ||
from onnxscript.onnx_opset import opset18 as op | ||
from onnxscript.onnx_types import TensorType | ||
|
||
const_zero_int = helper.make_tensor("zero_tensor", TensorProto.INT64, [1], [0]) |
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.
Just a note: for anything that is a global constant, prefer UPPER_CASE. If private, prefix with _
.
@@ -17,10 +17,12 @@ | |||
|
|||
from typing import Any, Optional, Sequence | |||
|
|||
from onnx import TensorProto, helper |
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.
Try to implement 2 ops in aten lib functions: zeros and zeros_like.