Skip to content

Mixed prefill/decode step execution: design spike and prototype #908

Closed

Description

@inureyes

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:

  1. 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).
  2. Prototype on one family (Llama3-class, which already supports batched prefill cohorts, src/server/batch/prefill_cohort.rs): implement the ragged mixed forward behind MLXCEL_MIXED_STEP=1, sufficient to serve real traffic in a test harness, without committing to the final scheduler design.
  3. Measurement: quantify what tick alternation actually costs today and what the prototype recovers (see validation), so the go/no-go decision is data-driven.
  4. 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>.md and 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_STEP unset, scheduler behavior is byte-identical (the decision-logic refactor, if any, must preserve decide_action semantics; existing scheduler unit tests pass unchanged).
  • Full server and mlxcel-core test 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.rs
  • docs/CONTINUOUS_BATCHING.md
  • src/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

  1. added
    status:blocked
    type:enhancement
    priority:low
    area:architecture
    on Jul 24, 2026
  2. added
    status:in-progress
    and removed
    status:blocked
    on Aug 3, 2026
  3. added
    status:review
    and removed
    status:in-progress
    on Aug 3, 2026
  4. added
    status:done
    and removed
    status:review
    on Aug 3, 2026
  5. self-assigned this
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:architecturepriority:lowstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions