Skip to content

epic: Make mlxcel-server faster on CUDA serving #3671

Done
8 of 8 issues completed
Done

Description

@inureyes

Problem / Background

On one NVIDIA B200 (sm_100, 179 GiB) serving nvidia/Gemma-4-31B-IT-NVFP4 (60 layers: 50 sliding-window layers, window 1024, 16 KV heads x head_dim 256; 10 full-attention layers, 4 KV heads x head_dim 512, K==V; hidden 5376, MLP 21504, vocab 262144), mlxcel-server is 2x slower than vLLM and SGLang at concurrency 1 and more than 10x slower at concurrency 32. The kernel work on #3650 (branch update/b200-nvfp4-gemma4-perf) closed part of the gap; what remains is structural in the server. Full record: docs/benchmark_results/Gemma4_sm100_Optimization_Report.md and docs/benchmark_results/Gemma4_sm100_Optimization_Runs.csv (land with #3650).

vllm bench serve as the client for every engine (OpenAI chat endpoint, random dataset, 512 input and 128 output tokens, --ignore-eos, 16 prompts at c=1, 4x concurrency prompts otherwise, warmup first):

Engine TPOT c=1 TTFT c=1 output tok/s c=8 output tok/s c=32 TPOT c=32
SGLang 1.0.0 (--quantization modelopt_fp4, trtllm_mha, decode CUDA graphs) 6.90 ms 67.7 ms 921.8 2390.1 9.48 ms
vLLM 0.34.0 (--quantization modelopt --max-model-len 8192 --gpu-memory-utilization 0.85; FP8 KV, FlashInfer TRT-LLM attention, full CUDA graphs) 8.18 ms 30.8 ms 827.4 2531.7 10.43 ms
mlxcel-server on #3650 (--parallel 32 --ctx-size 65536) 17.89 ms 131 ms 168.4 158.9 (204 with MLXCEL_CACHE_LIMIT=16GB) 190.5 ms (138.8 with the cache limit)
mlxcel engine path (mlxcel-bench-decode, single sequence) 12.0 ms 113 ms prefill at 512

Where the time goes (nsys, server decoding 8 concurrent requests, 25 s window, after #3650's step 9): graphs execute 16.6% of the window; 99.7k cudaFree, 99.4k cudaMallocManaged, 410k cudaMallocAsync/cudaFreeAsync, 1.04M cudaGraphAddKernelNode, 13.7k cudaGraphExecUpdate, 68k cudaGraphDestroy; per-row kernels copy_v 218k, copy_gg_nd 119k, rope_single 99k, rms_norm_small 52k launches. --parallel 32 at 8192 tokens per slot runs out of memory because the paged slab is sized as if all 60 layers were full attention in fp16 (about 257 GB), and MLX's CUDA buffer cache holds up to 95% of the device.

vLLM and SGLang hold up because they plan memory once at startup, give sliding layers only their window and store KV in FP8, capture one CUDA graph per padded batch bucket and replay it with fixed input buffers, run each op once for the whole batch, overlap host scheduling with GPU execution, and mix decode with chunked prefill under a per-step token budget. The sub-issues below bring each of those to mlxcel-server.

Metal constraint. Apple Silicon is the primary platform. On M1 Ultra, releasing the cache every decode step costs nothing measurable (qwen3-4b-4bit 136.9 vs 137.9 tok/s, llama-3.1-8b-4bit 106.2 vs 106.4), and bounding unified-memory residency matters there. Every sub-issue keeps Metal behaviour and performance unchanged unless it states and measures otherwise; backend-specific defaults (as MLXCEL_CACHE_CLEAR_INTERVAL does since #627) are the pattern.

Goal

On the B200 with this checkpoint and the shapes above, mlxcel-server is faster than vLLM 0.34.0 at c=1, 8 and 32: TPOT below 8.18 ms at c=1 and below 10.43 ms at c=32, output tok/s above 827.4 at c=8 and above 2531.7 at c=32, with --parallel 32 --ctx-size 262144 serving without OOM, all in the default mlxcel-server request path with no environment variables.

Sub-issues

Phase 1

Phase 2

Phase 3

Phase 4

#3665 depends on #3664 because both change cache/paged.rs and the batched KV write follows #3664's slab layout (first slab, K==V written once). #3668 captures whatever per-row launches remain, so landing #3665 first makes the captured graph smaller. #3663 should land first so every other PR reports the same table.

Acceptance Criteria

  • All sub-issues completed and merged.
  • scripts/bench/serving_compare.py (from chore: Add a serving benchmark harness against vLLM and SGLang #3663) run on the B200 shows mlxcel-server meeting the Goal numbers against vLLM, or the epic closes with a documented, measured reason for each missed cell.
  • --parallel 32 --ctx-size 262144 serves c=32 without failed requests.
  • Every optimization is in the default mlxcel-server path on CUDA; Metal measured or structurally unchanged.

Policy for every sub-issue PR

Cancel remote CI on the PR, run only the tests for the touched area locally (cargo test --profile test-fast --features cuda <module filter> -- --test-threads=1, plus the serving benchmark for performance claims), then merge. Each PR reports the serving table (c=1, 8, 32) before and after.

Technical Considerations

Starting points: src/server/batch/scheduler/ (decode_tick.rs, prefill.rs, planned_prefill.rs, handoff.rs, prompt_cache.rs, paged_layout.rs), src/server/batch/tick_policy.rs, src/server/model_worker.rs, src/server/model_provider.rs, src/execution/memory_estimate.rs, src/execution/runtime.rs, src/lib/mlxcel-core/src/cache/ (paged.rs, paged_batch_decode.rs), src/lib/mlxcel-core/src/paged_v2/, src/lib/mlxcel-core/src/memory.rs, src/models/gemma4.rs (scheduler-owned layer state since #3643), src/lib/mlxcelverse/overlays/cuda/mlx/backend/cuda/device.cpp (per-commit graph build, dependencies keyed by buffer pointer), and the MLX CUDA allocator at the pin. ADR 0005 (mixed prefill/decode, revisited by #3670) and ADR 0007 (unified batch-native engine).

Sub-issues

Sub-issues

8 of 8 Issues completed
Loading 8 sub-issues

Activity

  1. added
    type:epic
    priority:high
    status:ready
    area:inference
    platform:linux
    on Dec 2, 2026
  2. changed the title [-]epic: Make mlxcel-server faster than vLLM on CUDA serving[/-] [+]epic: Make mlxcel-server faster on CUDA serving[/+] on Dec 2, 2026
  3. inureyes commented on Dec 3, 2026

    @inureyes
    MemberAuthor

    Epic implementation complete

    All eight sub-issues are merged and closed, validated on an NVIDIA GB10 (sm_121). B200 measurements were out of reach on this host and are collected in one follow-up, #3725. GB10 timings in the PRs come from a shared host and are indicative only.

    Contract gate on final main (9402cf8, GB10): llama_compat_manifest passes, and the six real-model paged_*_parity targets pass 20/20 with --ignored. mlx_test_guard_coverage has one failure in nemotron_h_nano_omni_tests.rs that comes from #3681, not this epic; open PR #3720 fixes it.

    Known behavior to keep in mind:

    Follow-ups:

  4. added
    status:done
    and removed
    status:ready
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:inferenceplatform:linuxpriority:highstatus:donetype:epic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions