Structured error classes in TVM.

Each error class takes an error message as its input. See the example sections for for suggested message conventions. To make the code more readable, we recommended developers to copy the examples and raise errors with the same message convention.

exception tvm.error.InternalError(msg)

Internal error in the system.


// Example code C++
LOG(FATAL) << "InternalError: internal error detail.";
# Example code in python
raise InternalError("internal error detail")
exception tvm.error.OpAttributeInvalid

Attribute value is invalid when taking in a frontend operator.


raise OpAttributeInvalid(
    "Value {} in attribute {} of operator {} is not valid".format(
        value, attr_name, op_name))
exception tvm.error.OpAttributeRequired

Required attribute is not found.


raise OpAttributeRequired(
    "Required attribute {} not found in operator {}".format(
        attr_name, op_name))
exception tvm.error.OpAttributeUnimplemented

Attribute is not supported in a certain frontend.


raise OpAttributeUnimplemented(
    "Attribute {} is not supported in operator {}".format(
        attr_name, op_name))
exception tvm.error.OpError

Base class of all operator errors in frontends.

exception tvm.error.OpNotImplemented

Operator is not implemented.


raise OpNotImplemented(
    "Operator {} is not supported in {} frontend".format(
        missing_op, frontend_name))
exception tvm.error.TVMError

Default error thrown by TVM functions.

TVMError will be raised if you do not give any error type specification,

tvm.error.register_error(func_name=None, cls=None)

Register an error class so it can be recognized by the ffi error handler.

  • func_name (str or function or class) – The name of the error function.
  • cls (function) – The function to create the class

fregister – Register function if f is not specified.

Return type:



class MyError(RuntimeError):

err_inst = tvm.error.create_ffi_error("MyError: xyz")
assert isinstance(err_inst, MyError)