Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b069d06

Browse filesBrowse files
authored
1 parent ad963a0 commit b069d06
Copy full SHA for b069d06

File tree

Expand file treeCollapse file tree

1 file changed

+9
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-3
lines changed

‎llama_cpp/llama.py

Copy file name to clipboardExpand all lines: llama_cpp/llama.py
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ class _LlamaModel:
214214
NOTE: For stability it's recommended you use the Llama class instead."""
215215

216216
_llama_free_model = None
217+
# NOTE: this must be "saved" here to avoid exceptions when calling __del__
218+
suppress_stdout_stderr = suppress_stdout_stderr
217219

218220
def __init__(
219221
self,
@@ -237,7 +239,7 @@ def __init__(
237239
)
238240

239241
def __del__(self):
240-
with suppress_stdout_stderr(disable=self.verbose):
242+
with self.suppress_stdout_stderr(disable=self.verbose):
241243
if self.model is not None and self._llama_free_model is not None:
242244
self._llama_free_model(self.model)
243245
self.model = None
@@ -399,6 +401,8 @@ class _LlamaContext:
399401
NOTE: For stability it's recommended you use the Llama class instead."""
400402

401403
_llama_free = None
404+
# NOTE: this must be "saved" here to avoid exceptions when calling __del__
405+
suppress_stdout_stderr = suppress_stdout_stderr
402406

403407
def __init__(
404408
self,
@@ -419,7 +423,7 @@ def __init__(
419423
)
420424

421425
def __del__(self):
422-
with suppress_stdout_stderr(disable=self.verbose):
426+
with self.suppress_stdout_stderr(disable=self.verbose):
423427
if self.ctx is not None and self._llama_free is not None:
424428
self._llama_free(self.ctx)
425429
self.ctx = None
@@ -650,6 +654,8 @@ def default_params():
650654

651655
class _LlamaBatch:
652656
_llama_batch_free = None
657+
# NOTE: this must be "saved" here to avoid exceptions when calling __del__
658+
suppress_stdout_stderr = suppress_stdout_stderr
653659

654660
def __init__(
655661
self, *, n_tokens: int, embd: int, n_seq_max: int, verbose: bool = True
@@ -667,7 +673,7 @@ def __init__(
667673
)
668674

669675
def __del__(self):
670-
with suppress_stdout_stderr(disable=self.verbose):
676+
with self.suppress_stdout_stderr(disable=self.verbose):
671677
if self.batch is not None and self._llama_batch_free is not None:
672678
self._llama_batch_free(self.batch)
673679
self.batch = None

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.