feat: serve the OpenXLA backend through the continuous-batching engine (#449 M3 Stage 2c)#470
Merged
Merged
Conversation
#449 M3 Stage 2c) Wire the Stage 2b XlaBatchEngine into mlxcel-server so the OpenXLA backend is servable, not just CLI: with MLXCEL_BACKEND=xla on an xla-iree build, requests are served through the continuous-batching engine. The MLX serving path is unchanged. - BatchEngine trait (src/server/batch/mod.rs): the backend-neutral serve contract (the cross-backend batching seam ADR 0004 deferred). The MLX BatchScheduler and the new XlaServeWorker both implement it; the MLX worker spawn sites now dispatch through serve(), which forwards to the scheduler's existing run loop (behavior unchanged). - XlaServeWorker (src/server/batch/xla_worker.rs, gated on xla-iree): drains ModelRequests, encodes prompts, submits to the engine, pumps it one step at a time, and maps each EngineEvent to a GenerateEvent reusing the server's StreamingDecodeState for byte-fallback-safe detokenization; polls the cancel flag; blocks on recv when idle. - ModelProvider routing (model_provider.rs): MLXCEL_BACKEND=xla spawns the XLA worker (new_with_xla_worker / spawn_xla_model_worker, which build the engine + tokenizer on the worker thread); --max-batch-size maps to the engine's bundled B_max ({4, 8}); the HAL device comes from MLXCEL_XLA_DEVICE. - XlaBackend::supports_batched_serving() returns true under xla-iree. Scope: greedy and text-only (the engine's nature). Honors max_tokens and the model's EOS ids; serves greedily regardless of sampling parameters (logged once); rejects logprobs, structured / JSON-schema output, and multimodal inputs with a clear error rather than serving them wrong; stop strings are not enforced yet. Validated end-to-end on GB10 (CUDA): /v1/completions is token-exact against the --no-chat-template CLI reference; three concurrent prompts are each served correctly (continuous batching, B_max=4); streaming concatenates; a logprobs request is rejected. The MLX serving path is unchanged (default build and scheduler tests green). The engine is greedy, so this is a reference/experimental serving path gated behind xla-iree; default and CI builds are unaffected.
This was referenced Jun 28, 2026
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.
Summary
Stage 2c of the OpenXLA/IREE throughput milestone (#449 M3): wire the Stage 2b
XlaBatchEngine(PR #469) intomlxcel-serverso the OpenXLA backend is servable, not just CLI. WithMLXCEL_BACKEND=xlaon anxla-ireebuild, requests are served through the continuous-batching engine. The MLX serving path is unchanged.Until now the server only ran MLX: it always built a
BatchSchedulerfrom an MLXLoadedModel(the XLA backend'sload_model()errors), soMLXCEL_BACKEND=xlanever reached the server. This PR adds the first non-MLX serving worker.What's here
BatchEnginetrait (src/server/batch/mod.rs): the backend-neutral serve contract (the cross-backend batching seam ADR 0004 deferred). A worker owns its model + KV/scheduling, consumesModelRequests, and streamsGenerateEvents untilShutdown. The MLXBatchSchedulerand the newXlaServeWorkerboth implement it; the MLX worker spawn sites now dispatch throughserve(), which forwards to the scheduler's existingrunloop (behavior unchanged).XlaServeWorker(src/server/batch/xla_worker.rs,#[cfg(feature = "xla-iree")]): drainsModelRequests, tokenizes prompts, submits to the engine, pumps it one step at a time, and maps each per-requestEngineEventback to aGenerateEvent, reusing the server'sStreamingDecodeStatefor byte-fallback-safe detokenization. Polls the cancel flag; blocks onrecvwhen idle.ModelProviderrouting (model_provider.rs):MLXCEL_BACKEND=xlaspawns the XLA worker (new_with_xla_worker/spawn_xla_model_worker, which build the engine + tokenizer on the worker thread, same async-load posture as the MLX path);--max-batch-sizemaps to the engine's bundledB_max(>= 8-> 8, else 4); the HAL device comes fromMLXCEL_XLA_DEVICE.XlaBackend::supports_batched_serving()returnstrueunderxla-iree.Scope (the engine is greedy + text-only by nature)
Honors
max_tokensand the model's EOS ids; serves greedily regardless of sampling parameters (logged once). Rejects what it cannot serve faithfully, with a clear error rather than wrong output: logprobs (no logit readback), structured / JSON-schema output (no constraint masking), and multimodal inputs (text-only). Stop strings are not enforced yet (EOS +max_tokensterminate). So this is a reference/experimental serving path, gated behindxla-iree.Validation (E2E on GB10, CUDA)
Server started with
MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=cuda+ Llama-3.2-1B:/v1/completionsfor"The capital of France is"returns" Paris. The Eiffel Tower is located in Paris. The Louvre Museum is also located in", identical to the--no-chat-templateCLI reference (same engine, same greedy).B_max=4("Jupiter ... gas giant", "4", "small village ... Tuscany").logprobsrequest returnserror: ... the OpenXLA backend does not support logprobs ....prompt_tokens,completion_tokens,length/stop).MLX serving path unchanged: default build compiles with the XLA worker absent;
serve()is a verbatim forward to the scheduler'srun;cargo clippy -D warningsclean (default +xla-iree); scheduler tests green.Refs #449 (epic). Follows #469 (Stage 2b), #468/#466 (2a), #462 (Stage 1). Next: Stage 2d (paged-KV, chunked prefill, sampling, stop strings).