Decorator¶

onnxscript.script(opset: Opset | None = None, default_opset: Opset | None = None, **kwargs: Any) Callable[[Callable], OnnxFunction][source]¶

Main decorator. Declares a function as an onnx function.

Parameters:
  • opset – Opset the function belongs to (see Opsets).

  • default_opset – Opset to use for operators not in the function’s opset.

  • kwargs – Additional keyword arguments.

Returns:

an instance of onnxscript.values.OnnxFunction

Example:

@script()
def log2(x):
    one = op.Constant(value=make_tensor('one', TensorProto.FLOAT, [1], [1]))
    return op.Div(op.Log(x), op.CastLike(op.Log(cst), x))

Or:

from onnxscript.onnx_opset import opset16

@script(opset16)
def log2(x):
    one = op.Constant(value=make_tensor('one', TensorProto.FLOAT, [1], [1]))
    return op.Div(op.Log(x), op.CastLike(op.Log(cst), x))