Skip to content

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 into
spacemit-com:spacemit-mtmdfrom
co-seven:fix/mtmd-hybrid-recurrent-cache-and-tempfile
Jul 7, 2026
Merged

Conversation

@co-seven

@co-seven co-seven commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Two related fixes for the SMT vision multimodal server path:

  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.

@co-seven co-seven changed the title fix(server): fix SMT multimodal crash on hybrid-recurrent models + dr… 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 Jul 6, 2026
@alex-spacemit alex-spacemit requested a review from Copilot July 6, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tools/mtmd/smt-vision-wrapper.h Outdated
Comment thread tools/mtmd/smt-vision-wrapper.cpp
@co-seven co-seven force-pushed the fix/mtmd-hybrid-recurrent-cache-and-tempfile branch from 58c5b1f to 4532ab6 Compare July 7, 2026 02:15
@alex-spacemit alex-spacemit requested a review from Copilot July 7, 2026 03:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread tools/mtmd/smt-vision-wrapper.cpp
…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.
@co-seven co-seven force-pushed the fix/mtmd-hybrid-recurrent-cache-and-tempfile branch from 4532ab6 to 7937b47 Compare July 7, 2026 03:26
@alex-spacemit alex-spacemit requested a review from Copilot July 7, 2026 04:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@alex-spacemit alex-spacemit merged commit 21379f9 into spacemit-com:spacemit-mtmd Jul 7, 2026
13 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants