check_op_params

Description

Wraps an operator definition function and checks operator inputs, outputs, attributes, and kernel names.

Prototype

check_op_params(*type_args, **type_kwargs)

Parameters

Parameter

Description

type_args

List of variable-length parameters. For value range, see Input and Output Parameters, attributes, and Kernel Name.

type_kwargs

Reserved.

  • Inputs and Outputs
    Table 1 Input and output verification

    Value

    Description

    REQUIRED_INPUT

    Indicates that this input is required for the operator definition function.

    Common verification includes:

    • Whether it is a dictionary input.
    • Whether the dictionary contains:

      OpParamInfoKey.SHAPE, OpParamInfoKey.FORMAT, OpParamInfoKey.ORI_SHAPE, OpParamInfoKey.ORI_FORMAT, and OpParamInfoKey.DTYPE

      OpParamInfoKey describes the members of OpParamInfoKey.

    • Whether shape is a list or tuple and whether the dims in the shape are ints. 0 ≤ Rank ≤ 8, 0 ≤ Each dim ≤ 2**31, and 0 ≤ Shape size ≤ 2**31.
    • Whether dtype is one of the following: int8, int16, int32, int64, float16, float32, and float64.
    • Whether format is a member defined in TensorFormat.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_INPUT

    Indicates that this input is optional for the operator definition function.

    If it is set to None, its verification rule is the same as that of REQUIRED_INPUT.

    If the verification fails, the message "RuntimeError" is thrown.

    DYNAMIC_INPUT

    Indicates that this input is dynamic for the operator definition function.

    Must be a list or tuple. Each element in the list or tuple must meet the REQUIRED_INPUT verification rule.

    If the verification fails, a verification failure message is thrown.

    REQUIRED_OUTPUT

    Indicates that this output is required for the operator definition function.

    Its verification rule is the same as that of REQUIRED_INPUT.

    OPTION_OUTPUT

    Indicates that this output is optional for the operator definition function.

    Its verification rule is the same as that of OPTION_INPUT.

    DYNAMIC_OUTPUT

    Indicates that this output is optional for the operator definition function.

    Its verification rule is the same as that of DYNAMIC_INPUT.

  • Attributes
    Table 2 Attribute verification

    Value

    Description

    REQUIRED_ATTR_INT

    Indicates that this operator attribute is required in the operator definition function. Must be of type int64.

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_FLOAT

    Indicates that this operator attribute is required in the operator definition function. Must be of type float32.

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_STR

    Indicates that this operator attribute is required in the operator definition function. Must be of type string.

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_BOOL

    Indicates that this operator attribute is required in the operator definition function. Must be of type bool.

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_TYPE

    Indicates that this operator attribute is required in the operator definition function. Must be of type string, and the value range is ["int8", "int16", "int32", "int64", "float16", "float32", "float64"].

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_LIST_INT

    Indicates that this operator attribute is required in the operator definition function. Must be a list or tuple of ints.

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_LIST_FLOAT

    Indicates that this operator attribute is required in the operator definition function. Must be of a list or tuple of floats.

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_LIST_BOOL

    Indicates that this operator attribute is required in the operator definition function. Must be of a list or tuple of bools.

    If the verification fails, the message "RuntimeError" is thrown.

    REQUIRED_ATTR_LIST_LIST_INT

    Indicates that this operator attribute is required in the operator definition function. Must be a 2D list or tuple of ints.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_INT

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be an int.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_FLOAT

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be a float32.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_STR

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be a string.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_BOOL

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be a bool.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_TYPE

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be of type string and the value range is ["int8", "int16", "int32", "int64", "float16", "float32", "float64"].

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_LIST_INT

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be a list or tuple of int64s.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_LIST_FLOAT

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be a list or tuple of floats.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_LIST_BOOL

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be a list or tuple of bools.

    If the verification fails, the message "RuntimeError" is thrown.

    OPTION_ATTR_LIST_LIST_INT

    Indicates that this operator attribute is optional in the operator definition function.

    • The value can be None.
    • If the value is not None, the value must be a 2D list or tuple of int64s.

    If the verification fails, the message "RuntimeError" is thrown.

  • KERNEL_NAME

    Indicates the kernel name of the operator in the operator definition function. Allows only [A-Za-z_][A-Za-z0-9_] and contains a maximum of 200 characters.

    If the verification fails, the message "RuntimeError" is thrown.

Returns

None. If the verification fails, the message "RuntimeError" is thrown.

Restrictions

None

Example

@check_op_params(REQUIRED_INPUT, REQUIRED_OUTPUT, REQUIRED_ATTR_STR, KERNEL_NAME)
def sample_op(x, y, attr_a, kernel_name):

Calls the wrapper function check_op_params to verify the arguments of the operator definition function sample_op.

  • The argument x must meet the requirements of REQUIRED_INPUT as described in Inputs and Outputs.
  • The argument y must meet the requirements of REQUIRED_OUTPUT as described in Inputs and Outputs.
  • The argument attr_a must meet the requirements of REQUIRED_ATTR_STR as described in Attributes.
  • The argument kernel_name must meet the requirements as described in Kernel Name.