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

Define a custom op with a custom name #1985

Open
Johansmm opened this issue Dec 26, 2024 · 1 comment
Open

Define a custom op with a custom name #1985

Johansmm opened this issue Dec 26, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Johansmm
Copy link

I would like to know if it is possible to define a custom operator with a different name that its function name.

Example:

import onnx

# We use ONNX opset 15 to define the function below.
from onnxscript import FLOAT, script
from onnxscript import opset15 as op


@script(op_type="MY_NEW_NAME_OP")
def custom_op(X):
    return 5*X


def sample_model(X: FLOAT[64, 128]) -> FLOAT[64, 128]:
    return custom_op(X)


# onnx_model is an in-memory ModelProto
onnx_model = sample_model.to_model_proto()

# Check node op_type
assert model.graph.node[0].op_type == "MY_NEW_NAME_OP"
@justinchuby justinchuby added the enhancement New feature or request label Dec 27, 2024
@justinchuby
Copy link
Collaborator

Could you share your usage? When would this be useful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants