From 3757328b703b2cd32dcbd5853271e3a8c8599fe7 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Wed, 8 May 2024 22:16:18 -0400 Subject: [PATCH] fix: free last image embed in llava chat handler --- llama_cpp/llama_chat_format.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index beff6ca..84de989 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -2615,6 +2615,11 @@ class Llava15ChatHandler: if self._last_image_embed is not None and self._last_image_hash is not None and hash(image_bytes) == self._last_image_hash: return self._last_image_embed with suppress_stdout_stderr(disable=self.verbose): + # Free the previous image embed + if self._last_image_embed is not None: + self._llava_cpp.llava_image_embed_free(self._last_image_embed) + self._last_image_embed = None + self._last_image_hash = None embed = ( self._llava_cpp.llava_image_embed_make_with_bytes( self.clip_ctx,