Skip to content

fix: clean up chat handler resources in Llama.close() - #2353

Open
JingliangGao wants to merge 1 commit into
abetlen:mainfrom
JingliangGao:fix/chat-handler-close-cleanup
Open

fix: clean up chat handler resources in Llama.close()#2353
JingliangGao wants to merge 1 commit into
abetlen:mainfrom
JingliangGao:fix/chat-handler-close-cleanup

Conversation

@JingliangGao

Copy link
Copy Markdown

When a vision model's chat_handler (e.g. Llava15ChatHandler, Qwen2VLChatHandler) is passed to Llama(), its _exit_stack holds C-level resources (mtmd_ctx). Calling Llama.close() previously skipped this cleanup, so reloading a second model would crash with a null pointer because the old mtmd_ctx was still alive.

Now close() checks for _exit_stack or a close() method on chat_handler and calls it before closing the main ExitStack.

When a vision model's chat_handler (e.g. Llava15ChatHandler, Qwen2VLChatHandler)
is passed to Llama(), its _exit_stack holds C-level resources (mtmd_ctx).
Calling Llama.close() previously skipped this cleanup, so reloading a second
model would crash with a null pointer because the old mtmd_ctx was still alive.

Now close() checks for _exit_stack or a close() method on chat_handler and
calls it before closing the main ExitStack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant