Skip to content

test(cuda): make verify-test-cuda fails the cache-default test on every CUDA host since #2876 #2987

Closed

Description

@Jaeyeong-CHOI

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:808 verify-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_int calls mlx::core::config::get.
  • The memoization boundary is update: advance MLX pin to 9f806b36 and refresh backend overlays #2876 (MLX pin 7ca40033 to 9f806b36).
  • 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-cuda passes every test binary on a CUDA host.
  • the_cuda_cache_defaults_reach_mlx passes 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                 # FAILED

Expected 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, calls apply_cuda_graph_cache_default(), and reads the setting 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 that 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, through lru_cache.h:36). The gate runs the lib suite single threaded in name order, so ffi_tests::* have built the device long before native_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 7ca40033 the same read was mlx::core::env::get_var, a plain atoi(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 to config::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: the MLX_USE_CUDA_GRAPHS write in src/loading/mod.rs is 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). The ci.yml steps that run tests with --features cuda use narrow filters (global_scale, one WebUI harness test), not this suite.
  • The second name. The loop in the test checks MLX_CUDA_SDPA_CACHE_SIZE after 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-cuda passes 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

  1. changed the title [-]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[/+] on Nov 12, 2026
  2. added
    status:ready
    type:test
    priority:high
    area:core
    platform:linux
    on Nov 12, 2026
  3. added a commit that references this issue on Nov 15, 2026
    d630b27
  4. added this to the 0.9 milestone on Nov 30, 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:coreplatform:linuxpriority:highstatus:readytype:test

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions