Skip to content

docs(upstream): report the MLX CUDA graph-cache lifetime-miss abort - #1031

Merged
inureyes merged 1 commit into
mainfrom
update/issue-821-mlx-graph-cache-upstream-report
Aug 5, 2026
Merged

inureyes merged 1 commit into
mainfrom
update/issue-821-mlx-graph-cache-upstream-report

Conversation

@inureyes

@inureyes inureyes commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Delivers issue #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 (#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 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.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:

  • 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 to hardware.rs)
  • cargo check -p mlxcel-core --features cuda (clean)
  • 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 #821

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
@inureyes inureyes added status:review Under review type:dependency Dependency updates priority:low Low priority area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Aug 5, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels Aug 5, 2026
@inureyes
inureyes merged commit 4f5e313 into main Aug 5, 2026
4 checks passed
@inureyes
inureyes deleted the update/issue-821-mlx-graph-cache-upstream-report branch August 5, 2026 03:48
@inureyes inureyes self-assigned this Aug 31, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:low Low priority status:done Completed type:dependency Dependency updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(deps): report the MLX CUDA graph-cache lifetime-miss abort upstream and track dropping our local default

1 participant