8000 Fix #891 by kddubey · Pull Request #952 · abetlen/llama-cpp-python · GitHub
[go: up one dir, main page]

Skip to content

Fix #891 #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ class _LlamaModel:
NOTE: For stability it's recommended you use the Llama class instead."""

_llama_free_model = None
# NOTE: this must be "saved" here to avoid exceptions when calling __del__
suppress_stdout_stderr = suppress_stdout_stderr

def __init__(
self,
Expand All @@ -237,7 +239,7 @@ def __init__(
)

def __del__(self):
with suppress_stdout_stderr(disable=self.verbose):
with self.suppress_stdout_stderr(disable=self.verbose):
if self.model is not None and self._llama_free_model is not None:
self._llama_free_model(self.model)
self.model = None
Expand Down Expand Up @@ -399,6 +401,8 @@ class _LlamaContext:
NOTE: For stability it's recommended you use the Llama class instead."""

_llama_free = None
# NOTE: this must be "saved" here to avoid exceptions when calling __del__
suppress_stdout_stderr = suppress_stdout_stderr

def __init__(
self,
Expand All @@ -419,7 +423,7 @@ def __init__(
)

def __del__(self):
with suppress_stdout_stderr(disable=self.verbose):
with self.suppress_stdout_stderr(disable=self.verbose):
if self.ctx is not None and self._llama_free is not None:
self._llama_free(self.ctx)
self.ctx = None
Expand Down Expand Up @@ -650,6 +654,8 @@ def default_params():

class _LlamaBatch:
_llama_batch_free = None
# NOTE: this must be "saved" here to avoid exceptions when calling __del__
suppress_stdout_stderr = suppress_stdout_stderr

def __init__(
self, *, n_tokens: int, embd: int, n_seq_max: int, verbose: bool = True
Expand All @@ -667,7 +673,7 @@ def __init__(
)

def __del__(self):
with suppress_stdout_stderr(disable=self.verbose):
with self.suppress_stdout_stderr(disable=self.verbose):
if self.batch is not None and self._llama_batch_free is not None:
self._llama_batch_free(self.batch)
self.batch = None
Expand Down
0