Repository navigation
fix(server): report the expanded media prompt length on the xla-iree loop - #2436
Merged
Merged
Conversation
…loop The OpenXLA serve loop never sent GenerateEvent::Prefill and put the logical prompt length in its result, so an image or audio body reported the placeholder count in usage, in /v1/messages/count_tokens, and in the streaming message_start that #2337 holds until the worker's prefill report. ServeState now keeps one count, the expanded prepared length (the prompt length for text), and sends a single first-token PrefillStats before a request's first Token or its Done, as the batch scheduler does. The Done, the stop-string finish and the zero-budget media finish report the same length. Image families share this path (LLaVA, Gemma 3, Qwen2/2.5/3-VL, Molmo, Youtu-VL), as does Phi4MM image and audio. Tests drive admit, preprocessing and dispatch for text, image and Phi4MM audio/image; the fake Phi4MM producer now expands placeholders. Two stale message assertions in the module are updated to the current error text. On gemma-3-4b-it-4bit with MLXCEL_BACKEND=xla, an image body went from 18 to 277 on count_tokens, usage and message_start, matching the MLX path. Closes #2420
inureyes
force-pushed
the
fix/issue-2420-xla-expanded-prompt-length
branch
from
October 17, 2026 02:14
6a30cb9 to
815a6da
Compare
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.
Closes #2420
The
xla-ireeserve loop never sentGenerateEvent::Prefilland reported the logical (placeholder) prompt length, so a media body'susage,/v1/messages/count_tokensand the streamingmessage_startthat #2415 holds for the prefill report all carried the placeholder count. This makes the loop match the batch scheduler anddocs/llama-server-compat.md.Changes
ServeStatekeeps one count,effective_prefill_len(the expanded prepared length for media, the prompt length for text), and aprefill_reportedflag.ServeState::report_prefillsendsPrefillStats { prompt_tokens, cached_tokens: 0, processed, first_token: true, prompt_ms }once, before the firstTokenor beforeDonewhen the engine finishes with no token (withheld EOS), and stamps the decode state's first-token instant assequence.rsdoes.Done, the stop-string finish and the zero-budget media finish report the expanded length. The count route follows, since the XLA worker answers it with a one-token generation.handle_preprocessed, including the new Molmo (feat(xla): support Molmo sparse additive visual embeddings (#870) #918) and Youtu-VL (feat(xla): add Youtu-VL vision and MLA inference (#872) #919) producers, so they are covered too. So are the DeepStack (Qwen3-VL) and Phi4MM audio/image paths. The disaggregated coordinator stays out of scope, as the issue says.docs/llama-server-compat.mdhas no XLA-specific statement, and its general promise now holds on this loop.Tests
The new and updated tests drive the real
admit, preprocessing anddispatchpath with a fake engine: text getsPrefill(2), the image getsPrefill(5), and Phi4MM audio and image each getPrefill(6), every one sent before itsToken, withDonereporting the same length. They also cover zero-budget image and audio, and a bare EOS finish. The fake Phi4MM producer now expands placeholders. Two existing assertions in this module were already failing on main because the error messages had changed (structuredis nowconstrained decoding, andrefusing text fallbackis nowimage resolution cardinality mismatch). I updated them so the module runs green.server::batch::xla_worker, 15 passed (--release --features cuda,xla-iree,--test-threads=1, under gpu-lock).cargo clippy --release --features cuda,xla-iree --lib --tests -- -D warnings,cargo check --release --features cuda,xla-iree --all-targets,cargo fmt --checkand the repository check scripts pass.Real checkpoint
~/models/mlx/gemma-3-4b-it-4bit,MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=cuda MLXCEL_XLA_CONTEXT_CAPACITY=512 mlxcel-serveron the GB10 (the default 256 capacity refuses a Gemma 3 image). I sent one body (tests/fixtures/test_image.pngplus a short prompt) tocount_tokens, non-streaming and streaming/v1/messages:In every stream
message_startwas the first event, and it was sent once. Phi4MM audio was not run on a real checkpoint (none is present locally), so the fake-producer test covers it.