mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #390] [CLOSED] Multi-GPU: a --layer-split stage holds only its own layers' weights, and every card's leftover VRAM spills into a helper expert tier (4-way IQ3_S: 9,269 -> 14,172 expert slots, prefill chunk 2,048 -> 4,096) #2616
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#2616
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/390
Author: @gopinath87607
Created: 10/1/2026
Status: ❌ Closed
Base:
main← Head:layer-split-weight-carve📝 Commits (10+)
f05298cweights: a layer-range carve in the dense-weight loader74f29e7native dense: the same layer-range carve for the projectionsecce4felayer split: each stage holds only its own layers' dense weights0ecfb32layer split: STRATA_STAGE_CACHE_SLOTS pins a stage's expert cache71aba72layer split: CUDA0 holds only its own layers' weights tooa084595ngram: the PLE table's row size comes from its GGML type4309a4cserve: the Monitor's per-GPU cards, each card's free VRAM, and the vision footprint8a9c179layer split: score every four-way placement, and spill the VRAM a cache cannot usec13f056Merge origin/main into rel-0.1.31 (PR #390: the layer-split weight carve)c57f58dserve (vision): an image inside a tool_result reached the model as an empty result📊 Changes
26 files changed (+2262 additions, -355 deletions)
View changed files
📝
CMakeLists.txt(+19 -0)➕
configs/strata-iq3_s-4way.json(+55 -0)➕
configs/strata-q8_0-4way.json(+55 -0)📝
include/strata/core/expert_source.hpp(+9 -1)📝
include/strata/core/native_dense.hpp(+16 -3)📝
include/strata/core/remote_experts.hpp(+35 -0)📝
include/strata/core/weights.hpp(+61 -5)📝
include/strata/kernels/ngram.hpp(+21 -3)📝
include/strata/prefill/prefill.hpp(+13 -0)📝
serve/frontend.py(+16 -3)📝
serve/server.py(+75 -22)📝
serve/telemetry.py(+10 -3)📝
serve/test_server.py(+192 -3)📝
serve/web/app.css(+9 -0)📝
serve/web/app.js(+94 -5)📝
serve/web/index.html(+6 -0)📝
src/core/native_dense.cpp(+41 -3)📝
src/core/remote_experts.cpp(+69 -26)📝
src/core/weights.cpp(+71 -7)📝
src/kernels/ngram.cpp(+41 -9)...and 6 more files
📄 Description
What this is
Three things a
--layer-splitrun needed, plus the Monitor work that made the first one visible.The headline is the carve: every stage used to load the whole model's dense weights. Then the
VRAM those weights were wasting is given back — first to each stage's own expert cache, and then,
for whatever is still left over, to a helper tier that any stage's misses can hit.
1. A stage holds only its own layers' weights
Each
--layer-splitstage loaded the whole model's dense weights: on the 4-GPU IQ3_S rig,3,485.66 MiB per card — 1,466.78 pack arena + 2,018.88 native dense — about 10.2 GiB across four
cards, holding layers that stage will never run. A stage running 9 of 48 layers still held all 48.
Weights now get the treatment the session already got.
session_bytes(g, cells, k, lo, hi)is purearithmetic, so the split search prices a candidate layer range before allocating it; weights were
the one per-stage resource that never got that. The carve extends the same rule: a layer-range
predicate on the loader's existing skip/compact path, and the per-stage load moved down to after
st.lb/leare set. One rule produces both the priced size and the loaded layout, so they cannotdisagree.
Measured, 4-way IQ3_S (split 10,19,34 auto):
Per-card reclaim: CUDA0 2.56 GiB, CUDA1 2.78, CUDA2 2.33, CUDA3 2.42.
The same carve applies to the native GDN/QSA/shared-expert projections
(
NativeDense::load's range), which is 2,018.88 of those 3,485.66 MiB.Three things that fail silently
[lb, le), not[0, le).[0, le)leaves twothirds of the hole unclaimed while every printed number looks plausible — this got as far as a
commit before the per-range byte comparison caught it.
ffn_gate_inpout of CUDA0'stable to warm the next layer's pages. A dropped row is still in the metadata but has
data == nullptr, so the copy fails,okgoes false, and the lookahead turns itself offwithout saying so. All 48 are kept — 120 MiB is cheaper than losing the prefetch.
--split-skip-if-fitsmeasures CUDA0 before its weights exist, so the full dense cost isadded to what it holds back. Without that term the carve makes the check spend exactly the VRAM
it is about to free.
STRATA_WEIGHT_SLICE=0is the kill switch, so one binary runs both A/B arms.STRATA_STAGE_CACHE_SLOTS=Spins stage caches (test-only), because they are auto-sized from freeVRAM and freeing 2.5 GiB per stage would change the slot counts and mask the comparison.
2. Every card's leftover VRAM spills into a helper expert tier
The carve exposed a second problem it does not fix on its own: a stage's cache only ever holds its
own layers' pairs, so once a stage holds its whole range the cache cannot grow and the cost model
scores its spare VRAM at exactly zero. On the 4-way rig that stranded real memory — CUDA0 at
3,144 MiB and CUDA1 at 1,739 MiB while both 5060s were packed at 7,225 and 7,311.
With
--layer-split, every card the run already uses — CUDA0 included — now hands its leftover toa helper tier holding the globally hottest pairs no stage cache can hold. Stage misses hit it.
--no-remote-auto/STRATA_REMOTE_AUTO=0is the kill switch, soit is revertable and A/B-able from the config JSON without a rebuild.
--expert-cache-deviceNpath keeps its hard failure.Prefill, whose GPU MoE path measured 2.2× slower and corrupting.stage-relative
d_restable is untouched.untouched — it still picks what it picked.
The tier count goes 3 → 4 (
kRemoteMax) to cover four cards, and a helper may now live on device 0(
device < 1→device < 0), which is whypreflight(0)runs in the early window before anythingelse creates that context.
Selection is by byte budget, not slot count: a slot count is a poor proxy for a native pack
where
blob_bytes(l)varies per layer. The selection loop is extracted into a CUDA-free functionand unit-tested (
tests/core/remote_budget_test.cpp, run underCUDA_VISIBLE_DEVICES=-1) for thebudget bound,
claimed/primary-cache disjointness, rank order, and bit-for-bit agreement with theold
slotsmode.Not yet measured on the rig. The mechanism, the budget arithmetic and the disjointness are
covered by the unit test; the decode and hit-rate effect needs the 4-way run, which the cards were
busy for. Worth watching: the per-tier log line, and whether CUDA0's and CUDA1's stranded VRAM
shows up as tiers.
3. Score every four-way placement
The search tried every placement up to 3 GPUs and, beyond that, shared layers in proportion to
speed. Four cards got a heuristic instead of a search. It now enumerates all C(L−3, 3) = 15,180
placements and scores each. Memoised per-range fills (1,121 walks) bring it from 740 ms to 14 ms.
The mass model moved from
mass[r] = (r+1)^-1.2to the increment ofH(f) = 1 − (1 − f)^boverthe held fraction,
b = 3(STRATA_SPLIT_COVER_B). At f = 0.8138 (20,000 held) it gives 99.35%,identical to the old fit — so the validated 2-GPU regime is unchanged.
4. The Monitor's per-GPU cards
The split was invisible: one card holding 27 GiB read the same as four. Each GPU now gets its own
card, built from what only the engine knows (layer range, KV and prompt buffers, expert cache)
paired with that card's VRAM from NVML. The engine reports its allocation as seven parallel CSV
fields on the INFO line — single comma-separated tokens because the server splits on whitespace.
NVML's
mem_freewas being read and thrown away; each card's name is asked for once rather thanonce a second. A device that both runs a stage and hosts a helper merges into one card rather than
appearing twice.
The image encoder is a separate process reporting no memory of its own, so its footprint is
measured as the card's free VRAM lost while it started —
strata-visionruns a 2048px warm-upbefore printing READY, and a delta outside 64–8192 MiB is discarded as noise, keeping the last good
reading. The encoder is pinned to the card the config's
vision.cuda_devicenames (else theengine's first), which is the card the Monitor must show it on.
5. The PLE table's Q8_0 row
mainnow takes the PLE table's row size from the tensor's own GGML type (IQ4_NL 90 B, Q5_0110 B, FP8 E4M3 160 B). This branch adds the fourth format the published Q8_0 checkpoint carries:
Q8_0, 170 B — 5 blocks of 34, one fp16
dper 32 values, no min term. Same geometry, so therow cache, the batch slab and the 16-rows-make-2560 flatten are untouched; only the stride and the
block decoder differ.
ple_row_bytes()/ple_dequant_row()dispatch to the decoders inartifact/dequant.hpp, so the PLE row and the artifact reader cannot drift apart on the blocklayout. A row decoded at the wrong stride opens and decodes plausible garbage, so the row size and
format are logged once at open.
Unlike Q5_0, Q8_0 is not restricted to
--ple-io mmap: the Direct reader takes the row size.6. Three fixes found on the way
An image source that 404s, refuses the connection or names an unknown host raised
OSError, whichthe dispatcher does not map to a status — the client's connection closed with no reply at all
(
curl: (52) Empty reply from server) instead of a 400. Those now raiseValueErrorlike everyother bad image source.
free_vram_mibis one helper taking an index rather than two copies of thesame NVML call.
Testing
tests/core/weights_carve_test.cppcovers the range predicate and the priced-vs-loaded agreement.tests/core/remote_budget_test.cppcovers the helper tier's selection.There is no multi-GPU integration test in this repo, so the carve was verified by A/B: the engine
driven directly through
--serve(no tokenizer, so stdin takesGEN <n> <ids>and stdout emitsT <id>per token), with an explicit split and everything pinned — explicit--prefill,STRATA_LOOKAHEAD=0,STRATA_STAGE_CACHE_SLOTS— two binaries, one token hash, and the same hashas before the change. The
--split-device 0bit-exact A/B is only meaningful with--no-remote-auto; with tiers on, tokens may legitimately differ from the CPU pool's float order.Merged
mainmainis merged into this branch (128 commits, 0.1.32–0.1.34) and the conflicts resolved instead ofre-opened: the PLE row-size design is
main's with Q8_0 re-added on top, and the upstream changesin the split region (
Verifier::set_commit_async, #340's streamed-ring reserve,stage_room'ssearch/reserve distinction) are ported onto this branch's structure rather than replacing it.
Verified after the merge: builds clean, 56 of 58 ctest targets pass serially (the two failures are
environmental —
ple_paritywants a model shard that is not in the tree,expert_multi_testwantsAVX512-VNNI/VBMI), and
serve's 120 Python tests pass.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.