Repository navigation
feat: serve DiffusionGemma block diffusion in mlxcel-server (phase 3 of #217) - #220
Merged
Merged
Conversation
Phase 3 of issue #217: a dedicated single-stream (batch-1) serving path for DiffusionGemma inside the existing model worker thread. The worker now loads the model normally and, when the loaded model is DiffusionGemma, branches into a new block-diffusion serving loop instead of constructing the BatchScheduler (DiffusionGemma is model-owned and supports_batching() == false). The loop serves /v1/chat/completions and /v1/completions for text and image requests with SSE streaming and non-streaming, request cancellation, and accurate usage stats; audio/video requests are rejected per-request with a clear error. Requests queue on the existing mpsc channel and are served serially by design. Key changes: new src/server/diffusion_worker.rs (worker loop + server->engine options mapping + audio/video rejection + sampler parsing + finish-reason mapping); the CLI vision-prep path moved into DiffusionGemmaModel::prepare_image_prompt / build_image_processor so the CLI generate driver and the server worker share one image path; the load-time rejection helper (server_unsupported_model_error) and its call sites were removed; three serve-level diffusion flags (--max-denoising-steps, --diffusion-sampler, --diffusion-threshold) were threaded from ServeArgs / the mlxcel-server binary through ServerStartupInput, ServerStartupConfig, ServerConfig, and WorkerSchedulerConfig to the worker loop. Both the batched and legacy (--no-batch) workers branch to the diffusion loop.
Member
Author
Implementation Review SummaryIntentPhase 3 (final) of #217: serve DiffusionGemma block-diffusion in mlxcel-server via a dedicated single-stream (batch-1) worker loop, with serve-level diffusion flags threaded through, while leaving autoregressive serving byte-identical. Findings AddressedNone requiring changes. Implementation is correct, complete, and well integrated. Verification
Detail
Checks run (no real model / no server, per constraints)
Non-blocking observations (no change made)
|
The confidence threshold was only checked inside the engine per request, so an out-of-range serve-level value surfaced as a per-request error under the confidence sampler instead of failing fast at startup. Both binaries now reject it at parse time (pr-reviewer observation).
…nterval The phase-3 diffusion serving change inserted parse_unit_interval (and its doc comment) directly between the top-level mlxcel-server doc block and the #[derive(Parser)] Cli struct. With no blank line or intervening item, the whole doc block (the "Usage modes" long help) merged onto parse_unit_interval and detached from Cli, so the binary lost its long --help text, and clippy's doc_lazy_continuation fired on the merged comment under --tests --bins. Move parse_unit_interval below the Cli struct (matching the placement in src/main.rs) so the doc comment re-attaches to Cli. Behavior of the parser itself is unchanged.
Member
Author
Security and performance review (network-facing surface)Reviewed the phase-3 diffusion serving path with a focus on untrusted request fields, DoS/queue behaviour, channel hygiene, AR-model regression vectors, and per-request overhead. Net result: one fixed regression, two non-blocking observations, no CRITICAL/HIGH. Fixed (committed
|
A cancelled or disconnected server request previously kept denoising until the current block finished (up to max_denoising_steps forwards over a 256-token canvas, roughly 30 seconds), because the engine only honored the callback verdict between committed tokens. DiffusionGenerateOptions gains an optional cancel flag the server worker wires to its request cancellation AtomicBool; the denoise loop polls it at every step so an abort lands within one forward pass. The aborted partial block is never emitted. The CLI passes no flag and is unchanged (pr-security-checker observation).
Add a "Server mode" section to block-diffusion.md covering mlxcel-server usage, the three serve-level flags (--diffusion-sampler, --diffusion-threshold, --max-denoising-steps), image_url support, and operational caveats (thinking channel, max_tokens budget, streaming vs non-streaming reasoning, /v1/completions raw-prompt degradation, cancellation resolution). Remove "server mode not yet supported" from the limitations section; retain only the TP placeholder caveat. Update the DiffusionGemma row in supported-models.md from "Server mode is not yet supported" to note serial batch-1 serving via /v1/chat/completions and /v1/completions.
6 of 9 tasks
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
lablup#217) (lablup#220) * feat: serve DiffusionGemma block diffusion in mlxcel-server (lablup#217) Phase 3 of issue lablup#217: a dedicated single-stream (batch-1) serving path for DiffusionGemma inside the existing model worker thread. The worker now loads the model normally and, when the loaded model is DiffusionGemma, branches into a new block-diffusion serving loop instead of constructing the BatchScheduler (DiffusionGemma is model-owned and supports_batching() == false). The loop serves /v1/chat/completions and /v1/completions for text and image requests with SSE streaming and non-streaming, request cancellation, and accurate usage stats; audio/video requests are rejected per-request with a clear error. Requests queue on the existing mpsc channel and are served serially by design. Key changes: new src/server/diffusion_worker.rs (worker loop + server->engine options mapping + audio/video rejection + sampler parsing + finish-reason mapping); the CLI vision-prep path moved into DiffusionGemmaModel::prepare_image_prompt / build_image_processor so the CLI generate driver and the server worker share one image path; the load-time rejection helper (server_unsupported_model_error) and its call sites were removed; three serve-level diffusion flags (--max-denoising-steps, --diffusion-sampler, --diffusion-threshold) were threaded from ServeArgs / the mlxcel-server binary through ServerStartupInput, ServerStartupConfig, ServerConfig, and WorkerSchedulerConfig to the worker loop. Both the batched and legacy (--no-batch) workers branch to the diffusion loop. * fix: validate --diffusion-threshold to [0, 1] at argument parse time The confidence threshold was only checked inside the engine per request, so an out-of-range serve-level value surfaced as a per-request error under the confidence sampler instead of failing fast at startup. Both binaries now reject it at parse time (pr-reviewer observation). * fix: restore mlxcel-server Cli long-help doc detached by parse_unit_interval The phase-3 diffusion serving change inserted parse_unit_interval (and its doc comment) directly between the top-level mlxcel-server doc block and the #[derive(Parser)] Cli struct. With no blank line or intervening item, the whole doc block (the "Usage modes" long help) merged onto parse_unit_interval and detached from Cli, so the binary lost its long --help text, and clippy's doc_lazy_continuation fired on the merged comment under --tests --bins. Move parse_unit_interval below the Cli struct (matching the placement in src/main.rs) so the doc comment re-attaches to Cli. Behavior of the parser itself is unchanged. * perf: poll the cancellation flag once per denoising step A cancelled or disconnected server request previously kept denoising until the current block finished (up to max_denoising_steps forwards over a 256-token canvas, roughly 30 seconds), because the engine only honored the callback verdict between committed tokens. DiffusionGenerateOptions gains an optional cancel flag the server worker wires to its request cancellation AtomicBool; the denoise loop polls it at every step so an abort lands within one forward pass. The aborted partial block is never emitted. The CLI passes no flag and is unchanged (pr-security-checker observation). * docs: document DiffusionGemma server mode (phase 3 of lablup#217) Add a "Server mode" section to block-diffusion.md covering mlxcel-server usage, the three serve-level flags (--diffusion-sampler, --diffusion-threshold, --max-denoising-steps), image_url support, and operational caveats (thinking channel, max_tokens budget, streaming vs non-streaming reasoning, /v1/completions raw-prompt degradation, cancellation resolution). Remove "server mode not yet supported" from the limitations section; retain only the TP placeholder caveat. Update the DiffusionGemma row in supported-models.md from "Server mode is not yet supported" to note serial batch-1 serving via /v1/chat/completions and /v1/completions.
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
Phase 3 (final) of #217: a dedicated single-stream (batch-1) serving path for DiffusionGemma inside the existing model worker thread. DiffusionGemma generates by model-owned block diffusion (
supports_batching() == false) and cannot join the BatchScheduler, so the worker loads the model normally and, when it is a DiffusionGemma checkpoint, branches into a new block-diffusion serving loop instead of constructing the scheduler. The loop serves/v1/chat/completionsand/v1/completionsfor text and image requests, both streaming (SSE) and non-streaming, with request cancellation and accurate usage stats. Requests queue on the existing mpsc channel and are served serially: that is the design (no in-flight concurrency > 1).What changed
src/server/diffusion_worker.rs(new): the batch-1 worker loop (run_diffusion_worker_loop) plus the testable pure helpers it uses (diffusion_options_from_server/build_diffusion_optionsfor server-to-engine option mapping,reject_audio_video,parse_diffusion_sampler, anddiffusion_finish_reason_str). The loop tokenizes the already chat-templated prompt, optionally runs the phase-2 vision prefill, denoises throughgenerate_diffusion_streaming, streams each committed token via the server's incremental detokenizer (StreamingDecodeState), polls the cancellation flag in the engine callback, and emits a finalDonewith real usage/timings and a mapped finish reason. One bad request emitsErrorand the loop keeps serving.src/server/model_worker.rs: removed the load-time rejection helperserver_unsupported_model_errorand both its call sites; the batched and legacy (--no-batch) workers now branch into the diffusion loop after the model loads. Added the three serve-level diffusion fields toWorkerSchedulerConfig.src/models/diffusion_gemma/mod.rs: extracted the CLI vision-prep into sharedDiffusionGemmaModel::prepare_image_prompt/build_image_processor(+PreparedDiffusionImagePrompt), and re-exportedDiffusionFinishReason. The CLIgeneratedriver (src/commands/generate_diffusion.rs) now delegates to this helper and keeps working identically.--max-denoising-steps,--diffusion-sampler,--diffusion-thresholdthreaded fromServeArgs(newDiffusionServeOptionsgroup) and themlxcel-serverbinary throughServerStartupInput->ServerStartupConfig->ServerConfig->WorkerSchedulerConfig-> the worker loop. Help text documents that they only affect diffusion models.Options mapping (server -> engine)
options.max_tokensmax_new_tokensoptions.sampling.temperaturetemperature--diffusion-samplersampler--diffusion-thresholdconfidence_threshold--max-denoising-stepsmax_denoising_stepsoptions.sampling.stop_token_ids+ config EOS (deduped)extra_eos_token_idsoptions.sampling.seedmlxcel_core::random_seed(seed)before generationmin/max canvas,full_canvas,prefill_chunk_sizekeep engine defaultsLimitations (documented)
Errorevent.Length -> "length",Stop -> "stop",Aborted -> "stop"(the server response surface has no distinct cancelled-reason string).GET /v1/modelsand health endpoints are unchanged.Test plan
cargo fmtcargo check --lib --tests --bins --features metal,acceleratecargo clippy --lib --tests --bins --features metal,accelerate -- -D warningscargo test --lib --features metal,accelerate server::diffusion_worker(7 passed: options mapping, EOS union/dedup, audio/video rejection, sampler parse, finish-reason mapping, defaults)cargo test --lib --features metal,accelerate models::diffusion_gemma(32 passed, no regressions)cargo test --lib --features metal,accelerate server::cli_inputandcargo test --bin mlxcel ... serveandcargo test --bin mlxcel-server(config threading + arg parsing green)models/diffusiongemma-26B-A4B-it-4bit(orchestrator runs this; see Real-model verification below)Real-model verification (phase 3)
Live server on
models/diffusiongemma-26B-A4B-it-4bit:GET /v1/modelsreturns the model entry correctly.finish_reason: stop, usage token counts correct.delta.reasoning_contentcarries the thinking channel;delta.contentcarries the final reply;finish_reason: stopon the closing chunk; usage counts match non-streaming.image_urlrequest: 256 soft tokens expanded, model answered "a red square and a blue circle" correctly.--diffusion-sampler confidence-threshold --diffusion-threshold 0.6verified effective (178 tokens generated in 7.8 s wall clock).POST /v1/completions: mechanical-OK; raw un-templated prompts degrade as documented (the model depends on its chat structure), so chat completions are the recommended path.c38559cc).Closes #217