Repository navigation
[Engine] AMD on Linux: expert cache in equal pieces, so caps load - #326
Open
okada-shogo wants to merge 2 commits into
Open
okada-shogo wants to merge 2 commits into
okada-shogo wants to merge 2 commits into
Conversation
…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>
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.
Problem and result
On native Linux ROCm (RX 9070 XT,
/dev/kfd),STRATA_GPU_EXPERTS=Nwas 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):STRATA_GPU_EXPERTS=1000STRATA_GPU_EXPERTS=1500STRATA_GPU_EXPERTS=2000STRATA_GPU_EXPERTS=2325Speed (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: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=0turns it off on native Linux,=arenaasks 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:
STRATA_VMM_EQUAL_PIECES=0|arena|all(main's variable;1isall). Unset:allunder WSL2 as on main,arena(the expert cache's pieces only) on native Linux.STRATA_ARENA_EQUAL_PIECESis gone.python3 tools/settings_register.py --checkandtools/test_settings_register.py: OK at this commit.engine.cppfor 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=0now turns both off.--tokens302,--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.STRATA_VMM_EQUAL_PIECES=0(measured asSTRATA_ARENA_EQUAL_PIECES=0before the rename): 2336 experts, same as main.Failed:
Not run:
Limits
5-round rotated runs of the earlier build give the same picture.
🤖 Generated with Claude Code