Repository navigation
Description
Summary
make verify-test-cuda, the gate CONTRIBUTING.md names for Linux/NVIDIA, fails one test on every host with a CUDA device: native_env_tests::the_cuda_cache_defaults_reach_mlx reads MLX_CUDA_GRAPH_CACHE_SIZE as 400 where it expects 2000. The test became order-dependent when #2876 moved the MLX pin to 9f806b36: MLX now memoizes the first read of a setting, and in the gate's single-threaded order the CUDA device makes that read before the test does. Production is not affected.
Background
The gate runs the lib suite single-threaded in name order (Makefile:808, --features cuda --no-fail-fast -- --test-threads=1). The test removes MLX_CUDA_GRAPH_CACHE_SIZE, calls apply_cuda_graph_cache_default(), and reads it back through mlx_env_int, which is mlx::core::config::get in the bridge (src/lib/mlxcel-core/cpp/mlx_cxx_bridge.cpp:198). At pin 9f806b36 config::get stores the first value it returns for a name (the caller's default included) and answers from the store afterwards. The CUDA backend makes that first read when a command encoder is built (graph_cache_("MLX_CUDA_GRAPH_CACHE_SIZE", 400)), so by the time native_env_tests::* run the stored value is 400. At the previous pin 7ca40033 the read was mlx::core::env::get_var (a plain getenv on every call), so order did not matter.
Proposed Solution
Move the cache-default check into a test binary of its own, where nothing has initialized MLX configuration before the appliers run. This isolates the first-read state from the rest of the lib suite without a lock or a parallelism change.
Implementation Notes
Makefile:808verify-test-cuda:cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1.src/lib/mlxcel-core/src/native_env_tests.rs:206:assert_eq!(read, 2000, "{name}").src/lib/mlxcel-core/cpp/mlx_cxx_bridge.cpp:198:mlx_env_get_var_intcallsmlx::core::config::get.- The memoization boundary is update: advance MLX pin to 9f806b36 and refresh backend overlays #2876 (MLX pin
7ca40033to9f806b36). MLX_CUDA_SDPA_CACHE_SIZE, checked later in the same test, has the same exposure (first read at the cuDNN attention path), so moving both checks is worth it.
Acceptance Criteria
make verify-test-cudapasses every test binary on a CUDA host.the_cuda_cache_defaults_reach_mlxpasses whether or not a GPU test ran earlier in the same process.- Single-threaded (
--test-threads=1) runs stay green.
Original Suggestion
Title: fix(cuda): make verify-test-cuda fails one test on every CUDA host since #2876
Summary
make verify-test-cuda, the gate CONTRIBUTING.md names for Linux/NVIDIA, fails one test on a host with a CUDA device: native_env_tests::the_cuda_cache_defaults_reach_mlx reads MLX_CUDA_GRAPH_CACHE_SIZE as 400 where it expects 2000. The test became order-dependent when #2876 moved the MLX pin to 9f806b36: MLX now memoizes the first read of a setting, and in the gate's order the CUDA device makes that read before the test does. Production is not affected.
Reproduction steps
make verify-test-cuda
# or only the suite that holds the test, the way the gate runs it
cargo test --profile test-fast --features cuda -p mlxcel-core --lib --no-fail-fast -- --test-threads=1
# the order dependence, with two tests
cargo test --profile test-fast --features cuda -p mlxcel-core --lib -- --test-threads=1 --exact \
native_env_tests::the_cuda_cache_defaults_reach_mlx # ok
cargo test --profile test-fast --features cuda -p mlxcel-core --lib -- --test-threads=1 --exact \
ffi_tests::qmm_naive_output_is_identical_across_cta_tile_widths \
native_env_tests::the_cuda_cache_defaults_reach_mlx # FAILEDExpected behavior
The suite passes, as it did before #2876.
Actual behavior
---- native_env_tests::the_cuda_cache_defaults_reach_mlx stdout ----
thread 'native_env_tests::the_cuda_cache_defaults_reach_mlx' (1215207) panicked at src/lib/mlxcel-core/src/native_env_tests.rs:206:9:
assertion `left == right` failed: MLX_CUDA_GRAPH_CACHE_SIZE
left: 400
right: 2000
test result: FAILED. 2260 passed; 1 failed; 4 ignored; 0 measured; 0 filtered out; finished in 44.83s
It is the gate's only failure here: make verify-test-cuda on ce6855bc8 plus an unrelated change to the root crate passes 186 of 187 test binaries.
mlxcel version
main @ ce6855b
Install method
Built from source
Platform
Linux + CUDA (gb10)
Model checkpoint
None.
Relevant logs
The mlxcel-core lib suite with --features cuda -- --test-threads=1, and the test by itself and behind one GPU test, on three commits on the same host:
| Commit | MLX pin | mlx_env_get_var_int calls |
Lib suite | The test alone | After one GPU test |
|---|---|---|---|---|---|
912858435, the parent of #2876 |
7ca40033 |
mlx::core::env::get_var |
2214 passed, 0 failed | ok | ok |
f45a92cc9, #2876 |
9f806b36 |
mlx::core::config::get |
2213 passed, 1 failed | ok | FAILED, 400 |
ce6855bc8, main |
9f806b36 |
mlx::core::config::get |
2260 passed, 1 failed | ok | FAILED, 400 |
Additional context
- Cause. The test removes
MLX_CUDA_GRAPH_CACHE_SIZE, callsapply_cuda_graph_cache_default(), and reads the setting back throughmlx_env_int, which ismlx::core::config::getin the bridge (src/lib/mlxcel-core/cpp/mlx_cxx_bridge.cpp:198). At pin9f806b36that function stores the first value it returns for a name, the caller's default included, and answers from the store from then on (mlx/config.cpp:43-66:int val = get_env(name, default_val); update(name, val); return val;). The CUDA backend makes that first read itself when a command encoder is constructed:graph_cache_("MLX_CUDA_GRAPH_CACHE_SIZE", /* default_capacity */ 400)(overlays/cuda/mlx/backend/cuda/device.cpp:362, throughlru_cache.h:36). The gate runs the lib suite single threaded in name order, soffi_tests::*have built the device long beforenative_env_tests::*run, and 400 is what the store holds. - Why it started at update: advance MLX pin to 9f806b36 and refresh backend overlays #2876. At pin
7ca40033the same read wasmlx::core::env::get_var, a plainatoi(getenv(name))on every call (mlx/utils.cpp:294), so the test saw the value it had just set whatever ran before it. update: advance MLX pin to 9f806b36 and refresh backend overlays #2876 moved the pin and switched the bridge reader toconfig::get. The table above is that boundary, measured. - Production is not affected. The binaries call the two appliers once at the top of
main, before any MLX op, so the device reads 2000. I also looked for a runtime write of a setting that MLX could already have resolved: theMLX_USE_CUDA_GRAPHSwrite insrc/loading/mod.rsis already hoisted in front of the first GPU eval for this reason, and nothing else writes a memoized name after startup. - Why CI did not see it. The test is
#[cfg(feature = "cuda")], and CUDA tests are gated nowhere in CI (CONTRIBUTING.md). Theci.ymlsteps that run tests with--features cudause narrow filters (global_scale, one WebUI harness test), not this suite. - The second name. The loop in the test checks
MLX_CUDA_SDPA_CACHE_SIZEafter the graph cache and never gets there. Its cache is built the same way at the first cuDNN attention call (scaled_dot_product_attention.cpp:503), so it has the same exposure. I did not measure that half. - A fix is ready on a branch: the check moves to a test binary of its own, where nothing has touched MLX before the appliers run. With it
make verify-test-cudapasses every binary on this host.
Related report (read-only recheck, 2026-11-12)
Issue #2937 is closed and covers
parallel-only Metal/test-environment races and a missing serialized test command.
It is not this failure: the CUDA cache-default test above fails even with the
CI-faithful --test-threads=1, because an earlier test initialized process-local
MLX configuration. The fix here isolates that first-read state in a new process,
not a lock or a parallelism change.
Pre-submission checks
- I searched existing issues and did not find a duplicate
- This is not a security vulnerability (those go to SECURITY.md instead)
Activity
[-]fix(cuda): make verify-test-cuda fails one test on every CUDA host since #2876[/-][+]test(cuda): make verify-test-cuda fails the cache-default test on every CUDA host since #2876[/+]fix(server): keep a running listener's Unix socket and non-socket pat…
fix(core): reject packed uint8 weights in dense linear loaders (#3019)
fix(models): accept a Mamba config that names a setting both ways (#2995
fix(loading): resolve the tokenizer's eos_token through tokenizer.json (
fix(loading): load text-only Gemma 4 and Gemma 3n exports (#2997)
fix(models): run a mixed-bit Gemma MLP projection by projection (#2999)
fix(quant): load ModelOpt W4A16_NVFP4 checkpoints in families without…
fix(loading): repack ModelOpt NVFP4 weights on the Qwen3.5 VLM route (#…
test(cuda): run the CUDA cache-default check in its own process (labl…