Skip to content

fix(server): report the expanded media prompt length on the xla-iree loop - #2436

Merged
inureyes merged 2 commits into
mainfrom
fix/issue-2420-xla-expanded-prompt-length
Oct 17, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/issue-2420-xla-expanded-prompt-length

Conversation

@inureyes

Copy link
Copy Markdown
Member

Closes #2420

The xla-iree serve loop never sent GenerateEvent::Prefill and reported the logical (placeholder) prompt length, so a media body's usage, /v1/messages/count_tokens and the streaming message_start that #2415 holds for the prefill report all carried the placeholder count. This makes the loop match the batch scheduler and docs/llama-server-compat.md.

Changes

  • ServeState keeps one count, effective_prefill_len (the expanded prepared length for media, the prompt length for text), and a prefill_reported flag. ServeState::report_prefill sends PrefillStats { prompt_tokens, cached_tokens: 0, processed, first_token: true, prompt_ms } once, before the first Token or before Done when the engine finishes with no token (withheld EOS), and stamps the decode state's first-token instant as sequence.rs does.
  • 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.
  • Every XLA image family goes through 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.
  • No doc change: docs/llama-server-compat.md has no XLA-specific statement, and its general promise now holds on this loop.

Tests

The new and updated tests drive the real admit, preprocessing and dispatch path with a fake engine: text gets Prefill(2), the image gets Prefill(5), and Phi4MM audio and image each get Prefill(6), every one sent before its Token, with Done reporting 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 (structured is now constrained decoding, and refusing text fallback is now image resolution cardinality mismatch). I updated them so the module runs green.

  • Fix: server::batch::xla_worker, 15 passed (--release --features cuda,xla-iree, --test-threads=1, under gpu-lock).
  • Revert check: with the production files restored to main, 9 failed. That is the 7 new or updated tests plus the 2 stale assertions.
  • cargo clippy --release --features cuda,xla-iree --lib --tests -- -D warnings, cargo check --release --features cuda,xla-iree --all-targets, cargo fmt --check and 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-server on the GB10 (the default 256 capacity refuses a Gemma 3 image). I sent one body (tests/fixtures/test_image.png plus a short prompt) to count_tokens, non-streaming and streaming /v1/messages:

Body Build count_tokens usage.input_tokens message_start.input_tokens
image main cadc636, XLA 18 18 18
image this PR, XLA 277 277 277
image this PR, MLX path 277 277 277
text both builds, XLA 17 17 17

In every stream message_start was 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.

@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:low Low priority area:inference Generation, sampling, decoding (incl. speculative, DRY) status:review Under review status:done Completed and removed status:review Under review labels Oct 17, 2026
…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
inureyes force-pushed the fix/issue-2420-xla-expanded-prompt-length branch from 6a30cb9 to 815a6da Compare October 17, 2026 02:14
@inureyes
inureyes merged commit 85c1fe7 into main Oct 17, 2026
27 checks passed
@inureyes
inureyes deleted the fix/issue-2420-xla-expanded-prompt-length branch October 17, 2026 03:08
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:low Low priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(server): report the expanded media prompt length on the xla-iree loop

1 participant