diff --git a/CHANGELOG.md b/CHANGELOG.md index 853a7ca37..cc48609da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - fix(example): retain recurrent state for server MTP rollback - feat: update llama.cpp to ggml-org/llama.cpp@adb55e514 - fix(server): show falsey defaults in CLI help by @cupkk in #2355 +- fix: release multimodal contexts when closing Llama by @Anai-Guo in #2343 ## [0.3.34] diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index 4f41c2eb7..62e236415 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -9,7 +9,6 @@ import string from datetime import datetime -from contextlib import ExitStack from typing import ( Any, Dict, @@ -2779,7 +2778,6 @@ def __init__(self, clip_model_path: str, verbose: bool = True): self.clip_model_path = clip_model_path self.verbose = verbose self._mtmd_cpp = mtmd_cpp - self._exit_stack = ExitStack() self.mtmd_ctx: Optional[mtmd_cpp.mtmd_context_p] = None if not os.path.exists(clip_model_path): @@ -2825,7 +2823,7 @@ def mtmd_free(): self._mtmd_cpp.mtmd_free(self.mtmd_ctx) self.mtmd_ctx = None - self._exit_stack.callback(mtmd_free) + llama_model._stack.callback(mtmd_free) def load_image(self, image_url: str) -> bytes: return self._load_image(image_url) @@ -3278,7 +3276,6 @@ def __init__( self.verbose = verbose self.use_gpu = use_gpu self._mtmd_cpp = mtmd_cpp - self._exit_stack = ExitStack() self.mtmd_ctx: Optional[mtmd_cpp.mtmd_context_p] = None if not os.path.exists(clip_model_path): @@ -3321,7 +3318,7 @@ def mtmd_free(): self._mtmd_cpp.mtmd_free(self.mtmd_ctx) self.mtmd_ctx = None - self._exit_stack.callback(mtmd_free) + llama_model._stack.callback(mtmd_free) def load_image(self, image_url: str) -> bytes: return self._load_image(image_url)