diff --git a/python/tvm/_ffi/_ctypes/function.py b/python/tvm/_ffi/_ctypes/function.py index ec278bc2045c2b499172c4c51762ac95ca5b2461..189d9964baf596772540de9a63a47e522f593de9 100644 --- a/python/tvm/_ffi/_ctypes/function.py +++ b/python/tvm/_ffi/_ctypes/function.py @@ -165,7 +165,7 @@ class FunctionBase(object): self.is_global = is_global def __del__(self): - if not self.is_global: + if not self.is_global and _LIB is not None: check_call(_LIB.TVMFuncFree(self.handle)) def __call__(self, *args): diff --git a/python/tvm/_ffi/_ctypes/node.py b/python/tvm/_ffi/_ctypes/node.py index 08efc391308481d79b31814a2929f9d4a0b3805a..cb32b83291d11f03ba86788463f699aeec56c476 100644 --- a/python/tvm/_ffi/_ctypes/node.py +++ b/python/tvm/_ffi/_ctypes/node.py @@ -44,7 +44,8 @@ class NodeBase(object): self.handle = handle def __del__(self): - check_call(_LIB.TVMNodeFree(self.handle)) + if _LIB is not None: + check_call(_LIB.TVMNodeFree(self.handle)) def __getattr__(self, name): ret_val = TVMValue()