Vision/multimodal silently dropped with use_tokenizer_template on the python backends (sglang, vllm): images reach the engine but the prompt carries no media placeholder
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
調査の方向性
backend/python/sglang/backend.py と backend/python/vllm/backend.py、特に _messages_to_dicts() と _build_prompt() を読み、その後 core/http/middleware/request.go、core/schema/message.go、backend.proto を調べてください。tokenizer-template リクエストを再現し、sglang と vLLM が転送された画像に対応付けられたメディアプレースホルダーを受け取ることを確認してください。一方、テキストのみのリクエストには影響がないことも確認してください。
索引モデルが issue の本文から書いたものです。
説明
LocalAI version
v4.7.1, image localai/localai:v4.7.1-nvidia-l4t-arm64-cuda-13.
Backends cuda13-nvidia-l4t-arm64-sglang (sglang 0.5.17) and cuda13-nvidia-l4t-arm64-vllm (vLLM 0.24.0), both from the gallery.
Environment, CPU architecture, OS, and Version
NVIDIA DGX Spark (GB10, Blackwell sm_121), arm64, Ubuntu 24.04, CUDA 13, driver 595.71.05, Docker with the NVIDIA runtime.
Describe the bug
For a model configured with template.use_tokenizer_template: true, an image sent as an image_url content part is silently ignored. No error, no warning — the model simply answers as if no image had been attached. The same model, image and prompt work correctly when the engine is driven directly (standalone sglang.launch_server and its own /v1/chat/completions), so it is neither the model nor the engine.
The images do reach the backend. What does not reach it is the media placeholder in the prompt:
core/http/middleware/request.godecodes theimage_urlparts intoMessages[i].StringImages, and then — forUseTokenizerTemplate— deliberately writes only the text back intoStringContent:
// When the backend handles templating itself (UseTokenizerTemplate),
// it also injects media markers server-side (see
// oaicompat_chat_params_parse in llama.cpp). ...
if config.TemplateConfig.UseTokenizerTemplate {
input.Messages[i].StringContent = textContent
} else {
input.Messages[i].StringContent, _ = templates.TemplateMultiModal(...)
}
That assumption holds for llama.cpp's server, which injects the markers itself. It does not hold for the python backends: they call tokenizer.apply_chat_template() on plain string content, and a chat template only emits vision tokens when the content is a list of parts.
-
core/schema/message.go(Messages.ToProto()) then drops the image parts entirely and keeps only the concatenated.text. -
message Messageinbackend.protohas no media field at all, so images can only travel out-of-band in the globalPredictOptions.Images— the image↔message association is lost on the wire. -
In
backend/python/sglang/backend.py,_messages_to_dicts()builds{"role": …, "content": msg.content or ""}and_build_prompt()renders that throughapply_chat_template(). For a Qwen3.5-VL model the rendered prompt therefore contains no<|vision_start|><|image_pad|><|vision_end|>. -
The images themselves are forwarded correctly —
backend.pydoesimage_data = list(request.Images)→llm.async_generate(..., image_data=image_data). But sglang's multimodal processor locates images by scanning the prompt for the model's image token (sglang/srt/multimodal/processors/qwen_vl.py:image_token="<|vision_start|><|image_pad|><|vision_end|>"plus the matching regex). With no placeholder present nothing is split out andimage_datais discarded without a message.
backend/python/vllm/backend.py has the identical gap: its _messages_to_dicts() is the same string-content version and apply_chat_template() is applied the same way. Its load_image() / multi_modal_data / LimitImagePerPrompt machinery only carries the pixels, not the placeholder.
Rendering the model's own chat template confirms the mechanism directly (Qwen3.5-VL template, jinja2, no model load):
| message content | rendered user turn |
|---|---|
"Wie hoch steht das Wasser?" (what the backend builds today) |
<|im_start|>user\nWie hoch steht das Wasser?<|im_end|> — no placeholder |
[{"type":"image"},{"type":"text","text":"Wie hoch steht das Wasser?"}] |
<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>Wie hoch steht das Wasser?<|im_end|> |
To Reproduce
- Serve any VLM through the sglang backend with the tokenizer template:
name: vlm
backend: cuda13-nvidia-l4t-arm64-sglang
parameters:
model: <a Qwen3.5-VL-family checkpoint>
template:
use_tokenizer_template: true
engine_args:
model_path: /models/<checkpoint>
trust_remote_code: true
POST /v1/chat/completionswith animage_urlcontent part (data URI) and a question about the image.- → the model replies that no image was attached. HTTP 200, nothing in the log.
- Control: send the same request to a standalone
python3 -m sglang.launch_serverwith the same checkpoint → correct answer about the image.
Expected behavior
The image is coupled to the prompt and the model sees it — with use_tokenizer_template: true, on the sglang and vllm backends, the same way it already works on llama-cpp.
Additional context
Two ways to fix it, and they are not mutually exclusive:
(a) Backend-local, small, no protocol change. In _build_prompt(), rebuild the OpenAI content parts for the last user message from request.Images / request.Videos before templating, so the chat template emits the model's own placeholders. The pixels keep travelling via image_data / multi_modal_data:
n_img = len(request.Images) if request.Images else 0
n_vid = len(request.Videos) if request.Videos else 0
if n_img or n_vid:
idx = next((i for i in range(len(messages_dicts) - 1, -1, -1)
if messages_dicts[i].get("role") == "user"), None)
if idx is not None:
text = messages_dicts[idx].get("content") or ""
parts = [{"type": "image"}] * n_img + [{"type": "video"}] * n_vid
if text:
parts.append({"type": "text", "text": text})
messages_dicts[idx]["content"] = parts
The existing except TypeError around apply_chat_template() needs widening to except Exception so that a text-only template falls back to string content instead of failing the request. Text-only requests are unaffected — with no images the whole path is a no-op. The same patch applies verbatim to the vllm backend. This covers every single-image and last-turn request, which is effectively all real vision traffic.
(b) Protocol-level, complete. Add repeated string images (and videos/audios) to message Message in backend.proto, stop discarding the parts in Messages.ToProto(), and let the backends read them per message. This is the only way to get multi-turn conversations with images in different turns right, and it fixes every python backend at once.
Happy to send a PR for (a) — that is the change we are running locally.
Related: #10945 (same class of failure — marker↔bitmap coupling — but on the llama-cpp/mtmd path).
- 主要言語
- Go
- スター
- 49.2k
- フォーク
- 4.5k
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 340
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
mudler/LocalAI のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
mudler/LocalAI#11995 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
mudler/LocalAI#11991 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
fish-speech: make compile:true usable on Blackwell sm_121 by honouring the CUDA toolkit's ptxasオープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
mudler/LocalAI#11348 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
feat: add automatic MCP transport selection for 2024-11-05 / 2025-03-26 / 2025-06-18 vs 2025-11-25オープンenhancement
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
mudler/LocalAI#12262 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 3 日以内に返信
似ている issue
-
Remove CAAPFオープンkind/chore kind/cleanup needs-area
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
rancher/turtles#2848 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
priority: low 🌱 type: enhancement 💅🏼
難易度 2/5 半日 初心者へのやさしさ 84/100
nebari-dev/llm-serving-pack#199 ·
メンテナーはふだん 3 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
kedacore/keda#8225 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信