Skip to content

Custom pseudo-operations for generic rewriting #2162

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

Open
leshabirukov opened this issue Apr 3, 2025 · 0 comments
Open

Custom pseudo-operations for generic rewriting #2162

leshabirukov opened this issue Apr 3, 2025 · 0 comments

Comments

@leshabirukov
Copy link
Contributor

leshabirukov commented Apr 3, 2025

This text organized as

  1. Problem
  2. Solution
  3. This issue subject

Problem to solve

I want element-wise operations move above their commutatives (friends). See picture:

Image

I don't want to encode every possible interchange pair, so must be generic element-wise and generic friend. Can I have it with current onnxscript (0.2.2) rewriter?

  1. Solution

Use meta-abc node pairs like this:

Image

In the attachment, there is prototype implementation.
It moves elementwise operations (ReLU and Tanh) above Identity and Flatten

cusops2ons.py.txt

test_generic_as_wrap.py.txt

For now, we encode elementwise wrappers as [Split(axis=20), Sub]
and wrappers of their friend as [Split(axis=30), Sub]

What do you think about this approach to generics?

  1. The issue

Well, it works! But using Split and Sub as replacement to ABC_pre and ABC_post is obviously bad.
I actually tried to create custom pseudo-operation, but failed.

As I create op like this:

my_opset = Opset("com.mydomain", 15)

@script(my_opset)
def joy_of_relu( x:FLOAT ) -> FLOAT:
    y =    op.Relu(x)
    return op.Relu(y)


opsch = joy_of_relu.op_schema

shiny_new_op = Op(
    opset=my_opset, name="relurelu", op_schema=opsch
)

it not work with rewriter, also I tried onnxruntime_extensions.onnx_op

So, if it is possible, it would be great to have example of using rewriter with custom nodes.

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

No branches or pull requests

1 participant