Skip to content

fix(python): fix VLM multi-turn image guard and test message order#1130

Merged
Mengsheng Wu (mengshengwu) merged 2 commits into
mainfrom
worktree-fix-vlm-ci-tests
Jul 3, 2026
Merged

fix(python): fix VLM multi-turn image guard and test message order#1130
Mengsheng Wu (mengshengwu) merged 2 commits into
mainfrom
worktree-fix-vlm-ci-tests

Conversation

@mengshengwu

@mengshengwu Mengsheng Wu (mengshengwu) commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Closes #1131

What

Two test-sdk-qdc / llama_cpp_vlm failures on X Elite Windows (CI run 28492301153):

test_multi_turn_without_reset — raised ValueError: messages reference image content but generate(images=[...]) is empty. _messages_have_modality scanned the entire conversation history; the second turn passed the full history (containing the first-turn image block) to apply_chat_template, setting _last_template_has_image=True. The guard then blocked generate(images=[]), which is the correct call for a follow-up turn whose image is already in the KV cache.

test_quality_keywords[npu] — image content order in _vlm_prompt was [image, text]. The C SDK reference (build_vlm_prompt in benchmark.c, PR #1112) uses [text, image] order.

Changes

  • modeling.py: _messages_have_modality now checks only the last user message instead of the full history. Prior-turn media is already in the KV cache and must not be re-supplied.
  • test_llama_cpp_vlm.py: align _vlm_prompt content order to [text, image], matching build_vlm_prompt in benchmark.c.
  • test_error_messages.py: three unit regressions covering the modality-scope fix (ignore prior turns, detect current turn, empty list).

_messages_have_modality scanned the entire conversation history, so the
second turn of a multi-turn session incorrectly raised ValueError when
generate(images=[]) was called with no new image (image already in the
KV cache).  Only the last user message carries new media; check that
instead.

Also align _vlm_prompt message content order with the C SDK reference
(build_vlm_prompt in benchmark.c): text-first, then image, matching
how vlm_message_to_common_chat_msg assembles the mtmd marker+text
content.

Signed-off-by: Mengsheng Wu <mengshengwu@outlook.com>
Cover the three predicate cases exercised by the fix:

- prior-turn image/audio blocks must not gate the current text-only turn
- current-turn media still trips the guard
- empty message list is a no-op

Signed-off-by: Mengsheng Wu <mengshengwu@outlook.com>
@mengshengwu Mengsheng Wu (mengshengwu) merged commit 95abcb6 into main Jul 3, 2026
28 checks passed
@mengshengwu Mengsheng Wu (mengshengwu) deleted the worktree-fix-vlm-ci-tests branch July 3, 2026 12:43
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.

python: multi-turn VLM raises on generate() when prior turn had media

1 participant