Skip to content

epic: CUDA (MLX backend) prefill and decode acceleration program #623

Closed

Description

@inureyes

Summary

Program of work to raise prefill and decode throughput of the MLX backend on CUDA (primary validation target: NVIDIA GB10, sm_121, 122 GB unified LPDDR5x at ~273 GB/s). Based on the 2026-06-17 GB10 benchmark sweep (benchmarks/cuda_gb10_2026-06-17.csv, 147 models) compared against the same-week Metal M1 Ultra sweep, plus a code audit of the generation hot path, the CUDA binding layer, and the serving layer.

Diagnosis (baseline)

Dense single-stream decode is already close to the memory-bandwidth roofline on GB10:

Model Measured decode Roofline (273 GB/s) Attained
llama-3.1-8b-4bit 49.1 tok/s ~59 tok/s ~83%
llama-3.1-8b-bf16 14.8 tok/s ~17 tok/s ~87%
qwen2.5-0.5b-bf16 200 tok/s ~276 tok/s ~72%
llama-3.2-1b-4bit 260 tok/s ~390 tok/s ~67%

Consequences:

  • For 7B+ dense models, kernel micro-tuning has at most ~15% headroom. The big single-stream levers are fewer bytes (KV quantization, lower-bit weights) and fewer steps (speculative decoding).
  • Models under ~2B are launch/dispatch-overhead bound (67-75% attained). Pipelining and host-overhead work pays off there.
  • Several model families are far below roofline on CUDA and represent outright defects rather than tuning targets:
Family Evidence (CUDA vs Metal M1 Ultra)
MoE prefill mixtral-8x7b-4bit 12.5 vs 81.0 tok/s; llama-4-scout 28.2 vs 119.5; phi-3.5-moe 28.9 vs 114.0; gpt-oss-20b 126.2 vs 282.4
nvfp4 gemma-4-31b-it-nvfp4 decode 0.9 vs 8.9 tok/s; prefill 16.3 vs 38.9
Hybrid SSM granite-4.0-h-350m decode 64 vs 219.5; falcon-h1-tiny 103 vs 288; plamo-2-1b 34.4 vs 107.1; hunyuan-13b 14.8 vs 44.4 (pure mamba2 is fine: 81.4 vs 79.2)

Code-audit findings that shape the plan:

Phases and sub-issues

Implementation order. Each phase gate is a benchmark comparison against the phase's entry baseline.

Phase 0: measurement foundation

Phase 1: upstream sync and re-baseline (gate for Phase 3 scoping)

Phase 2: low-risk defaults and knobs (parallelizable after Phase 1)

Phase 3: targeted CUDA gap fixes (scope re-confirmed by Phase 1 triage; close any item upstream already fixed)

Phase 4: dispatch and host overhead

Phase 5: long-context and bandwidth reduction

Phase 6: larger bets

Working agreements for implementers

  • Hardware: CUDA items require a CUDA machine; the reference target is GB10 (sm_121). Checkpoints are expected under ./models/ as used by scripts/bench_all_models.sh and the CSVs in benchmarks/.
  • Build: cargo build --release --features cuda. The first build compiles MLX from source via CMake (src/lib/mlx-cpp/CMakeLists.txt); expect a long cold build. CI does not run the test suite, so cargo test --features cuda locally is the merge gate.
  • Benchmarks: scripts/bench_decode.sh (same-process decode harness, binary mlxcel-bench-decode), scripts/bench_all_models.sh (sweep, appends CSV under benchmarks/), scripts/bench_mlxlm.py (cross-check vs Python mlx-lm).
  • Every sub-issue must land integrated into the real code path it targets (CLI and/or server), not as a standalone module. Benchmarks or metrics proving the effect are part of done.
  • Do not regress Metal. Anything backend-conditional must key off runtime backend detection (existing pattern: !mlx::core::metal::is_available() in src/lib/mlxcel-core/cpp/mlx_cxx_kernels.cpp) or build features, and keep the Metal defaults unchanged.

Non-goals

Activity

  1. added
    type:performance
    status:ready
    priority:medium
    area:core
    area:inference
    on Jul 2, 2026
  2. self-assigned this
    on Jul 2, 2026
  3. inureyes commented on Jul 2, 2026

    @inureyes
    MemberAuthor

    Execution progress (/epic-impl, autonomous straight-through, max-parallel 1 on GB10):

    Wave 0 complete.

    Phase 1 triage (docs/benchmark_results/mlx-pin-upgrade-2026-07-03.md) re-scopes Phase 3: no sub-issue is fully fixed by the bump, so all three proceed.

    Proceeding to Wave 1 (Phase 2 knobs): #626, #627, #628.

  4. added
    status:done
    and removed
    status:ready
    on Sep 6, 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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions