Skip to content

feat(runtime): warn when a CPU-only build runs on an NVIDIA host (#326) - #372

Merged
inureyes merged 3 commits into
mainfrom
fix/cpu-only-build-guard
Jun 19, 2026
Merged

inureyes merged 3 commits into
mainfrom
fix/cpu-only-build-guard

Conversation

@inureyes

Copy link
Copy Markdown
Member

Why

A default cargo build --release on Linux uses the default features (surgery only), omits cuda, and produces a CPU-only binary. It still loads and generates, but silently runs MLX on the host CPU at single-digit tok/s, and the only hint is Runtime device: CPU. This bit a GB10 benchmarking session for #326 (0.13 tok/s before the mistake was caught) and is already flagged in model_tests_gb10.md.

What

Three layers of prevention for the same footgun:

  1. Runtime warning (the real guard). At startup, when the user wanted the GPU but a CPU-only binary fell back to CPU on a host that has an NVIDIA GPU, print a loud one-line warning pointing at the --features cuda rebuild. Fires every time the mistake happens, regardless of how the binary was built.
    • Detection uses the NVIDIA device nodes (/dev/nvidiactl, /proc/driver/nvidia/version), which the kernel driver exposes without linking CUDA, so a CPU-only build can still tell it is on an NVIDIA host.
    • An explicit MLXCEL_DEVICE=cpu suppresses it, and a cuda-capable build that fell back to CPU is a genuine no-GPU host, not the footgun.
    • The decision is a pure function (should_warn_cpu_only_on_nvidia_host) with a unit test.
  2. cargo cuda alias (.cargo/config.toml) for the feature-correct build, so the right thing is one token.
  3. Docs: the README build section and installation.md now call out the CPU-only footgun next to the build commands.

No behavior change on a correctly built GPU binary: the warning is gated to CPU-fallback-on-NVIDIA-without-cuda, and the cuda/Metal paths never reach it.

Validation

  • should_warn_cpu_only_on_nvidia_host unit test (5 cases: footgun fires; cuda build, no-NVIDIA host, explicit CPU, and on-GPU all stay quiet). Passes under cargo test --release --features cuda --lib.
  • NVIDIA device-node detection confirmed present on the GB10 host.
  • Compiles in both the --features cuda and default (CPU-only) configurations.

Follow-up to #326 / #357 (the GB10 fused QK-norm benchmark, where this footgun first showed up).

inureyes added 2 commits June 19, 2026 17:01
A plain `cargo build --release` on Linux omits the `cuda` feature and produces a
CPU-only binary that silently runs MLX on the host CPU at a fraction of GPU
throughput (single-digit tok/s on GB10). Call this out in the README build
section and next to the CUDA build command in installation.md so the
`--features cuda` requirement is hard to miss on an NVIDIA host.
A default `cargo build --release` on Linux omits the `cuda` feature and
produces a CPU-only binary. It still loads and generates, but silently runs MLX
on the host CPU at single-digit tok/s, and "Runtime device: CPU" is easy to
miss. This bit a benchmarking session on GB10 (#326).

At startup, when the user wanted the GPU but a CPU-only binary fell back to CPU
on a host that has an NVIDIA GPU, print a loud one-line warning pointing at the
`--features cuda` rebuild (or `cargo cuda`). Detection uses the NVIDIA device
nodes (/dev/nvidiactl, /proc/driver/nvidia/version), which the kernel driver
exposes without linking CUDA, so a CPU-only build can still tell it is on an
NVIDIA host. An explicit MLXCEL_DEVICE=cpu suppresses the warning, and a
cuda-capable build that fell back to CPU is a genuine no-GPU host, not the
footgun. The decision is a pure function with a unit test.

Also add a `.cargo/config.toml` `cargo cuda` alias for the feature-correct
build, and document the footgun in the README and installation.md.
@inureyes inureyes added area:cli Command-line interface / CLI flags area:docs User and developer documentation type:enhancement New features, capabilities, or significant additions labels Jun 19, 2026
@inureyes
inureyes merged commit 66fc9da into main Jun 19, 2026
4 checks passed
@inureyes
inureyes deleted the fix/cpu-only-build-guard branch June 19, 2026 08:49
@inureyes inureyes added this to the 0.3 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added the status:done Completed label Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…lup#326) (lablup#372)

A default `cargo build --release` on Linux omits the `cuda` feature and produces a CPU-only binary that still runs but executes MLX on the host CPU at single-digit tok/s, with only `Runtime device: CPU` as a hint. This bit a GB10 benchmarking session for lablup#326.

At startup, when the user wanted the GPU but a CPU-only binary fell back to CPU on a host that has an NVIDIA GPU (detected via `/dev/nvidiactl` or `/proc/driver/nvidia/version`, which need no CUDA linkage), print a one-line warning pointing at the `--features cuda` rebuild or the new `cargo cuda` alias. An explicit `MLXCEL_DEVICE=cpu` suppresses it, and a cuda-capable build that fell back to CPU is a genuine no-GPU host, not the footgun. The decision is a pure function with a unit test.

Also adds the `cargo cuda` alias in `.cargo/config.toml` and documents the footgun in the README build section and installation.md. No behavior change on a correctly built GPU binary. Follow-up to lablup#326 and lablup#357.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Command-line interface / CLI flags area:docs User and developer documentation status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant