Repository navigation
Description
Blocked by #899 (fused v2 decode in production; the plan/run infrastructure this builds on).
Background
mlxcel's continuous-batching scheduler alternates prefill and decode by tick: decide_action() (src/server/batch/scheduler.rs lines ~3222-3292) returns one of {Prefill, Decode, SpeculativeRound, Idle} per tick, and a forward step never mixes prefill and decode work. Chunked prefill (default 512-token chunks) bounds how long a single prefill tick blocks decode, but the structural trade-off remains: while a prefill chunk runs, every decoding stream waits a full model forward, which shows up as inter-token latency (ITL) spikes on admission; conversely small decode batches leave compute idle that a co-scheduled prefill chunk could use.
Modern serving engines mix the two workloads at two maturity levels:
- Single-launch kernel-level mixing: one kernel launch carries both a prefill and a decode workload; each CTA claims either a prefill tile or a decode tile through an atomic work counter (with SM-aware proportional interleaving and fallback to the other queue when one drains). Decode is executed as tiny-q prefill (a 16-row query tile), which is what makes a single kernel family serve both.
- Persistent work-queue batching: requests are partitioned by packed query length into prefill-like (128-row tile) and decode-like (16-row tile) work-item classes, load-balanced across SM clusters by a cost heap so each cluster gets ~equal KV work; SM-resident persistent kernels consume the mixed queue without relaunch.
For mlxcel, the honest scope is a design spike: full adoption changes the scheduler's execution model and touches every family's forward. The pragmatic middle step to evaluate is model-level ragged mixing: concatenate the active decode batch (q_len=1 rows) and one prefill chunk (q_len=N rows) into a single ragged forward, which requires ragged attention support in the family forward and per-row position/mask handling. The XLA/IREE engine already has a ragged decode concept (emit_decode_ragged, src/lib/mlxcel-xla/src/emitter/mod.rs), which can inform the shape of the MLX-side contract.
Task
This issue delivers a decision, not a production feature:
- Design document (ADR): analyze the candidate execution models for mixed steps on the MLX path: (a) status quo tick alternation with smaller chunks, (b) ragged mixed forward at the model level, (c) kernel-level mixing (requires Route production batched paged decode through the fused v2 kernel, retiring the gather-then-SDPA hot path #899's fused kernel plus a prefill-capable variant). Cover scheduler state machine changes, family forward-signature impact, speculative-round interaction, and CUDA-graph implications (MLX graph cache keyed by shapes; ragged shapes churn the cache).
- Prototype on one family (Llama3-class, which already supports batched prefill cohorts,
src/server/batch/prefill_cohort.rs): implement the ragged mixed forward behindMLXCEL_MIXED_STEP=1, sufficient to serve real traffic in a test harness, without committing to the final scheduler design. - Measurement: quantify what tick alternation actually costs today and what the prototype recovers (see validation), so the go/no-go decision is data-driven.
- Decision gate: the ADR concludes with adopt/defer/reject and, if adopt, the follow-up issue breakdown.
Performance validation (mandatory)
- Scenario: 4 active decode streams; admit a new request with an 8K-token prompt; measure per-stream ITL p50/p95 during the prefill window, plus time-to-first-token of the admitted request. Compare tick-alternation baseline vs the mixed-step prototype, Metal and GB10 when available.
- Throughput controls: pure-decode (no admission) and pure-prefill scenarios must show no regression with the flag on but idle (< 1% overhead).
- Record in
docs/benchmark_results/mixed-step-prototype-<hw>-<date>.mdand summarize in the ADR.
Regression guard (mandatory)
- Prototype correctness: greedy token parity for both the decoding streams and the admitted request vs the tick-alternation baseline on pinned prompts.
- With
MLXCEL_MIXED_STEPunset, scheduler behavior is byte-identical (the decision-logic refactor, if any, must preservedecide_actionsemantics; existing scheduler unit tests pass unchanged). - Full server and
mlxcel-coretest suites pass; speculative scheduling (speculative_slice) continues to function with the flag on (mixed steps and speculative rounds may exclude each other in the prototype; document).
References
src/server/batch/scheduler.rs(decide_action)src/server/batch/prefill_cohort.rsdocs/CONTINUOUS_BATCHING.mdsrc/lib/mlxcel-xla/src/emitter/mod.rs(ragged decode contract)
Line numbers are indicative as of current main; search for the named symbols.
Part of epic #909.
Activity
docs(adr): reject mixed prefill/decode step execution, add the admiss…
fix(bench): size the harness thread pool and close the ADR's open gaps
fix(server): stop the mixed-step prototype from corrupting its own me…
feat(server): MLXCEL_MIXED_STEP prototype and ADR 0005 decision (#1010)
fix(server): bound a parked chunked prefill's wait with a fairness grant
fix(server): bound a parked chunked prefill's wait with a fairness gr…
fix(server): add a kill switch and record the boundary split's output…
fix(server): add a kill switch and record the boundary split's output…
feat(server): MLXCEL_MIXED_STEP prototype and ADR 0005 decision (labl…
fix(server): bound a parked chunked prefill's wait with a fairness gr…