Skip to content

Define a custom op with a custom name #1985

Open
@Johansmm

Description

@Johansmm

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions