Skip to content

feat(atenlib): add ops (any, expand_as) #463

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

Merged
merged 18 commits into from
Mar 2, 2023
Merged

feat(atenlib): add ops (any, expand_as) #463

merged 18 commits into from
Mar 2, 2023

Conversation

xiaowuhu
Copy link
Contributor

No description provided.

@xiaowuhu xiaowuhu marked this pull request as draft February 23, 2023 11:47
@gramalingam
Copy link
Collaborator

A couple of questions: why not use ReduceMax instead of ReduceSum ? Is it because of opset dependence?

Also: does ReduceSum not work for scalar inputs? I am wondering where exactly the logic breaks (with onnx.ORT) if a zero-dimensional tensor is used.

@xiaowuhu xiaowuhu changed the title [draft] feat(atenlib): add ops (any) [draft] feat(atenlib): add ops (any, expand_as) Feb 26, 2023
@xiaowuhu xiaowuhu marked this pull request as ready for review February 26, 2023 08:13
@xiaowuhu xiaowuhu changed the title [draft] feat(atenlib): add ops (any, expand_as) feat(atenlib): add ops (any, expand_as) Feb 26, 2023
@codecov
Copy link

codecov bot commented Feb 26, 2023

Codecov Report

Merging #463 (1795cf3) into main (e66ca88) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #463      +/-   ##
==========================================
+ Coverage   72.46%   72.52%   +0.06%     
==========================================
  Files         109      109              
  Lines       10607    10626      +19     
  Branches     1093     1096       +3     
==========================================
+ Hits         7686     7707      +21     
+ Misses       2614     2612       -2     
  Partials      307      307              
Impacted Files Coverage Δ
...s/function_libs/torch_aten/ops_correctness_test.py 90.22% <ø> (ø)
onnxscript/function_libs/torch_aten/ops/core.py 70.19% <100.00%> (+0.42%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@xiaowuhu
Copy link
Contributor Author

xiaowuhu commented Feb 27, 2023

A couple of questions: why not use ReduceMax instead of ReduceSum ? Is it because of opset dependence?

Also: does ReduceSum not work for scalar inputs? I am wondering where exactly the logic breaks (with onnx.ORT) if a zero-dimensional tensor is used.

Thanks for reminder. I changed to use ReduceMax now.
Both ReduceMax and ReduceSum cannot work on scalar, have to Reshape to 1-D tensor at very beginning.

@@ -269,10 +269,33 @@ def aten_angle(self: TensorType) -> TensorType:
raise NotImplementedError()


def aten_any(self: TensorType) -> TensorType:
@torch_op("aten::any", trace_only=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need trace_only here? Looks like all of operations are safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

due to the Optional argument parsing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you say more on what optional argument parsing is? I would also add a comment on why trace_only was needed in 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.

if not use trace_only, it will throw exception:


E   TypeError: Required input 'dim: Attribute[None]' was not provide

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is the same as the issue we discussed in today's meeting. if (OptionalHasElement(x)) then use(x) is an issue. We need to find a solution to this. One possibility is to extend OptionalGetElement, but wonder if that's enough for all cases.

Copy link
Contributor

@fatcat-z fatcat-z left a comment

Choose a reason for hiding this comment

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

Thanks!

@xiaowuhu xiaowuhu merged commit 10395c8 into microsoft:main Mar 2, 2023
@xiaowuhu xiaowuhu deleted the xiaouw/addOps(any,-expand_as) branch March 2, 2023 06:00
@@ -269,10 +269,32 @@ def aten_angle(self: TensorType) -> TensorType:
raise NotImplementedError()


def aten_any(self: TensorType) -> TensorType:
@torch_op("aten::any", trace_only=True)
def aten_any(self: TTensor, dim: Optional[int] = None, keepdim: bool = True) -> BOOL:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think keepdim should default to False, or set as keepdim: Optional[bool] = None, and explicitly set to False if None.

That way we can avoid hard coding keepdims=0 later.

https://github.com/microsoft/onnx-script/blob/ec7c26471e0ef1896ba492549f33d0367b0301e4/onnxscript/function_libs/torch_aten/ops/core.py#L292

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't the default value be determined by the spec of the aten op?

Copy link
Contributor

@BowenBao BowenBao Mar 4, 2023

Choose a reason for hiding this comment

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

Looking at it again, I figured we are supporting 2 overloads of aten::any with this function. So for - func: any(Tensor self) -> Tensor we need actually figuring out what the behavior is since both dim and keepdim are not provided and have no defaults. So I think this is fine.

And for - func: any.dim(Tensor self, int dim, bool keepdim=False) -> Tensor, yea you are right, the current default is wrong and it should be False.

- func: any(Tensor self) -> Tensor
  device_check: NoCheck   # TensorIterator
  structured_delegate: any.all_out
  variants: method, function
  dispatch:
    SparseCPU, SparseCUDA: any_sparse

- func: any.dim(Tensor self, int dim, bool keepdim=False) -> Tensor
  device_check: NoCheck   # TensorIterator
  structured_delegate: any.out
  variants: function, method

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @justinchuby it is weird the wrong default is not caught in op test, I wonder if it is just not enough coverage in original opinfo or something else.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should not have combined the two overloads, and yes - you have a great point that we should verify the opinfo to assert how much confidence it can provide us for each op before trusting it. I will add this to the authoring guide

This was referenced Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants