mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #580] [CLOSED] Weight carve 0138 #2704
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#2704
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/580
Author: @gopinath87607
Created: 10/3/2026
Status: ❌ Closed
Base:
main← Head:weight-carve-0138📝 Commits (5)
e9267b2weights: a layer-range carve in the dense-weight loader144461bnative dense: the same layer-range carve for the projections034a46dlayer split: each stage holds only its own layers' dense weightse223797layer split: STRATA_STAGE_CACHE_SLOTS pins a stage's expert cache688f46flayer split: CUDA0 holds only its own layers' weights too📊 Changes
7 files changed (+672 additions, -135 deletions)
View changed files
📝
CMakeLists.txt(+11 -0)📝
include/strata/core/native_dense.hpp(+16 -3)📝
include/strata/core/weights.hpp(+61 -5)📝
src/core/native_dense.cpp(+41 -3)📝
src/core/weights.cpp(+71 -7)📝
src/program/generate.cpp(+220 -117)➕
tests/core/weights_carve_test.cpp(+252 -0)📄 Description
What this is
A
--layer-splitstage loaded the whole model's dense weights. On the 4-GPU IQ3_S rig that is3,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.
Each stage now holds only its own
[lb, le)layers' weights. The VRAM that frees goes to thatstage's expert cache.
This is the first of the pieces #390 was cut into. Nothing else from that branch is in here: no
placement search, no helper tier, no Monitor change, no image-API change. The split behaviour is
identical to before — the carve changes where the weights live, not what the run computes.
What changed
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.
The ranges reach:
WeightPool::load(..., layer_lo, layer_hi)— the pack arena (src/core/weights.cpp)WeightPool::pool_bytes(..., layer_lo, layer_hi)— the priced size, same predicateNativeDense::load(..., layer_lo, layer_hi)— the GDN/QSA/shared-expert projections, 2,018.88 ofthose 3,485.66 MiB (
src/core/native_dense.cpp)NativeDense::served_layer_bytes()— the priced size for the native halfsrc/program/generate.cpp, moved after the split is choseneverything
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.
What it buys
The rig's own 4-way IQ3_S config, nothing pinned —
--layer-split auto,--expert-cache auto,--prefill auto:32768,--kv int8 --kv-resident 32768, context 262144, one run of each arm:Both arms chose the same split, 0-13 / 14-28 / 29-37 / 38-47, so the VRAM is the only thing that
moved. Per card:
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.Testing
tests/core/weights_carve_test.cppcovers the range predicate and the priced-vs-loaded agreement:every tensor the loader keeps is in range, every tensor it drops is out of range, and
pool_bytes(lo, hi)equals the bytesload(lo, hi)actually takes — over every range, on asynthetic pack built to exercise the rounding, and on the real IQ3_S pack when one is named:
It also pins the no-op: a full range with no
skipreproduces the pack's own pool byte for byte.There is no multi-GPU integration test in this repo, so the equivalence claim is an A/B rather than
a unit test.
STRATA_WEIGHT_SLICE=0runs the pre-carve path and=1the carve, from one binary, sothe two arms differ in nothing but where the weights live. Everything else is pinned, because an
auto-sized cache would read the freed VRAM and change the slot counts — and then a token difference
would say nothing about the weights:
--layer-split, so the placement is not a variable--expert-cachesmall enough that CUDA0's cache is not clamped differently in the two arms--vram-reserve-mibexplicit, so the adaptive reserve stays outSTRATA_STAGE_CACHE_SLOTS=Spins every stage's cache to the same slot count in both arms--prefillexplicit,STRATA_LOOKAHEAD=0The two arms, 4-way IQ3_S,
--layer-split 10,19,34,--expert-cache 512,STRATA_STAGE_CACHE_SLOTS=512, context 16384, a 512-token prompt and 32 greedy tokens:STRATA_WEIGHT_SLICE=0=1expert_slotsvram_free_mib3680a63c…3680a63c…Same slot counts, same placement, the same 32 token ids, byte for byte — and 2,794 MiB more free
VRAM on CUDA0. That is the carve moving bytes and nothing else.
The ids are the 32
Tlines each arm's log prints, in order, one per line:STRATA_WEIGHT_SLICE=0andSTRATA_STAGE_CACHE_SLOTSare test hooks in the same spirit as theexisting
STRATA_TEST_CACHE_FAIL; the first is also the revert switch, so the carve can be A/B'dfrom a config without a rebuild.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.