mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #880] [CLOSED] layer split: the stage weight trim works under auto too 4X gain in the prefill in 4 way ring #2889
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#2889
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/880
Author: @gopinath87607
Created: 10/5/2026
Status: ❌ Closed
Base:
main← Head:stage-trim-auto📝 Commits (2)
ce1e63flayer split: the stage weight trim works underautotoo572b607layer split:autoprices the stage's whole footprint, projections and cudaMalloc granules included📊 Changes
3 files changed (+221 additions, -48 deletions)
View changed files
📝
include/strata/core/native_dense.hpp(+17 -0)📝
src/core/native_dense.cpp(+61 -1)📝
src/program/generate.cpp(+143 -47)📄 Description
--trim-stage-weights(PR #559) /STRATA_STAGE_TRIM=1(PR #639) gives a stage only its own layers' denseweights, but it refuses to run unless
--layer-splitis written out:autochooses the split points 590 linesafter the stages' weights are loaded, so by the time the split is known there is nothing left to trim.
Those weights now load after the search. The expert caches are sized later, from live free VRAM, so they collect
the freed bytes.
On the 4-way IQ3_S rig (2x RTX 3060 12 GB + 2x RTX 5060 8 GB),
--layer-split auto,--trim-stage-weights:CUDA0 still trims only with an explicit
--layer-split. Its arena is read out to build the prompt path's PLEtables, 590 lines before the split exists, so moving it is the larger half of this change. It is also the cheap
half to leave: measured, it costs 1%.
The bug found in review, and the fix
Deferring the load also defers the allocations that come with it, and the search priced those from the pack
index instead of from
cudaMemGetInfo. That price was wrong three ways:stage_poolwas re-priced onlyif (stage_trim), which is false underauto- so it held the whole pool while the stage really loaded a carved one.NativeDense::loadallocates on the device, andnothing priced it. On this pack that is 2018.88 MiB over 300 matrices. This is the 1.92 GiB
@paulhothersall measured on a P40 + RTX 3070 rig, and it is what made the planner tell the 8 GB card it had
4.26 GiB free where v0.1.39 said 2.34 - so it picked K=2 instead of K=16, leaving the P40 on two layers.
cudaMallocrounding was not priced.NativeDense::loadmakes onecudaMallocper matrix and thedriver backs each call with 2 MiB granules, so the footprint is not the payload sum. Measured on the RTX 5060:
300 buffers asking 2018.9 MiB cost 2400.0 MiB - 381.1 MiB of rounding the search could not see.
The fix, as @j-luwierski suggested: one per-stage footprint calculation, covering the arena and the native
projections, priced from the pack before the search and subtracted per candidate inside
predictbesidesession_bytes, memoised by layer range.WeightTable::pool_bytesreadsindex.txtandNativeDense::weight_bytes_forreads the GGUF headers - neither allocates, so no device is needed and no stagehas to load early.
alloc_bytesprices each matrix the waycudaMallocbacks it: a 2 MiB granule for everymatrix of a MiB or more, the payload below, because the driver packs the small ones into the slack of the rounded
ones. On this pack's 300 matrices that prices 2255 MiB against a real 2238, +0.8% - erring high on purpose, so the
card is left slightly less room than it has rather than slightly more.
Measurements
Two devices (RTX 3060 12 GB + RTX 5060 8 GB),
--layer-split auto:K=20 is what plain v0.1.39 picks with no deferral at all, so the fix reproduces the old planner rather than
inventing a new one - same split, same 435 expert-cache slots, same 256-token chunk, throughput within 4%.
With the trim on:
+116% prefill, +15% decode. The chunk follows the split: 768 -> 2048 tokens.
On 4 cards the split does not move - K=10,19,34 in every arm - and prefill is 884.0 tok/s against 878.8 for
the unfixed build, i.e. noise. That rig cannot show the flaw: with four stages no card's cap is the binding
constraint. It is a regression test, and it passes.
Stacked on #887, which is where this actually bites
The paragraph above is why this PR's own four-card numbers look flat. #887 ("layer split: score every four-way
placement instead of guessing it") is the branch where it shows. #887 does not carry this bug - the deferral
comes from this PR - but it is what makes the four-way choice cap-bound, so a mis-priced card changes the answer
there instead of hiding inside a guess. 4 cards,
--layer-split auto --trim-stage-weights:The two are worth reading as a pair, and testing as one. #887 chooses between placements; this PR is what
prices the cards those placements are scored against.
My other two open PRs, #582 ("Serve tool result images") and #581 ("the Monitor's per-GPU cards"), are in the
build I run daily but are frontend and telemetry: they do not touch the split, the caches or the prompt chunk,
and they change none of these numbers.
Self-check
After each stage loads, the code compares the bytes the search priced against the bytes that stage really
took, read from
cudaMemGetInfobefore and after the load. It warns on any under-pricing (the actual bug - thecard is handed more than it can hold) and on over-pricing past 5% (the granule rule runs ~0.8% high by design, so
real drift would stand out). It stayed silent in every arm above, including the two-device runs where the old
price was 2.49 GiB out.
Known limits
two-device runs above are.
may round differently - @aswin-dot-R, if the split moves the wrong way on 2x gfx1201, say so and I will
re-measure the constant.
the log line to check is
layer split auto: CUDA1 ... GiB free before its weights, session and experts- itread 2.34 GiB on v0.1.39, 4.26 under the old build, and should read 2.34 again.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.