mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3185] [Engine] arena: hand back the block for layers a GPU holds whole (opt-in, saves 21.7 GiB of RAM) #4494
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4494
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3185
Author: @weituotian
Created: 10/19/2026
Status: 🔄 Open
Base:
main← Head:pr/arena-release📝 Commits (8)
a5550e3docs: upstream v0.2.2 measured - first token -28.4% (10/10), but its auto layer split picks K=31 and costs 5.8% decode035d13aarena-skip 1/3: load_experts_ranges takes a dst_bias34dd151arena-skip 2/3a: the tail block's plumbing (members, set_split_layer, release_tail) - inert until open honours it0f744f3arena-skip 2/3b+3/3: two-block load, blob_at() branch, and the release decision after host_resfe7542aarena-skip: works on the GGUF path - the V100 layer block (21.71 GiB) is handed back5a97722docs: design note for the arena releaseb26e4d5arena-skip: hand the block back only when the tail stage lends nothing, and make the own-buffer margin per-stage4fc7884arena-skip: do not create the tail block in modes that move residency at run time📊 Changes
7 files changed (+799 additions, -24 deletions)
View changed files
➕
docs/ARCH-EXPERT-MEMORY-2026-10-19.md(+477 -0)➕
docs/UPSTREAM-0.2.2.md(+68 -0)📝
include/strata/core/expert_source.hpp(+23 -1)📝
include/strata/core/pinned.hpp(+4 -2)📝
src/core/expert_source.cpp(+118 -16)📝
src/core/pinned.cu(+6 -4)📝
src/program/generate.cpp(+103 -1)📄 Description
Problem and result
On a layer split, the layers a GPU stage holds whole — every one of its experts resident in that card's cache — are never read from the CPU expert arena. They are still copied into it and paid for in RAM/commit for the whole run. On this rig that is 21.71 GiB of a 46.84 GiB arena, and it is the difference between "the Windows commit limit is 117 GiB and 0.5 GiB of it is left" and 21 GiB of headroom.
After (opt-in,
STRATA_ARENA_RELEASE_BLOCK=1):experts loadedfile_blobs/file_mb(per request)Default off: one block, byte-identical to before.
Related discussion
No issue filed — this grew out of a private investigation on a 3090 + V100 rig. A related data point appeared in the thread from @ruibeikaa: on four GP100 dies where every layer is resident he frees the whole arena (
STRATA_ARENA_FREE=1), engine private memory 51.86 → 5.02 GiB, 15 replies and state hashes identical, decode 56.38 → 56.34 tok/s, start-up 276 → 277 s. That is the all-resident case (one allocation, nothing to partition); this PR is the per-stage case. His guard list is what the guards below were checked against.Approach
A second allocation at the split point, released whole. A large-page region cannot be freed in part (
MEM_DECOMMITonMEM_LARGE_PAGESfails), and the default arena is anonymous 2 MiB pages — so a released page would read back as zeros, not as a fault to be re-read.release()already exists and already acts on every VRAM-resident pair, but only for the file-backed arena (STRATA_ARENA_MMAP), whereMADV_DONTNEEDjust means a minor fault later. The only way to keep the large pages is to make the releasable layers their own allocation: the split point is known ~1,600 lines before the arena is built (stage_ofatgenerate.cpp:4339,arena_src.openat 4995), and the tail stage's layers are a contiguous layer range.Released only on proof, and only after the prompt partition. The block goes back when every pair of those layers has
host_res != kNotResident: a layer with all 512 experts resident has no spare slot toadmit()another, so the adaptive tier can never evict one into a read. That is true when the table is built — but the serve setup may then hand that stage's prompt path a loan of its own cache slots, which evicts experts for the whole prompt and refills them after it. So the release waits for the partition and happens only when the tail stage lent nothing:Guards. The block is not created at all when residency can move at run time:
--vram-elastic,--peer-device,--adapt-async,STRATA_RAM_ADAPT/STRATA_RAM_ADAPT2, and the Foresight swap space (STRATA_FS_SLOTS). Not touched:--mmap-experts/--resident-*(own partial-residency machinery), the paddedSTRATA_PIN_BY_NEEDlayout,--shared-expert-arena,--expert-cache-device1..3—open()falls back to one block for all of them.Both expert sources. The pack here has no
experts.bin(native_experts.txt→ the GGUF shards), soopen()takes thefrom_ggufpath. That needed two changes toload_experts_gguf: adst_bias(it writes atdst + lay.blob_offset(...), which a second allocation cannot use) and a layer range (it walked alllay.n_layers, so a block would have filled all 48 layers).load_experts_rangesgot the samedst_bias. Both default to the old behaviour.Files.
include/strata/core/pinned.hpp,src/core/pinned.cu(dst_bias),include/strata/core/expert_source.hpp,src/core/expert_source.cpp(the secondPinnedArena,blob_at()branch,release_tail(),close()),src/program/generate.cpp(set_split_layerbehind the switch, the residency proof, the deferred release, the guards,STRATA_SPLIT_OWN_MARGIN_MIB).Validation
Passed:
Build — revision
4fc78847(branchpr/arena-release, cut from46c152a1= v0.2.7.1), Windows 11, MSVC 19.4x, CUDA 12.x,-DCMAKE_CUDA_ARCHITECTURES="70;86"(sm_70 for the V100, sm_86 for the 3090):Start, 3090 + V100,
--layer-split 27,--max-context 262144,--kv int8 --kv-resident 32768:Ten replayed real agent requests (
replay.py --suite 56:6,0:4, recorded traffic, ~200K-token contexts, paired per request against the same 10 without the switch): decode median −1.2 % (5 up / 5 down), VRAM hit 96.70 % vs 96.15 %, CPU pool 3.10 % vs 3.55 %,file_blobs/file_mb0 on every request, zerocould not produce a blob, engine log free of errors.The borrow case — K=26 with
--vram-reserve-later-mib 0, where the V100 lends 1,027 slots:The runtime-residency guard — same rig with
--vram-elastic:Failed:
prefill: expert source has no blob/ engine exit 1 / restart loop — observed in an earlier revision of this branch when the release ran before the prompt partition (K=26). Fixed by deferring the release; the case above is the regression test. No other failure observed.Not run:
Linux, HIP, SYCL and Metal builds (this tree has no
pinned.dp.cpp); the AMD/Linux path ofload_experts_rangeswith a non-zerodst_bias; a single-GPU run;STRATA_ARENA_MMAPand--shared-expert-arena(both keep one block, unexercised with the switch on); the router look-ahead with a released block — in this tree it warms CUDA0's arena and the block is a later stage, but I could not prove it never reaches a later stage, so it is the one guard I did not add.Limits
--layer-split autopicks K=31 (V100 gets 17 layers, 8,704 slots) where the condition still holds for the V100 but the split is 5.8 % slower than K=27 for unrelated reasons; at K=26 the V100 has 22 layers, still 100 % covered, but decode is flat and first token 32 % worse. K=27 is the measured optimum here.host_resat start plus the prompt partition); the guards cover the modes I know can move residency afterwards. A future mode that evicts outside that list would make a released block readable — the failure is loud (nullptr →the expert source could not produce a blob), not silent, which is the property this design relies on.STRATA_SPLIT_OWN_MARGIN_MIB(default 1,536 MiB, the pre-existing slack) is only there so one stage can keep its prompt buffers when it is just short of that margin;--no-prefill-borrowdoes the same for every stage and costs the other card's cache (measured: 8,709 → 7,819 slots, decode −9 %).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.