Repository navigation
docs(upstream): report the MLX CUDA graph-cache lifetime-miss abort - #1031
Merged
Merged
Conversation
MLX's `LRUCache` throws a fatal `Cache thrashing is happening` `runtime_error` once its miss counter passes `2 * capacity`, and that counter is lifetime-scoped: it is never reset on a hit, in `trim()`, or in `clear()`. Any long-lived, shape-diverse CUDA process therefore aborts eventually regardless of its hit rate, which is what killed a speculative-decode `mlxcel-server` on GB10 in #818. Raising `MLX_CUDA_GRAPH_CACHE_SIZE` to 2000 (bac0fca) only buys a proportionally larger lifetime budget, so the mitigation is a delay rather than a fix. Adds `docs/upstream/mlx-cuda-graph-cache-lifetime-miss-abort.md`, a report draft in the same form as the existing qmm non-determinism report: summary, evidence, root cause with quoted code, a minimal fix diff, a repro, and the affected surface. It recommends a windowed miss rate plus demoting the `throw` to a one-shot warning, with reset-on-hit as a one-line fallback. Every claim was verified against the pinned MLX source at `b7c3dd6d`, not against the issue body. Three corrections came out of that: the pin is `b7c3dd6d`, not the `57c66cac` / 0.32.1 the issue cites (all cited line numbers still hold); an opt-out already exists as the undocumented, all-or-nothing `MLX_ENABLE_CACHE_THRASHING_CHECK=0`, which MLX's own test suite sets; and the graph cache key is graph topology (node-type codes plus dependency-edge ordinals), not tensor shape, so distinct keys accumulate with op-stream diversity rather than with model shapes. Also records the removal condition on `cuda_graph_cache_default()` so the raised default is not orphaned when the MLX pin moves. Validated with `cargo fmt -p mlxcel-core --check`, `cargo clippy -p mlxcel-core --lib --all-targets -- -D warnings`, `cargo doc --no-deps -p mlxcel-core` (no new warnings in `hardware.rs`), and `cargo check -p mlxcel-core --features cuda`. Closes #821
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…ablup#1031) ## Summary Delivers issue lablup#821's upstream report as a committed draft under `docs/upstream/`, matching the existing `mlx-cuda-quantized-matmul-nondeterminism.md` convention, and records the removal condition for mlxcel's raised `MLX_CUDA_GRAPH_CACHE_SIZE` default so it is not orphaned when the MLX pin moves. No upstream issue or PR was filed; the maintainer files that personally. MLX's `LRUCache` throws a fatal `Cache thrashing is happening` `runtime_error` once its miss counter passes `2 * capacity`, and that counter is lifetime-scoped: never reset on a hit, in `trim()`, or in `clear()`. Any long-lived, shape-diverse CUDA process aborts eventually regardless of hit rate (lablup#818). Raising the cap to 2000 (`bac0fca`) buys a proportionally larger lifetime budget, so it delays rather than fixes. ## What changed - `docs/upstream/mlx-cuda-graph-cache-lifetime-miss-abort.md` (new): report draft with Summary / Evidence / Root cause (quoted code at exact file:line) / Minimal fix (diff) / Minimal standalone repro / Affected surface. Recommends a windowed miss rate plus demoting the `throw` to a one-shot warning, with reset-on-hit as a one-line fallback, and tabulates the other four caches that share the same fatal semantics. - `src/lib/mlxcel-core/src/hardware.rs`: appends a tracking note to `cuda_graph_cache_default()` pointing at the report and lablup#821, and stating the removal condition (once an upstream fix lands that stops punishing a large lifetime working set and the MLX pin moves past it, the 2000 default can be lowered toward MLX's 400 or dropped). `src/lib/mlxcel-core/src/autotune/ops/cuda_kernel_knobs.rs` was left alone deliberately: both of its references to `apply_cuda_graph_cache_default` cite it as the precedent for the startup env-application contract, not for the default's value, so a removal-condition pointer there would be noise. ## Verified against the pinned MLX source Everything was read at `b7c3dd6d27f45b5365b08a840310187dc503f1db` (the pin in `src/lib/mlx-cpp/CMakeLists.txt`), not copied from the issue body. Three places where the issue body is stale or imprecise: - The pin is `b7c3dd6d`, not the `57c66cac` / "0.32.1" the issue cites. All the cited line numbers still hold at `b7c3dd6d`: `lru_cache.h:91` throw, `lru_cache.h:131` counter, `device.cpp:210` default capacity 400, `device.cpp:490` key construction. - An opt-out already exists: `lru_cache.h:35-40` arms the check only while `MLX_ENABLE_CACHE_THRASHING_CHECK` (default 1) is truthy. It is undocumented and all-or-nothing across the graph, conv, SDPA, and FFT caches, and MLX's own test suite sets it to 0 (`python/tests/mlx_tests.py:9`, added by the same commit that introduced the check). - The graph cache key is graph topology (node-type codes from `subgraph_to_key` plus dependency-edge ordinals), not tensor shape. Distinct keys accumulate with op-stream diversity and commit cut points, not with the number of model shapes. ## Test plan Docs plus a doc comment, so there is no new logic to unit-test. Gates run with the pinned 1.93.1 toolchain: - [x] `cargo fmt -p mlxcel-core --check` (clean) - [x] `cargo clippy -p mlxcel-core --lib --all-targets -- -D warnings` (clean) - [x] `cargo doc --no-deps -p mlxcel-core` (succeeds; no warnings attributed to `hardware.rs`) - [x] `cargo check -p mlxcel-core --features cuda` (clean) - [x] an em-dash scan over the branch diff returns nothing, and no AI-attribution strings appear in the diff or commit message The synthetic Python reproducer in the report is labeled as not run: no MLX Python build with CUDA was available here. The report leads with the server-level repro that actually produced the abort, and the only quantitative datum used is the 13/13-requests figure from the `hardware.rs` doc comment. Closes lablup#821
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Delivers issue #821's upstream report as a committed draft under
docs/upstream/, matching the existingmlx-cuda-quantized-matmul-nondeterminism.mdconvention, and records the removal condition for mlxcel's raisedMLX_CUDA_GRAPH_CACHE_SIZEdefault so it is not orphaned when the MLX pin moves. No upstream issue or PR was filed; the maintainer files that personally.MLX's
LRUCachethrows a fatalCache thrashing is happeningruntime_erroronce its miss counter passes2 * capacity, and that counter is lifetime-scoped: never reset on a hit, intrim(), or inclear(). Any long-lived, shape-diverse CUDA process aborts eventually regardless of hit rate (#818). Raising the cap to 2000 (bac0fca) buys a proportionally larger lifetime budget, so it delays rather than fixes.What changed
docs/upstream/mlx-cuda-graph-cache-lifetime-miss-abort.md(new): report draft with Summary / Evidence / Root cause (quoted code at exact file:line) / Minimal fix (diff) / Minimal standalone repro / Affected surface. Recommends a windowed miss rate plus demoting thethrowto a one-shot warning, with reset-on-hit as a one-line fallback, and tabulates the other four caches that share the same fatal semantics.src/lib/mlxcel-core/src/hardware.rs: appends a tracking note tocuda_graph_cache_default()pointing at the report and chore(deps): report the MLX CUDA graph-cache lifetime-miss abort upstream and track dropping our local default #821, and stating the removal condition (once an upstream fix lands that stops punishing a large lifetime working set and the MLX pin moves past it, the 2000 default can be lowered toward MLX's 400 or dropped).src/lib/mlxcel-core/src/autotune/ops/cuda_kernel_knobs.rswas left alone deliberately: both of its references toapply_cuda_graph_cache_defaultcite it as the precedent for the startup env-application contract, not for the default's value, so a removal-condition pointer there would be noise.Verified against the pinned MLX source
Everything was read at
b7c3dd6d27f45b5365b08a840310187dc503f1db(the pin insrc/lib/mlx-cpp/CMakeLists.txt), not copied from the issue body. Three places where the issue body is stale or imprecise:b7c3dd6d, not the57c66cac/ "0.32.1" the issue cites. All the cited line numbers still hold atb7c3dd6d:lru_cache.h:91throw,lru_cache.h:131counter,device.cpp:210default capacity 400,device.cpp:490key construction.lru_cache.h:35-40arms the check only whileMLX_ENABLE_CACHE_THRASHING_CHECK(default 1) is truthy. It is undocumented and all-or-nothing across the graph, conv, SDPA, and FFT caches, and MLX's own test suite sets it to 0 (python/tests/mlx_tests.py:9, added by the same commit that introduced the check).subgraph_to_keyplus dependency-edge ordinals), not tensor shape. Distinct keys accumulate with op-stream diversity and commit cut points, not with the number of model shapes.Test plan
Docs plus a doc comment, so there is no new logic to unit-test. Gates run with the pinned 1.93.1 toolchain:
cargo fmt -p mlxcel-core --check(clean)cargo clippy -p mlxcel-core --lib --all-targets -- -D warnings(clean)cargo doc --no-deps -p mlxcel-core(succeeds; no warnings attributed tohardware.rs)cargo check -p mlxcel-core --features cuda(clean)The synthetic Python reproducer in the report is labeled as not run: no MLX Python build with CUDA was available here. The report leads with the server-level repro that actually produced the abort, and the only quantitative datum used is the 13/13-requests figure from the
hardware.rsdoc comment.Closes #821