mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5265] [Engine] layer split auto: price the prompt read by the bytes each stage streams over its own link #3134
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#3134
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?
Originally created by @Norhiro on GitHub (Nov 5, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5265
Area
[Engine]
Problem
On a two-card layer split with unequal links,
--layer-split autopicks the split by the predicted decode window. The prompt read then runs much slower than a split chosen for it.Rig: RTX 3060 12 GB on PCIe 3.0 x16 (probe 12.3 GB/s) + RTX 5060 Ti 16 GB on 3.0 x8 (6.9 GB/s), i7-7800X, 125 GiB RAM, Qwen3.8-Flash-Next UD-Q4_K_XL native. All experts were in RAM, with v0.2.10 chunk-major (the default).
link_miss_scaleonly scales from a 4x gap on (#2007), so the search does not see the difference.Why the prompt read is slow here (nsys, one 31.1K prompt, auto K=18):
So in chunk-major each chunk re-streams nearly every expert of every layer: copies ÷ (chunks × layers) comes to about 450-580 a layer a chunk out of 512, and the read is the slower stage's link time.
What I measured
The prompts are the same 31.1K and 26.2K tokens every time. There is one start per row; the rows marked "same session" were re-run on the same day.
Layer sweep with
--trim-stage-weights:STRATA_PREFILL_AUTO_MAX=16384A cliff in the auto chunk. On auto, a 3060 cache of 1,473 slots gives a 6,400-token chunk and 1,472 slots gives 6,144. That puts the 31.1K prompt in 5 or 6 chunks, a 4 s difference between two starts of the same config.
A model of the prompt read, fitted to these runs
layer_msis the engine's own per-layer time (1.46 ms on the 3060, 0.75 ms on the 5060 Ti).cfrom the nsys kernel time (31 us a layer a token on the 3060, 17 us on the 5060 Ti, so c ≈ 0.0212), the fit over 22 points gives N = 516 (≈ n_expert = 512), a cache term φ = 0, t0 = 5.4 s, RMSE 1.0 s (max 2.3 s).Prototype:
STRATA_SPLIT_OBJECTIVE=prompt(opt-in, +47/−2 insrc/program/generate.cpp)When the variable is set,
consider()scores a placement by the formula above for one chunk at its slowest stage. The decode window only breaks ties.STRATA_SPLIT_PROMPT_CHUNK, or--prefill N, or else 8192.Same build, same session:
STRATA_SPLIT_OBJECTIVE=promptPart of the gain is the chunk: at K=23 the auto chunk came out at 8,192, so the prompt needs 4 chunks instead of 6. Auto cannot use stage trim, so the hand-picked K=24 + trim + AUTO_MAX (29.2 s) stays about 3.7 s ahead.
Related
--layer-split-objective interactive|prompt|decode. Both were closed in the 0.2.0-beta tracker reset, not rejected.Questions on scope
--layer-split-objective promptas in #2385? I would rather build on #2385's flag than open a competing one.autouse stage trim once the split is chosen? Today trim needs an explicit K. On this rig trim is worth another ~3-4 s by letting the auto chunk grow to 8,192.Validation
Passed:
ffa80d73): sm_86;120, CUDA 13.3, g++ 15,STRATA_ISA_FLOOR=avx, 170/170.Not run:
consider(), so the variable would change its scoring too. I have not run it on three cards and do not know whether the formula holds there; the pipeline fill may matter more with three stages.c= 0.0212 comes from one nsys run on this pair.AI-assisted: Claude Code ran the measurements on my machine and drafted this; the numbers and log lines are from those runs.
@udqe commented on GitHub (Nov 5, 2026):
The other half of the control for this model: a pair whose links are equal enough that the pathology cannot form. Same engine, and conveniently we booted
STRATA_PREFILL_TIMING=1this morning for the other thread (#5202), so the per-phase summaries are fresh.Our box: 2x RTX 4090 Windows pair under a fixed layer split (22), links the engine probes as near-identical Gen4 x16 - the gap is nowhere near the 4x gate of
link_miss_scaleeither, but unlike your rig the two stages would balance even if the gate moved. Per-prompt summaries of 150 K-295 K reads: the copy side of the read iswait copy 2.8 %andgather 1.0 %of the GPU timeline at 295 K (941 ms select and 3,415 ms select across sizes aside) - the read is owned by embed+steps ~25 %, the expert GEMMs ~28 % and dequant ~16 %. That is the symmetric-link prediction of your own model: when link GBps is equal, the min-max over stages balances by construction, the byte term stops discriminating between placements, and the decode-chosen split serves prompts nearly as well - which matches our season: our split was picked on decode measurements early in the season and we have never measured a prompt-side regret against it at these sizes. Your issue is therefore the clean statement of what the pathology actually is: an unequal link crossed with a chunk-size cliff, not chunk-major streaming per se - on equal fast links the same streaming is real (your phi = 0 holds here too: our cache never stopped the stream) and merely cheap.On your question 3, a production data point: our config has run
STRATA_STAGE_TRIM=1with a hand-picked split since early in the season (it is one of the eight env keys we quote in our footers), and through 168 engine boots of varied traffic the trim path has produced no failure we have had to chase; our auto prompt chunk reads 8192 in today's log. We cannot answer "would auto pick a trim-compatible K" - no auto here after the initial search - but the trim engine itself is stable enough in our traffic mix to survive being an auto-side default, which is what your question is really probing.On question 1, with a fact checked on today's tree: #2385 closed unmerged, and
--layer-split-objectivedoes not exist in main at 2026-11-03 (grep empty) - so "build on #2385's flag" is really "resurrect that flag surface", and worth saying out loud to the maintainer, because #2385'sinteractiveobjective (decode optimum first, prompt-pipeline min-max only among non-regressing placements) is already half of your design, missing exactly your bytes term. If the surface returns, your objective slots in as itspromptmode with the byte term as the scoring function, and the env-vs-flag question answers itself in the planner's own vocabulary. Either way keep the prototype's three log lines - your own PR #5255 is the argument: a placement decision that prints its numbers (predicted X ms per chunk at its slowest stage) is reviewable by a reader who cannot run your rig. Thelink_miss_scaleline you cite is real, by the way:generate.cpp:5773(main@11-03) comments "only from a 4x gap on" verbatim - the search really is blind to your 1.8x pair today.Offer and caveats: today's three summaries (150,691 / 199,339 / 294,925 tokens with full phase lists) are yours to fold in as symmetric-link validation rows if they help the fit - with the honest caveat that our pair runs
--pcie-frac 0.20, so our per-chunk streamed set is not your near-512-of-512, and the transferable numbers are the copy-phase shares rather than the bytes; the timing run itself costs ~4 % of read rate (declared there too); and we have not built or run your prototype, so nothing here tests the objective itself, only the model's symmetric prediction.Scope: measurement quotes are from our production log today (protocol and the TIMING-overhead caveat disclosed in #5202); user, not maintainer, on a box shape your sweep does not cover (equal links) and covers in kind (Windows).
(ai-assisted; our quoted lines from production boot 2026-11-05 11:09 JST, per-prompt
strata prefill timingsummaries)@Norhiro commented on GitHub (Nov 5, 2026):
@udqe thank you. The symmetric pair is the control this needed, and "an unequal link crossed with a chunk-size cliff, not chunk-major streaming per se" is a better statement of the problem than mine.
Your data. Yes please, the three summaries would help. I would use them for what they can show:
--pcie-frac 0.20your stream is not the near-512-of-512 set mine is, so I would not fit N or φ from them.Question 3. 168 boots of
STRATA_STAGE_TRIM=1with a hand-picked split and no failure to chase is the evidence the "could auto trim" question needed. Thank you for writing it down.Question 1, restated after your check. You are right:
--layer-split-objectiveis not in main, so building on #2385 means bringing that flag back, not reusing it. For the maintainers, the proposal is:--layer-split-objective decode|prompt.decodestays the default and keeps today's behaviour byte for byte.promptscore a placement by the slowest stage per chunk. Each stage costsmax(layers × n_expert × slot bytes / its probed link, layers × c × layer_ms × chunk), the formula above. #2385's prompt objective used the decode miss cost from the routed mass the caches hold. On this rig that cost does not predict the prompt read (φ = 0).interactiveobjective (decode optimum first, prompt min-max only among non-regressing placements) unless the maintainers want it. On this pair it cannot reach K=23. The decode prediction rises from 60.0 to 63.7 ms, but the measured decode did not drop.I have not written the flag version yet; the prototype is still the env variable. I will turn it into the flag form if the scope is agreeable.
I had not used
STRATA_PREFILL_TIMING=1. I will run it next time beside nsys, so the phase shares here can be compared with yours on the same footing.@udqe commented on GitHub (Nov 5, 2026):
The two fields you asked for, plus one wrinkle about where our link numbers come from - it matters for how comparable they are.
PCIe share: the CPU pool takes 50 us per missed expert (62.7 GB/s of expert bytes), the link 26.4 GB/s -> pcie_frac 0.20 (was 0.55- ours is a manual override, and this is the line where our per-chunk streamed set is capped before your n_expert term; quoting it rather than interpreting it, since the exact pool/link split is yours to read as the code says.One caveat that generalizes to your 12.3 and 6.9: our season-long probe record shows CUDA0 reading 6.7 GB/s in 10 of 57 starts (CUDA1 never read low), and a boot that takes a misprobe runs with it all day. If the objective ever scores placements from a fresh probe, a single-start value is a fragile input on Windows; your logged predicted-ms line is what makes that failure visible, which is one more argument for keeping it.
For your run beside nsys: the per-chunk line carries
GPU timeline X ms, wall Y ms, host staging Z ms- share comparisons are cleanest on the GPU timeline column, and host staging drifts upward within a prompt as chunks queue behind the GPU (ours grew 391 to 5,344 ms across one 150 K read), so don't read that column as a stall rate.The three summaries plus these fields are then a full row for the symmetric case: equal probed links, x1.00 both sides, 8192 chunk, 3.14 MB slots, and a read owned by embed+GEMM+dequant with the copy side at 2.8 % + 1.0 %. If your formula lands on "the byte term does not discriminate here", the rig and the numbers say the same thing from opposite ends of the link-gate.
Since nobody else seems to: we pulled your four related issues today and they check out as described - #509 is a gen3 x4 riser on the V100 side (2.86x prefill gap), #2052 is indeed still open, and #2644/#1616 are the tiny-stage passes, with #1616's chunk clamp from a one-layer card being the same #448 machinery your 1,473/1,472-slot cliff rides on. The lineage in your issue is real, not recycled.
(ai-assisted; quoted lines from our engine log, boots 2026-10-31 04:55 and 2026-11-05 11:09 JST)
@Norhiro commented on GitHub (Nov 5, 2026):
@udqe thank you for the fields, and for checking the four linked issues. Here is the follow-up I promised, plus one result that tests the formula harder than the K sweep did.
Your rig in the formula. With equal links the byte term grows with the layer count at the same rate on both stages. Even with N = 516 as an upper bound (your
pcie_frac 0.20streams fewer), it is about 1.35 s per 8,192-token chunk for 22 layers and 1.60 s for 26. So it points to the same split the compute term does, and does not discriminate. That matches your 2.8 % + 1.0 % copy share and the decode-chosen split serving prompts fine.Probe stability, the other end. On this Linux box the probe never misread: 71 boots logged, CUDA0 (3060, Gen3 x16) at 12.3–12.4 GB/s and CUDA1 (5060 Ti, Gen3 x8) at 6.7–6.9 GB/s. With your 10 of 57 low reads on Windows, I agree a single-boot value is a fragile input. So the predicted-ms line should print the GB/s it priced, so a misprobe shows up in the same line.
STRATA_PREFILL_TIMING=1on this pair (31.1K prompt, GPU-timeline column as you suggested):--trim-stage-weights+STRATA_PREFILL_AUTO_MAX=16384(chunk 11,008): 14–23 %, and the 3060 becomes compute-bound (attn 23 %, GEMM 26 %, wait copy 1 %).K sweep and repeats (trim, chunk 8,192, 31.1K):
Three restarts of the best config gave 29.03 / 29.08 / 29.04 s, so ±0.05 s between boots.
A harder test: NVFP4 experts on the same pair. Same build, all experts in RAM,
w4a8on both cards (the 3060 has no FP4 MMA; asking forw4a4printed the per-card fallback note, as documented). The expert copy shrinks from 3.15 to 2.76 MB, and the auto chunk grows with the freed VRAM:The best K moves from 24 to 18. With smaller copies the 5060 Ti's receive is no longer the limit. The 3060's compute is, at about 1.8x the 5060 Ti's time per layer, so the 3060 gets fewer layers. Fewer layers on the 3060 also frees enough VRAM for a 15,872-token chunk, which reads 31.1K in two chunks instead of three.
I priced each stage with per-layer copy sizes (UD mixes Q4_K/Q5_K, so even UD needs that) and read the chunk off a short engine start for each candidate. On that basis the formula ranked NVFP4 K = 18 first. It reads 1–3 s low on NVFP4, though, so the compute coefficients are not right for that format yet.
What this means for the proposal:
cost(l)per layer.max(receive, compute)is needed, not the byte term alone. The NVFP4 optimum is set by compute.RAG answers on a fixed 16-question set scored the same for UD and NVFP4-GPTQ. That is a narrow check, not a quality claim.
@udqe commented on GitHub (Nov 6, 2026):
Convergence note: since the exchange above, the two halves of this ask have each grown an independent witness on a third and fourth machine, and there is now code moving toward the same seam from a different direction. None of it tests your formula on new byte-cells - the two rows I can add are about the piece that applies even when the link term cannot discriminate, which is exactly your symmetric-pair conclusion.
Row 1 - the equal-link short-prompt cost, on a third machine. #5376 (RX 9070 pair, same UD-Q4_K_XL pack as our control, both cards x8 PCIe 5.0 so links are as equal as ours): dual versus single, same profile, three repetitions per case. At 16K prompts the second card pays the way your formula says it should (prompt rate +33%, TTFT -25%). But the SHORT case moves the wrong way: TTFT 0.60 s single -> 0.96 s dual (+60%), totals +25%. That is on a pair where
link_miss_scalewould score both stages x1.00 and the byte term would balance - the pathology your rig caught at 31K does not need an unequal link to show up at the other end of the size range; a fixed per-request split cost is enough. Ifautopriced the read at all, this is the cell where it should say "the decode-chosen split costs a short prompt 0.36 s" - today nothing says it.Row 2 - a crossover documented at the doc level, the fourth machine. #5187 measured the same trade end to end (2x 4060 Ti 16 GB, split engine versus stock layer split, agent workload): the layer split wins where requests are long and loses below about 730 generated tokens per request, with the crossover now printed in
docs/SPLIT_ENGINE.mditself, stated with the one-machine-one-run caveat. Same physics as the decode-chosen-split question here: the right answer depends on work per request, so a price that is constant in request length cannot be the last word.The code is moving too, from PRs rather than reports. #4534 (price a pipelined two-stage split) and #4549 (keep the draft head's room out of the split search) are both live and both in this search's territory - #4549 is literally about a term the search over-counts by the draft-head reservation, which is our box's shape (283 MiB printed per boot). Whatever the formula's final shape, it should absorb those two without breaking the byte term this thread worked out.
Where I would still add one term, agreed with your thread's conclusion rather than against it: on equal-link pairs - the class this thread now covers from two sides (ours at 26.4/26.4 GB/s probed, the 9070 pair at x8 5.0) - the stream term does not discriminate, and the only thing left that the search cannot see is the fixed cost per request: hand-off, first-chunk latency, and the short-prompt penalty above. A probe-time constant, measurable once at boot the way the links already are, would make the search honest on symmetric pairs without touching your unequal-link formula at all. Two of the four machines in this thread's evidence set are symmetric; that class is the common case, and it is currently the one the search optimizes blind.
Numbers quoted from #5376 (medians of n=3, complete runs, both 12/12) and #5187 (their table, one run each, stated as such by their author); our own rig's fields are in the comments above and unchanged.
@Norhiro commented on GitHub (Nov 6, 2026):
@udqe thank you for collecting these. I measured the same short-prompt case on this pair before answering, because it tests which decision the per-request cost would change.
The standard benchmark,
standard-v1, on this rig. Engine 0.1.57, NVFP4-GPTQ experts, one run each. The run is nonconforming only because I skipped model hashing.The 11/12 is one miss on I2 at temperature 1.0. So the #5376 shape shows up here too: the pair loses on the short prompt and wins from 4K on. On this rig the short-prompt cost is about 1.1 s, not 0.36 s.
On an unequal pair that cost depends on K. I timed only the read of an ~80-token prompt (engine
prompt_ms, 10 prompts with distinct first tokens, so there was no prefix reuse):The read gets about 38 ms faster per layer moved to the x16 card. Each layer costs about 27 ms on the 3060 stage and 65 ms on the 5060 Ti stage. The 2.4x gap is wider than the 1.8x link ratio, so it is not only bytes over the link. Extending the line to K=48 gives about 1.3 s, close to the 3060 alone (1.12–1.39 s). That leaves little room for a fixed split cost on this rig, but it is an extension of a line, not a measurement. Four points on one line cannot separate a constant from the per-layer slope.
What I take from it.
So my proposal is to keep #5265 to choosing K within a fixed stage count, with the prompt length as an input. The
promptobjective would score at a given prompt length, the auto chunk by default. The log line would print the predicted short-prompt cost next to the long one, so the trade is visible. One card versus two, with the fixed cost you describe, could be its own issue that prints the crossover length rather than choosing. I can write that up if you think it is worth filing.(A side note on #5376: the "short" totals, 6.4 → 8.0 s, include output length under
reasoning_effort xhigh. So I would quote the TTFT there, as you did, rather than the totals.)#4534 and #4549. Both should fit without changing the byte term.
--pipeline-windows 2, the slower stage instead of the sum. In thepromptobjective the decode prediction only breaks ties, so it would change the tie-breaker and nothing else.I have not run either PR on this rig. The flag version (
--layer-split-objective decode|prompt) is still waiting on a maintainer's view of the scope.@udqe commented on GitHub (Nov 6, 2026):
Conceding your first point outright, then taking the second offer.
You are right about the constant: a term that is common to every placement shifts all scores by the same amount and cancels in the comparison. My "makes the search honest on symmetric pairs" line was written for the wrong question - inside a fixed two-card search it changes no K, and the decision it would actually change (one card versus two) is one the auto search does not currently make at all. So: agreed, the fixed-cost idea does not belong in this formula, and my row 1 (#5376's short case, TTFT 0.60 s -> 0.96 s on an equal-link pair) is a one-versus-two datum, not a K datum. Thanks for pinning that down.
Your K-vs-length table makes the scoping sharper than either of us had it. On your pair an ~80-token read goes 2,677 -> 1,994 ms going K=12 -> 30 (your fastest short-read placement puts most layers on the fast-link side and leaves the narrow stage the least to fill - short reads are dominated by what the slowest stage has to chew through once, not by the steady-state stream), while your 31.1K read is fastest at K=18. So the ranking the objective should produce flips inside two-card placements as a function of prompt length - which is exactly your proposal: keep #5265 about choosing K with prompt length as an input and predict the short-prompt cost alongside the long one. No byte-term change needed, as you said, and the prototype's shape survives.
The one-versus-two question is the one my fixed-cost framing was really groping at, and I think it is worth its own issue. Yes to opening it, and yes, please write it up - you have the unequal-pair half of the evidence set. What I can contribute from this box (2x RTX 4090, Windows, links probed 26.4/26.4 GB/s, main engine, fixed split 22):
docs/SPLIT_ENGINE.mditself, their one-run caveat stated), and #5376's 9070 pair crosses somewhere between 80 tokens (dual loses, TTFT +60%) and 4K (dual wins, TTFT -7.7%, totals at cap). Two equal-link boxes, two different crossover neighborhoods - which is the argument that the crossover needs measuring per box, the same conclusion this thread already reached for K.One taxonomy suggestion for the write-up: there are two crossovers living under what looked like one. The axis I keep hitting (short prompt, dual worse than single, symmetric links, both quantizations) is cards-into-the-request: fixed per-request cost versus streaming gain, decided before any K matters. The axis your table exposes is layers-onto-which-card: min-max fill versus steady-state balance, decided inside a fixed card count. An issue that prices the first and leaves the second to this thread should not need to mention the byte term at all, which keeps it reviewable independently of this formula.
Numbers quoted: your K table and short-read rows as you posted them; #5376 medians (n=3, complete runs); #5187's documented crossover, one run, as stated by its author. Our curve, when posted, will carry its own repetition table.
(ai-assisted; all quoted lines pinned in our notes; happy to rerun any arm)