Skip to content

[Engine] AMD on Linux: expert cache in equal pieces, so caps load - #326

Open
okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-native-equal-pieces
Open

okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-native-equal-pieces

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem and result

On native Linux ROCm (RX 9070 XT, /dev/kfd), STRATA_GPU_EXPERTS=N was refused for every N ("the card has N MiB for the expert cache, the first N experts take a few MiB more"). ROCm 7.2.4 refuses the shorter last piece of the expert cache after the 64 MiB ones. Without a cap the engine silently lost that last piece. WSL2 already maps equal pieces; native Linux did not.

Now every piece of a reservation has one size on all Linux HIP builds. Caps work, and a normal load keeps 3 more experts.

Experts kept in VRAM (Inkling 2 Mini IQ4_NL, RX 9070 XT 16 GB, --vram-reserve-mib 700):

Case main this PR
STRATA_GPU_EXPERTS=1000 refused 1000
STRATA_GPU_EXPERTS=1500 refused 1500
STRATA_GPU_EXPERTS=2000 refused 2000
STRATA_GPU_EXPERTS=2325 refused 2325
No cap (experts in VRAM) 2336 2348

Speed (tok/s, mean of 3 runs, main and this PR alternating, same card, --kv fp16, 32K context). "this PR alone" is the build of this PR:

Measure main this PR alone Change
Decode, 302-token prompt 63.9 64.0 +0.1%
Decode, 8,192-token prompt 58.7 58.8 +0.1%
Prompt, 302 tokens 498.8 495.1 -0.7%
Prompt, 8,192 tokens 1256.7 1252.3 -0.3%

The small prompt differences are inside the run-to-run spread of this box (5-run means of an earlier build of this PR: 1254.3 against main's 1256.9 at 8,192 tokens). Giving every reservation equal pieces instead (not this PR) was lower, 1251.1, so only the expert cache uses them.

Related discussion

none. Follows the equal-piece fix for WSL2 (STRATA_VMM_EQUAL_PIECES).

Approach

The expert cache's pieces are now all one size on every Linux HIP build (before, only under WSL2). The other reservations (attention caches, the staging buffer, a prompt's work memory) map as on main. STRATA_VMM_EQUAL_PIECES=0 turns it off on native Linux, =arena asks for only this on any Linux HIP build, and =all (or =1) is main's meaning: every reservation. CUDA, Metal and Windows HIP are unchanged.

The expert cache never maps past free VRAM minus the reserve. When the room limits it, it is rounded down to whole pieces (64, 32 or 16 MiB, whichever holds the most). A cap is accepted when its size, rounded up to a piece, fits; otherwise it is refused with the rounded room and need (room is always below need).

Validation

Passed:

  • Setting: STRATA_VMM_EQUAL_PIECES=0|arena|all (main's variable; 1 is all). Unset: all under WSL2 as on main, arena (the expert cache's pieces only) on native Linux. STRATA_ARENA_EQUAL_PIECES is gone. python3 tools/settings_register.py --check and tools/test_settings_register.py: OK at this commit.
  • Build at this PR's head: engine.cpp for HIP gfx1201 (ROCm 7.2.4). An independent review of the diff found no bugs; the old and new truth tables of the two switches agree except that =0 now turns both off.
  • Native Fedora, ROCm 7.2.4 container, RX 9070 XT, IQ4_NL, --tokens 302, --max-new 64, --top-probs 20, STRATA_FREEZE_EXPERTS=1: caps 1000, 1500, 2000 and 2325 load (main refuses all); 2328 also loaded on an earlier build when the card had more free VRAM. Earlier runs with less free VRAM refused caps 2328 and up with rounded numbers, for example 2328: room 11407 MiB, need 11417 MiB.
  • Cap outputs (md5) are the same as in the build that used equal pieces for every reservation, and on the final build.
  • STRATA_VMM_EQUAL_PIECES=0 (measured as STRATA_ARENA_EQUAL_PIECES=0 before the rename): 2336 experts, same as main.
  • Free VRAM at the lowest point of a run with a 700 MiB reserve (sysfs): 644 MiB against main's 631 MiB, measured on the build that used equal pieces for every reservation (a prompt's work memory can use some of the reserve in both).
  • Merge with [Engine] AMD on Linux: size the expert staging buffer to the misses #322 (port/hip-vram-trim) is textually clean; that build ran and cached 2447 to 2461 experts.
  • Speed tables above: 5 rounds, rotated order, main and this PR.
  • A fresh independent review of the diff (its WSL and regrow findings are fixed).

Failed:

  • none observed.

Not run:

  • Identity for the same cached set as main: main cannot run a cap, and its uncapped load caches a different number of experts.
  • CUDA, Metal, Windows HIP and WSL2 builds: the changed code is only built for non-Windows HIP, and WSL2 behaviour is the same code path as before.
  • The free-VRAM check and the [Engine] AMD on Linux: size the expert staging buffer to the misses #322 merge were run on an earlier build, not on this exact one.
  • A cache cut to nothing by a long prompt and then regrown keeps its piece size (reviewed, not run on its own).

Limits

  • A cache the room limits loses up to one piece (63 MiB at most) compared with a byte-exact map.
  • Attention caches on native still map pieces of different sizes, as on main.
  • Other native ROCm versions or cards were not tested.
  • In the 3-run speed table this PR always ran second in each pair, so order could bias its prompt rows slightly; the
    5-round rotated runs of the earlier build give the same picture.

🤖 Generated with Claude Code

okada-shogo and others added 2 commits November 25, 2026 08:17
…ATA_GPU_EXPERTS=N is accepted

Native Linux ROCm 7.2.4 (RX 9070 XT, /dev/kfd) refuses the shorter last piece of the expert
cache after the 64 MiB ones, as WSL2 does, so STRATA_GPU_EXPERTS=N was refused for every N
and an uncapped load silently lost its last piece.  The expert cache's pieces are now all of
one size on every Linux HIP build (STRATA_ARENA_EQUAL_PIECES=0 turns that off); the other
reservations (attention caches, the staging buffer, a prompt's work memory) map as before on
native, where every reservation in equal pieces cost 0.5% of 8K prompt speed.

The cache is sized to whole pieces that fit under free VRAM minus the reserve: rounded down
when the room limits it (64, 32 or 16 MiB pieces, whichever holds the most), and a cap is
accepted when its size rounded up to a piece fits.  A refused cap prints the rounded room
and need.  CUDA, Metal and Windows are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…UAL_PIECES

One variable for which VRAM reservations map in pieces of one size: all (or 1) every reservation, as on main with =1; arena the expert cache's only, the default on native Linux HIP; 0 none. Unset: all under WSL2, arena on native Linux, as before. STRATA_ARENA_EQUAL_PIECES is no longer read; the register note of STRATA_VMM_EQUAL_PIECES says what it does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@okada-shogo okada-shogo changed the title [Engine] AMD on Linux: let STRATA_GPU_EXPERTS caps load [Engine] AMD on Linux: expert cache in equal pieces, so caps load Nov 25, 2026
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