Skip to content

feat(atenlib): add ops(layer_norm)#459

Merged
xiaowuhu merged 20 commits intomicrosoft:mainfrom
xiaowuhu:xiaowu/addOps(layer_norm)
Mar 1, 2023
Merged

feat(atenlib): add ops(layer_norm)#459
xiaowuhu merged 20 commits intomicrosoft:mainfrom
xiaowuhu:xiaowu/addOps(layer_norm)

Conversation

@xiaowuhu
Copy link
Copy Markdown
Contributor

No description provided.

@xiaowuhu xiaowuhu mentioned this pull request Feb 22, 2023
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 22, 2023

Codecov Report

Merging #459 (58173d6) into main (c5ca05b) will increase coverage by 0.08%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #459      +/-   ##
==========================================
+ Coverage   72.37%   72.46%   +0.08%     
==========================================
  Files         109      109              
  Lines       10580    10603      +23     
  Branches     1089     1094       +5     
==========================================
+ Hits         7657     7683      +26     
+ Misses       2616     2613       -3     
  Partials      307      307              
Impacted Files Coverage Δ
onnxscript/function_libs/torch_aten/ops/core.py 69.74% <100.00%> (+0.24%) ⬆️
...ipt/tests/function_libs/torch_aten/extra_opinfo.py 100.00% <100.00%> (ø)
...s/function_libs/torch_aten/ops_correctness_test.py 90.30% <100.00%> (+0.08%) ⬆️
onnxscript/converter.py 83.46% <0.00%> (+0.26%) ⬆️

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

"""layer_norm(Tensor input, int[] normalized_shape, Tensor? weight=None, Tensor? bias=None, float eps=1e-05, bool cudnn_enable=True) -> Tensor"""

raise NotImplementedError()
axes = [-i for i in range(len(normalized_shape), 0, -1)]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So, the actual value specified in normalized_shape is irrelevant for aten_layer_norm? That sounds odd, so checking.

"convolution": core_ops.aten_convolution,
"empty_like": core_ops.aten_empty_like,
"index_select": core_ops.aten_index_select,
# "native_layer_norm": core_ops.aten_layer_norm, # FIXME: 3 outputs != 1 output
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would duplicate the opinfo and update its op

skips=(),
supports_out=False,
),
opinfo_core.OpInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's move this on top of "nn.functional.conv3d" for alphabetical order.

Copy link
Copy Markdown
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.

LGTM, thanks!

@titaiwangms
Copy link
Copy Markdown
Contributor

There is actually an opset for LayerNorm

@xiaowuhu xiaowuhu merged commit 690ed5d into microsoft:main Mar 1, 2023
@xiaowuhu xiaowuhu deleted the xiaowu/addOps(layer_norm) branch March 1, 2023 09:26
@@ -3984,18 +3995,18 @@ def _aten_native_layer_norm_onnx(
) -> Tuple[TReal, TReal, TReal]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

axes should be input now.

axes: Sequence[INT64],

And other places using ReduceMax/ReduceMean/ReduceMin should all be updated, otherwise, the model would pop errors saying ReduceXXX having unexpected input/attribute axes depending on opset_verison 17/18.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not necessarily. The interface of an aten op/function shouldn't change because of its implementation. Since an attribute can be promoted to be an input, it should be okay to leave the interface as is. But it is important to ensure that the implementation works correctly. Eg., use the noop_with_empty_axes attribute as appropriate to ensure correct behavior for when axes is empty, etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you referring to the annotation (Sequence[INT64]) or usage (op.ReduceMean(input, axes=axes))? I think both of them needed to be modified to be compatible with opset18?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am saying that the annotation should ideally depend on the aten specification (and not on the onnx opset). The call to onnx ops like ReduceMean, of course, will depend on the onnx opset.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make sense, but for onnx function (aten interface), I think we still rely on function_ir to differentiate attrs/inputs. I guess I am not sure if function_ir changed due to the opset version bump 17 -> 18 in this case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the idea might be related to #443

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am saying that the annotation should ideally depend on the aten specification (and not on the onnx opset). The call to onnx ops like ReduceMean, of course, will depend on the onnx opset.

I agree. We could change it to INT64 (instead of Sequence[INT64]) prepare for symint inputs. The evaluator should be able to handle this (maybe already)

@@ -3984,18 +3995,18 @@ def _aten_native_layer_norm_onnx(
) -> Tuple[TReal, TReal, TReal]:

# FIXME(justinchuby): Use opset18 when it is supported by onnxruntime
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Remove

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