tvm_ffi.register_object

tvm_ffi.register_object#

tvm_ffi.register_object(type_key=None)[source]#

Register object type.

Parameters:

type_key (str | None, default: None) – The type key of the node. It requires type_key to be registered already on the C++ side. If not specified, the class name will be used.

Return type:

Callable[[TypeVar(_T, bound= type)], TypeVar(_T, bound= type)]

Notes

All Object subclasses get __slots__ = () by default via the metaclass, preventing per-instance __dict__. To opt out and allow arbitrary instance attributes, declare __slots__ = ("__dict__",) explicitly in the class body:

@tvm_ffi.register_object("test.MyObject")
class MyObject(Object):
    __slots__ = ("__dict__",)

Examples

The following code registers MyObject using type key “test.MyObject”, if the type key is already registered on the C++ side.

@tvm_ffi.register_object("test.MyObject")
class MyObject(Object):
    pass