diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 66c76c9..b52a398 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -1503,10 +1503,10 @@ class Llama: return self._convert_text_completion_to_chat(completion) def __del__(self): - if self.model is not None: + if hasattr(self, "model") and self.model is not None: llama_cpp.llama_free_model(self.model) self.model = None - if self.ctx is not None: + if hasattr(self, "ctx") and self.ctx is not None: llama_cpp.llama_free(self.ctx) self.ctx = None