Skip to content
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

add elementwise max/min conversation and test case #92

Merged
merged 5 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/oneflow2onnx/nodes/CPU/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def forward(self, x: flow.Tensor) -> flow.Tensor:
y3 = flow.acos(y3)
y3 = flow.pow(y3, 2.0)
y2 = y2 + y3
flow.minimum(y2, y3)

B = x # shape: (1, 3, 224, 224)
flow.matmul(self.A, B)
Expand Down
1 change: 1 addition & 0 deletions examples/oneflow2onnx/nodes/GPU/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def forward(self, x: flow.Tensor) -> flow.Tensor:
y3 = flow.acos(y3)
y3 = flow.pow(y3, 2.0)
y2 = y2 + y3
flow.minimum(y2, y3)
Copy link
Contributor

Choose a reason for hiding this comment

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

cpu那里的测试也对应加一下吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


B = x # shape: (1, 3, 224, 224)
flow.matmul(self.A, B) # (128, 224) x (1, 3, 224, 224)
Expand Down
2 changes: 2 additions & 0 deletions oneflow_onnx/oneflow2onnx/handlers/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def _MakeMinOrMaxOp(ctx, op_type, inputs, outputs, output_shapes=None, output_dt

@flow_op("broadcast_minimum", onnx_op="Min")
@flow_op("broadcast_maximum", onnx_op="Max")
@flow_op("elementwise_minimum", onnx_op="Min")
@flow_op("elementwise_maximum", onnx_op="Max")
class MinMaxOp:
@classmethod
def Version_1(cls, ctx, node, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里我有个疑问,我看 https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Min-1 提到 Version 1 的 Min,是不支持 broadcast 的,所以在下面 _MakeMinOrMaxOp 里做了一些处理。

然而后面较高版本的 onnx op (比如 12 https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Min-12)又支持 broadcast 了。

不过自定义的 trick 好像又够用了,这个是不是暂时就不用添加更高版本的映射了?

Copy link
Contributor

Choose a reason for hiding this comment

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

是的

Expand Down