tvm_ffi.register_object#
- tvm_ffi.register_object(type_key=None, *, init=True)[source]#
Register object type.
- Parameters:
type_key (
str|None, default:None) – The type key of the node. It requirestype_keyto be registered already on the C++ side. If not specified, the class name will be used.init (
bool, default:True) – If True (default), install__init__from the C++__ffi_init__TypeAttrColumn when available, or a TypeError guard forObjectsubclasses that lack one. Set to False when a subsequent decorator (e.g.@c_class) will handle__init__installation.
- Return type:
Callable[[TypeVar(_T, bound=type)],TypeVar(_T, bound=type)]
Notes
All
Objectsubclasses 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