8000 llama: fix exception in Llama.__del__ by cebtenzzre · Pull Request #846 · abetlen/llama-cpp-python · GitHub
[go: up one dir, main page]

Skip to content

llama: fix exception in Llama.__del__ #846

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 1, 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: 7 additions & 5 deletions llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,12 +1637,14 @@ def create_chat_completion(
)
return self._convert_completion_to_chat(completion_or_chunks, stream=stream) # type: ignore

def _free_model(self):
if hasattr(self, "model") and self.model is not None:
llama_cpp.llama_free_model(self.model)
def _free_model(self, *, _lfree_model=llama_cpp._lib.llama_free_model, _free=llama_cpp._lib.llama_free):
model = getattr(self, 'model', None)
if model is not None:
_lfree_model(model)
self.model = None
if hasattr(self, "ctx") and self.ctx is not None:
llama_cpp.llama_free(self.ctx)
ctx = getattr(self, 'ctx', None)
if ctx is not None:
_free(ctx)
self.ctx = None

def __del__(self):
Expand Down
0