Make use of suppress_stdout_stderr when freeing model (#803)

This commit is contained in:
Pierre Alexandre SCHEMBRI 2023-10-15 19:52:43 +02:00 committed by GitHub
parent a1ac199980
commit 10304d75fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,