From 10304d75fc84b6819ffdcc19712d6e5272cbfd18 Mon Sep 17 00:00:00 2001 From: Pierre Alexandre SCHEMBRI Date: Sun, 15 Oct 2023 19:52:43 +0200 Subject: [PATCH] Make use of suppress_stdout_stderr when freeing model (#803) --- llama_cpp/llama.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 434d824..8951bed 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -1655,7 +1655,7 @@ class Llama: ) return self._convert_completion_to_chat(completion_or_chunks, stream=stream) # type: ignore - def __del__(self): + def _free_model(self): if hasattr(self, "model") and self.model is not None: llama_cpp.llama_free_model(self.model) self.model = None @@ -1663,6 +1663,13 @@ class Llama: llama_cpp.llama_free(self.ctx) self.ctx = None + def __del__(self): + if self.verbose: + self._free_model() + else: + with suppress_stdout_stderr(): + self._free_model() + def __getstate__(self): return dict( model_path=self.model_path,