Skip to content

spark-runtime: don't report host MemAvailable as device free on a carve-out APU - #182

Merged
AzeezIsh merged 3 commits into
mainfrom
fix/carveout-free-memory
Oct 27, 2026
Merged

AzeezIsh merged 3 commits into
mainfrom
fix/carveout-free-memory

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

cuda_free_memory_bytes and the backend's free_memory return max(cuMemGetInfo free, /proc/meminfo MemAvailable). That's correct where the device draws from host RAM (GB10, a GTT-backed Strix Halo), and wrong on an APU with a dedicated carve-out larger than host RAM.

Measured on the 128 GB Framework (96 GiB BIOS carve-out, 31 GiB host RAM, Linux, ROCm 7.13):

  • Every free-memory read during a Flash-Next load returned the ~26 GB of host MemAvailable.
  • Meanwhile sysfs mem_info_vram_used climbed to 92.5 GiB; process GTT was 8 MiB.
  • The KV budget and the MoE transpose tier were sized from the host-RAM number, and the first KV allocation hit a full device.

Fix: unified_free() applies the MemAvailable floor only when the device total is at most ~10% above host MemTotal. It's unit-tested: GB10 and GTT Strix keep the floor; the carve-out case does not.

Effect

  • Flash-Next on the Framework: an honest refusal ("No memory left for KV cache ... 94.5 GB already consumed") instead of a crash in the middle of allocating the KV pool.
  • Nemotron 3.5 VL on the Framework: golden 3/3 at g8 and at off, byte-exact.
    • The KV pool is now sized to what the device can back: 1.4 GB = 189,744 tokens at g8.
    • Before, it claimed 12.9 GB / 1.69M tokens, about 11 GB more than the device could actually provide. Both are far above 32k x batch 1.
  • GB10 and strix: unchanged by construction (device total ≈ host MemTotal); covered by the unit tests. No GB10 run done.

🤖 Generated with Claude Code

AzeezIsh and others added 2 commits October 17, 2026 09:05
…ve-out APU

cuda_free_memory_bytes and the backend's free_memory took
max(cuMemGetInfo free, /proc/meminfo MemAvailable), which is right where the
device draws from host RAM (GB10, GTT-backed Strix Halo). On an APU with a
dedicated carve-out larger than host RAM it is wrong: the 128 GB Framework at
a 96 GiB BIOS carve-out has 31 GiB of host RAM, so every free-memory read
during a Flash-Next load returned the ~26-27 GB of host MemAvailable while the
carve-out filled (sysfs vram_used peaked at 92.5 GiB). The KV budget and the
MoE transpose tier were sized from it and the first KV alloc hit a full
device (#145).

unified_free() applies the MemAvailable floor only when the device total is
no more than ~10% above host MemTotal. Unit tests cover GB10, GTT Strix and
the carve-out case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…(500-LoC cap)

The carve-out fix took cuda_backend.rs from 475 to 545 lines. unified_free,
the /proc/meminfo readers and their tests move to a sibling module; the
call sites are unchanged (re-exported into cuda_backend).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant