Repository navigation
[Engine] AMD on Linux: size the expert staging buffer to the misses - #322
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
…ROCm on Linux Same bits for a given cached set (placement: more experts cached). ROCm on Linux lends nothing back to the expert cache (vmm_unmap() frees VRAM only with its addresses), so the staging buffer was a whole layer for the whole run: 1,033 MiB for Inkling 2 Mini IQ4_NL, whose Q8_0 layers have 128 experts of 8.1 MiB. Once the cache is filled, load() now cuts it to the most a layer's call copies through it (the experts the layer lacks, plus a margin for what the attention caches may still take from the cache), with room for vram_ahead()'s groups of 4 slots so the router launches stay as they were. The freed VRAM goes to the expert cache. A cache that later loses more than the margin copies a layer in rounds; on RDNA4's BLAS loop that changes the last bits of those calls. Inkling 2 only (trims_stage()); CUDA, Metal and Windows HIP are unchanged. STRATA_STAGE_TRIM=0 keeps the whole layer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ATA_STAGE_TRIM) STRATA_STAGE_TRIM is the program engine's split-stack weight trim; strata-poly no longer reads it, so setting it for a split config cannot change poly's staging buffer. The new STRATA_POLY_STAGE_FIT=0 keeps the whole layer, as STRATA_STAGE_TRIM=0 did, and is registered. 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 ROCm on Linux the expert staging buffer is never lent back to the expert cache (
vmm_unmap()frees VRAM there onlytogether with its addresses), so it stays one whole layer for the whole run. For Inkling 2 Mini IQ4_NL that is
1,033 MiB: its four Q8_0 layers have 128 experts of 8.1 MiB. A prompt call only copies the experts the cache lacks
through it.
This PR cuts the buffer, once the cache is filled, to what a layer's call can copy (plus a margin), and gives the rest
to the expert cache. On an RX 9070 XT at a 32K context the buffer goes from 1,033 to 384 MiB and the cache holds 131
more experts. Same bits for the same cached set.
Mean of 3 runs each,
--prompt-batch 1024,--max-context 32768, a warm 302-token prompt first in every engine.Prompt (tok/s)
Decode (tok/s)
Each run (tok/s)
Speed: Salad RX 9070 XT container (noisy node, not used above)
A rented RX 9070 XT (Salad, 12 vCPUs, ROCm 7.2.4 container), same commands and commit, 3 rotated rounds. This node
was noisy: runs of the same build spread by up to 23%, and the engines' cache sizes at load varied by run. The
numbers are listed for completeness; the native Fedora rows above are the clean A/B.
Experts at load in these runs: main 2,230-2,235, this PR 2,310-2,363.
VRAM: experts and staging buffer (RX 9070 XT, MiB)
Requests in one engine: 2,048 + 64, 8,192 + 64, 302 + 256, 2,048 + 64.
ROCBLAS_DEVICE_MEMORY_SIZE=8388608frees about 24 MiB (no moreexperts).
ROCBLAS_USE_HIPBLASLT=0frees 112 MiB, but prompts become about 2x slower.Related discussion
None. This follows from a VRAM breakdown of Inkling 2 Mini on the RX 9070 XT, where the staging buffer was the
largest item after the expert cache and the dense weights.
Approach
Engine::trim_stage()runs inload()right afterfill_expert_cache(), and again inresize_cache().attention caches may still map and the reserve, spread over the layers by bytes.
vram_ahead()'s 7 groups of 4 slots andcard_rows()slots, so the router launches andfar_plan()stay as they were. HIP builds no mirror, so nothing is uploaded into those slots.grow_cache()).cudaMallocbuffer and allocating a smaller one made ROCm 7.2.4 later fail to re-reserve the expertcache's addresses at the same place. The engine then stopped on the next VRAM resize.
resize_cache()maps the whole layer again before it refills the cache, then cuts it for the new cache.STRATA_VMM_RELEASE_WITH_ADDRESSESis set (ROCm on Linux, WSL included), and only for Inkling 2(
trims_stage()). CUDA, Metal, Windows HIP and the other families are unchanged.--stage-mib, the VRAM pool or a layer split.STRATA_POLY_STAGE_FIT=0keeps the whole layer. (STRATA_STAGE_TRIMis the program engine's split-stack weight trim; strata-poly does not read it.)Validation
Passed:
STRATA_POLY_STAGE_FIT=0(new name, in the settings register; was read asSTRATA_STAGE_TRIM).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.every step, 32 tokens generated.
STRATA_FREEZE_EXPERTS=1. The PR's cache growth was turned off in a scratch build, and main was given--vram-reserve-mib 576, so both cache 2,350 experts.STRATA_GPU_EXPERTS=2000 STRATA_FREEZE_EXPERTS=1, the same cache fnv in both builds. Prompts of 302, 2,048, 5,040 and 8,192 tokens, 8,192 with--no-graphs, and a forced multi-round--stage-mib 70vs main at 70 MiB and vs main at its default: SAME 7/7.VRAM, a 2K prompt, thenVRAM 700, then another 8K prompt,then
VRAM. All 3 requests finished, at contexts 32,768 and 131,072, on native Fedora and on Salad.strata-poly --serve --prompt-cache 0 --conversation-cache-mib 0 --kv fp16 --prompt-batch 1024 --max-context N.--threads 11on the native box.STRATA_VRAM_TRACE=1.Failed:
cudaMallocbuffer and allocated a smaller one. It aborted invmm_unmap()on the first VRAM resize after an 8K prompt. That is fixed by the VMM pieces above.Not run:
Limits
call copies its misses in rounds. That is slower. On RDNA4's default BLAS loop it can also change the last bits of
those calls, because a row's product there depends on the launch's rows. A frozen cache never does this.
STRATA_GPU_EXPERTS=Nalready fails on main: the expert cache's smaller last VMM piece isrefused, and
vmm_equal_pieces()is only on under WSL. This PR does not change that.🤖 Generated with Claude Code