Skip to content

Commit f685aa4

Browse files
authored
Fix "'NoneType' object has no attribute 'cast'" error when model is freed (#117)
1 parent 25ee75e commit f685aa4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

rwkv/rwkv_cpp_shared_library.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def __init__(self, shared_library_path: str):
9090
self.library.rwkv_get_system_info_string.argtypes = []
9191
self.library.rwkv_get_system_info_string.restype = ctypes.c_char_p
9292

93+
self.nullptr = ctypes.cast(0, ctypes.c_void_p)
94+
9395
def rwkv_init_from_file(self, model_file_path: str, thread_count: int) -> RWKVContext:
9496
"""
9597
Loads the model from a file and prepares it for inference.
@@ -232,7 +234,7 @@ def rwkv_free(self, ctx: RWKVContext) -> None:
232234

233235
self.library.rwkv_free(ctx.ptr)
234236

235-
ctx.ptr = ctypes.cast(0, ctypes.c_void_p)
237+
ctx.ptr = self.nullptr
236238

237239
def rwkv_quantize_model_file(self, model_file_path_in: str, model_file_path_out: str, format_name: str) -> None:
238240
"""

0 commit comments

Comments
 (0)