fix(server): fix SMT multimodal crash on hybrid-recurrent models + drop temp-file round-trip Two related fixes for the SMT vision multimodal server path#18
Merged
alex-spacemit merged 1 commit intoJul 7, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes two issues in the SMT multimodal server path: (1) avoids a crash when prompt-cache reuse interacts with hybrid/recurrent multimodal models, and (2) removes an unnecessary disk temp-file round-trip when feeding SMT vision tensors into the ONNX runtime.
Changes:
- Disable prompt-cache reuse (LCP-based slot selection + common-prefix reuse) for hybrid/recurrent multimodal models to prevent seq rollback aborts.
- Add an in-memory SMT vision encode path and switch the server to feed preprocessed tensor bytes directly to ONNX (no temp file).
- Bump version to 0.1.6.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| VERSION_NUMBER | Version bump to 0.1.6. |
| tools/server/server-smt-vision.cpp | Uses in-memory SMT vision encoding instead of writing/reading a temp file. |
| tools/server/server-context.cpp | Gates prompt-cache reuse off for hybrid/recurrent multimodal models to avoid recurrent-state rollback aborts. |
| tools/mtmd/smt-vision-wrapper.h | Exposes encode_image_mem() API for in-memory tensor ingestion. |
| tools/mtmd/smt-vision-wrapper.cpp | Implements in-memory tensor ingestion and keeps a file-path wrapper delegating to it. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
58c5b1f to
4532ab6
Compare
…op temp-file round-trip
Two related fixes for the SMT vision multimodal server path, plus a version bump.
1. Prompt-cache reuse crash on hybrid/recurrent multimodal models
(e.g. Qwen3.5VL). A multi-turn chat answered turn 1 but aborted on
turn 2 with:
common.cpp:1495: failed to remove sequence N with p0=M, p1=-1
Root cause: the text prompt-cache reuse path (LCP-similarity slot
selection + get_common_prefix) was applied to multimodal requests on
hybrid-recurrent models. Their llama_memory_recurrent::seq_rm() cannot
partially remove a tail range outside the bounded per-token snapshot
window (n_rs_seq), so the reuse-computed KV position makes seq_rm
return false -> GGML_ABORT. Pure-attention multimodal models (e.g.
LLaVA-style fastvlm) are unaffected. Gate prompt-cache reuse off
precisely for multimodal AND hybrid/recurrent models
(prompt_cache_reuse_unsafe()), so those prompts are fully re-processed
while pure-attention multimodal models keep their cache reuse.
2. Remove the pointless temp-file round-trip in SMT vision encode. The
preprocessed float32 tensor was written to /tmp/llama-server-smt-XXXXXX
and immediately read back into memory by the ONNX engine. Feed the
in-memory blob directly (encode_image_mem / set_input_tensor_from_memory).
This removes a per-image disk write+read and fixes intermittent
"failed to write temp file" failures on boards whose root (/tmp)
partition is full. The file-path API is kept as a thin wrapper for
other callers; the audio path is unchanged.
3. Bump VERSION_NUMBER 0.1.5 -> 0.1.6.
4532ab6 to
7937b47
Compare
21379f9
into
spacemit-com:spacemit-mtmd
13 of 18 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related fixes for the SMT vision multimodal server path:
Prompt-cache reuse crash on hybrid/recurrent multimodal models (e.g. Qwen3.5VL). A multi-turn chat answered turn 1 but aborted on turn 2 with: common.cpp:1495: failed to remove sequence N with p0=M, p1=-1 Root cause: the text prompt-cache reuse path (LCP-similarity slot selection + get_common_prefix) was applied to multimodal requests on hybrid-recurrent models. Their llama_memory_recurrent::seq_rm() cannot partially remove a tail range outside the bounded per-token snapshot window (n_rs_seq), so the reuse-computed KV position makes seq_rm return false -> GGML_ABORT. Pure-attention multimodal models (e.g. LLaVA-style fastvlm) are unaffected. Gate prompt-cache reuse off precisely for multimodal AND hybrid/recurrent models (prompt_cache_reuse_unsafe()), so those prompts are fully re-processed while pure-attention multimodal models keep their cache reuse.
Remove the pointless temp-file round-trip in SMT vision encode. The preprocessed float32 tensor was written to /tmp/llama-server-smt-XXXXXX and immediately read back into memory by the ONNX engine. Feed the in-memory blob directly (encode_image_mem / set_input_tensor_from_memory). This removes a per-image disk write+read and fixes intermittent "failed to write temp file" failures on boards whose root (/tmp) partition is full. The file-path API is kept as a thin wrapper for other callers; the audio path is unchanged.