Skip to content

test(cuda): run the CUDA cache-default check in its own process - #2988

Merged
inureyes merged 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:fix/cuda-cache-defaults-test-order
Nov 15, 2026
Merged

inureyes merged 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:fix/cuda-cache-defaults-test-order

Conversation

@Jaeyeong-CHOI

@Jaeyeong-CHOI Jaeyeong-CHOI commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

native_env_tests::the_cuda_cache_defaults_reach_mlx is the one test that fails in make verify-test-cuda on a host with a CUDA device. It reads a setting that MLX has memoized since the pin moved to 9f806b36 (#2876), and in the gate's order the CUDA device has resolved that setting first. This moves the check into a test binary of its own, where nothing has touched MLX before the appliers run. With it the gate passes every test binary.

Related issues

Closes #2987.

Type of change

  • test — tests only

Cause

The test removes MLX_CUDA_GRAPH_CACHE_SIZE, calls apply_cuda_graph_cache_default() and reads the setting back through mlx_env_int. Since #2876 that read is mlx::core::config::get, which 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 at 9f806b36). The CUDA backend makes that first read itself, with its own default of 400, when a command encoder is constructed (graph_cache_ in the device.cpp overlay). The gate runs the mlxcel-core lib suite single threaded in name order, so ffi_tests::* have built the device long before native_env_tests::* run.

Before #2876 the same read was mlx::core::env::get_var, a plain getenv on every call. Measured on this host, the mlxcel-core lib suite with --features cuda -- --test-threads=1:

Commit MLX pin Lib suite The test alone After one GPU test
912858435, the parent of #2876 7ca40033 2214 passed, 0 failed ok ok
f45a92cc9, #2876 9f806b36 2213 passed, 1 failed ok FAILED, 400
ce6855bc8, main 9f806b36 2260 passed, 1 failed ok FAILED, 400
this PR 9f806b36 2260 passed, 0 failed moved moved

Production is not affected: the binaries call the appliers once at the top of main, before any MLX op.

Change

  • tests/cuda_cache_defaults_env.rs: the same check, both names through the real appliers and read back through mlx_env_int, as the only test of its binary. It asserts the value in the C runtime first (native_getenv), so a failure tells an applier that did not write from a setting MLX had already resolved.
  • src/lib/mlxcel-core/src/native_env_tests.rs: the test is removed, with a comment where it was that says why it cannot live there. The other tests in that file use NATIVE_ENV_TEST_* names that nothing else reads, so they are not exposed.
  • No production code changes.

Test plan

Run on this PR's commit (62b6010c7, one commit on ce6855bc8) on a DGX Spark (GB10).

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --features cuda -- -D warnings (the Linux spelling of the template's line)
  • make verify-test-cuda (cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1): all 188 test binaries pass, 15487 tests passed, 0 failed, 496 ignored. On main it is 186 of 187 with this test as the one failure
  • cargo test --profile test-fast --features cuda -p mlxcel-core --lib --no-fail-fast -- --test-threads=1: 2260 passed, 0 failed (main: 2260 passed, 1 failed)
  • cargo test --profile test-fast --features cuda --test cuda_cache_defaults_env: 1 passed, also on a second run in a row
  • The new test fails for the two things it guards. With a GPU eval placed in front of the appliers, which is what the lib suite did: MLX_CUDA_GRAPH_CACHE_SIZE as MLX reads it, left: 400, right: 2000. With the write removed from apply_cuda_graph_cache_default: MLX_CUDA_GRAPH_CACHE_SIZE in the C runtime, left: None
  • The self-hosted ci.yml jobs a pull request from a fork does not get, run by hand: clippy (cargo clippy -p mlxcel --lib --tests -- -D warnings, default features), cpu-link (both commands; its native_env filter still runs 13 tests, since the moved one was CUDA only), xla-compile (cargo check --features cuda,xla-iree --all-targets, cargo check --no-default-features --features xla-diagnostics --all-targets): all pass
  • scripts/ci/check_env_var_docs.py, scripts/ci/check_native_env_writes.py, scripts/insert_apache_header.py --check, scripts/ci/check_cross_repo_refs.py, and python3 -m unittest discover -s tests -p 'test_*.py' (219 tests): all OK
  • Validated with a real checkpoint: not applicable, no inference code changes. cargo build --release compiles neither file
  • cargo deny check: not run and not applicable (no manifest, lockfile or deny.toml change)
  • Metal and Windows: not built or run here

Notes for reviewers

  • Why a binary of its own, and not an assertion on the environment alone. Asserting native_getenv(name) == "2000" in place would be independent of the order too, but it would no longer show that the value reaches MLX, which is what fix(windows): environment set from Rust does not reach MLX's getenv #2803 was about. tests/rocm_fft_cache_env.rs and tests/cpu_device_custom_kernel_gates.rs are the precedents for giving a process-global read a process of its own.
  • The binary has to stay a single test. A second test that evaluates an array, or reads either name, brings the order dependence back. Its header says so.
  • MLX_CUDA_SDPA_CACHE_SIZE has the same exposure and was never reached. The old loop asserted the graph cache first and stopped there. Its cache is built at the first cuDNN attention call. The new test checks both names, in a process where neither has been read.
  • Not run: Windows, where fix(windows): environment set from Rust does not reach MLX's getenv #2803 lived, and the reason the check exists. The test's content is unchanged apart from the extra C-runtime assertion, and it uses the same mlxcel_core::native_env functions as before. On a build without the cuda feature the file is an empty test binary (#![cfg(feature = "cuda")]).

Checklist

  • PR title uses a Conventional Commits prefix
  • One logical change per PR
  • Updated docs/: no user-facing behavior or supported-model change
  • Updated // Used by: ... comments: no shared function is modified
  • No secrets, credentials, or .env files committed

`native_env_tests::the_cuda_cache_defaults_reach_mlx` is the one test that
fails in `make verify-test-cuda` on a host with a CUDA device:
`MLX_CUDA_GRAPH_CACHE_SIZE` reads 400 where the test expects the 2000 that
`apply_cuda_graph_cache_default` has just set.

The read is memoized. lablup#2876 moved the MLX pin to 9f806b36, where a setting
is read through `mlx::core::config::get`, which stores the first value it
returns for a name and answers from that store from then on. The CUDA
device makes that first read with its own default of 400 when a command
encoder is constructed. The gate runs the lib suite single threaded in
name order, so `ffi_tests::*` have built the device long before
`native_env_tests::*` run. Alone, the test passes.

The check moves to `tests/cuda_cache_defaults_env.rs`, a test binary of its
own in which nothing has touched MLX before the appliers run. That is the
order production has: the appliers run once, at the top of `main`, before
any MLX op. It also asserts the value in the C runtime, so a failure tells
a missing write from a setting MLX had already resolved.
@inureyes inureyes added area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific priority:high High priority status:review Under review type:test Test related changes labels Nov 15, 2026
@inureyes

Copy link
Copy Markdown
Member

Implementation hardening for #2988.

Reviewed #2987: the native environment read now happens in a dedicated integration-test process, removing the memoized read/order race without changing production defaults. No additional security or performance defect was found.

Validation: the_cuda_cache_defaults_reach_mlx passed in its own process during the combined full CUDA run.

Commands: cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1 on the combined candidate tree has passed the affected module tests noted above; the broader run is still finishing. cargo fmt --all -- --check and python3 scripts/ci/check_kernel_dtype_keys.py passed. Required GitHub checks are checked again immediately before merge.

@inureyes
inureyes merged commit d630b27 into lablup:main Nov 15, 2026
31 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 15, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific priority:high High priority status:done Completed type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants