Repository navigation
Commit 9dd3950
* fix(llama): release a vision chat handler's mtmd context on close (#2342)
`Llama.close()` tore down the model and its context but left the chat
handler's `_exit_stack` untouched, so the mtmd/clip context it built from
that model was never freed.
Handlers routinely outlive the `Llama` that initialized them -- callers
construct one handler and reuse it across loads -- and
`_init_mtmd_context()` returns early while `mtmd_ctx` is set. After the
first `close()` the handler therefore kept a context bound to an
already-freed model and handed it back on the next load, where it
surfaces as a null `mtmd_ctx` on the C++ side.
Register the handler's exit stack on the Llama's `_stack`. It unwinds
LIFO, so the mtmd context is released ahead of the model teardown
registered earlier in `__init__`, and `mtmd_free` resets `mtmd_ctx` to
`None` so the next load re-initializes cleanly. Duck-typed on
`_exit_stack`, which both `Llava15ChatHandler` and `MTMDChatHandler`
(and every subclass) expose.
* fix: bind multimodal context cleanup to model
---------
Co-authored-by: Anai Guo <antai12232931@anaiguo.com>
Co-authored-by: abetlen <abetlen@gmail.com>
1 parent d8a4a1e commit 9dd3950
2 files changed
Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
2779 | 2778 | | |
2780 | 2779 | | |
2781 | 2780 | | |
2782 | | - | |
2783 | 2781 | | |
2784 | 2782 | | |
2785 | 2783 | | |
| |||
2825 | 2823 | | |
2826 | 2824 | | |
2827 | 2825 | | |
2828 | | - | |
| 2826 | + | |
2829 | 2827 | | |
2830 | 2828 | | |
2831 | 2829 | | |
| |||
3278 | 3276 | | |
3279 | 3277 | | |
3280 | 3278 | | |
3281 | | - | |
3282 | 3279 | | |
3283 | 3280 | | |
3284 | 3281 | | |
| |||
3321 | 3318 | | |
3322 | 3319 | | |
3323 | 3320 | | |
3324 | | - | |
| 3321 | + | |
3325 | 3322 | | |
3326 | 3323 | | |
3327 | 3324 | | |
| |||
0 commit comments