Skip to content

perf(server): split batched prefill into compatible cohorts instead of all-or-nothing fallback #332

Closed

Description

@inureyes

Summary

When a collected prefill batch contains one incompatible request, the scheduler currently falls the WHOLE window back to sequential prefill. Instead, split the window into compatible cohorts so eligible concurrent work still runs batched.

Source: idea.md "4. Batched Prefill Cohort Splitting" (P1, expected payoff medium, risk medium).

Current state

  • Batched prefill is available only when the model opts in via supports_batched_prefill(); the default is false (src/lib/mlxcel-core/src/generate.rs:467).
  • Qwen3 opts into batched prefill, maskless padded prefill, and paged decode (src/models/qwen3.rs, around line 821).
  • In the scheduler, one incompatible request forces the whole collected batch back to sequential prefill: unsupported model, any VLM embeddings, any adopted prompt-cache prefix, or incompatible prompt lengths (src/server/batch/scheduler.rs, around lines 3092 / 3110 / 3129 / 3146).

Proposal

  • Instead of falling back the whole prefill window, split it into compatible cohorts:
    • cold text requests eligible for padded batched prefill,
    • adopted-prefix requests that need sequential offset-aware prefill,
    • VLM or custom-embedding requests,
    • equal-length-only models.
  • Preserve request priority order at cohort boundaries so latency fairness does not regress.
  • Expand batched-prefill support to additional dense families ONLY after cohort splitting is measured; otherwise support expansion is hidden by fallback behavior.

Validation

  • Synthetic server queue with mixed cold prompts and prompt-cache hits.
  • Measure prefill tok/s, time-to-first-token, and head-of-line blocking.
  • Correctness tests for cache-offset handling when adopted-prefix rows are split away from cold rows.
  • Suggested first experiment (idea.md): add queue-shape tracing for batched-prefill fallback reasons first. If most fallback windows mix cold and adopted-prefix requests, cohort splitting is worth implementing.

Acceptance criteria

  • Mixed prefill windows are partitioned into cohorts; the cold-text cohort runs padded batched prefill even when other requests in the window are incompatible.
  • Request priority order is preserved at cohort boundaries (no fairness regression).
  • Cache-offset correctness verified when adopted-prefix rows are separated from cold rows.
  • Prefill tok/s, TTFT, and head-of-line blocking measured on a mixed synthetic queue vs the current all-or-nothing fallback.
  • INTEGRATION into the live scheduler prefill path.

Risk and priority

idea.md priority P1; risk medium. Batched prefill is a high-leverage server feature; the current all-or-nothing fallback can waste eligible concurrent work.

References

  • idea.md "4. Batched Prefill Cohort Splitting" and "Suggested First Experiments" item 4.
  • Code: src/lib/mlxcel-core/src/generate.rs (supports_batched_prefill), src/models/qwen3.rs, src/server/batch/scheduler.rs (prefill fallback gates).

Activity

  1. added
    type:performance
    priority:medium
    area:inference
    area:core
    status:in-progress
    status:review
    and removed
    status:in-progress
    on Jun 17, 2026
  2. added a commit that references this issue on Jun 18, 2026
  3. added
    status:done
    and removed
    status:review
    on Jun 18, 2026
  4. added this to the 0.3 milestone on Jun 21, 2026
  5. self-assigned this
    on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:corearea:inferencepriority:mediumstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions