10000 Make use of suppress_stdout_stderr when freeing model (#803) · NickAlgra/llama-cpp-python@10304d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10304d7

Browse files
authored
Make use of suppress_stdout_stderr when freeing model (abetlen#803)
1 parent a1ac199 commit 10304d7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llama_cpp/llama.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,14 +1655,21 @@ def create_chat_completion(
16551655
)
16561656
return self._convert_completion_to_chat(completion_or_chunks, stream=stream) # type: ignore
16571657

1658-
def __del__(self):
1658+
def _free_model(self):
16591659
if hasattr(self, "model") and self.model is not None:
16601660
llama_cpp.llama_free_model(self.model)
16611661
self.model = None
16621662
if hasattr(self, "ctx") and self.ctx is not None:
16631663
llama_cpp.llama_free(self.ctx)
16641664
self.ctx = None
16651665

1666+
def __del__(self):
1667+
if self.verbose:
1668+
self._free_model()
1669+
else:
1670+
with suppress_stdout_stderr():
1671+
self._free_model()
1672+
16661673
def __getstate__(self):
16671674
return dict(
16681675
model_path=self.model_path,

0 commit comments

Comments
 (0)
0