mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2690] [Engine] verify: STRATA_VERIFY_DEFER_CPU=1, a layer's light CPU expert rows join at the next layer's FFN half (heavy rows on time, 0.1 by default; opt-in) #4214
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#4214
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/2690
Author: @lask3802
Created: 10/15/2026
Status: 🔄 Open
Base:
main← Head:verify-defer-heavy📝 Commits (9)
19aede1verify: STRATA_VERIFY_DEFER=1, a layer's CPU expert rows join the residual before the next layer's FFN-side read1a99ad3verify: STRATA_VERIFY_DEFER, review: the zeroed rows by a kernel, the hits in the combine, a profile slot, docs1750313verify: STRATA_VERIFY_DEFER_HEAVY=, a deferred layer keeps its CPU rows of routing weight >= w on timed4deb0cverify: STRATA_VERIFY_DEFER is now STRATA_VERIFY_DEFER_CPUf4ab7e7verify: STRATA_VERIFY_DEFER_HEAVY is now STRATA_VERIFY_DEFER_CPU_BELOW, 0.1 by default53858fdverify: STRATA_VERIFY_DEFER_CPU_BELOW, review: start-up lines and docs0f15f75verify: STRATA_VERIFY_DEFER_CPU on 0.2: off with STRATA_PCIE_BALANCE=1, docs for the cold overlapa7b5c88verify: STRATA_VERIFY_DEFER_CPU on 0.2.3: off while the DFlash2 taps run2e57231verify: with the DFlash2 taps, deferral is off from the start📊 Changes
10 files changed (+469 additions, -17 deletions)
View changed files
📝
docs/DETAILS.md(+63 -0)📝
include/strata/core/expert_source.hpp(+6 -0)📝
include/strata/core/peer_experts.hpp(+5 -0)📝
include/strata/core/verify.hpp(+15 -0)📝
include/strata/kernels/verify_kernels.hpp(+14 -0)📝
src/core/expert_source.cpp(+45 -4)📝
src/core/peer_experts.cpp(+3 -0)📝
src/core/verify.cpp(+235 -13)📝
src/kernels/cuda/verify_kernels.cu(+80 -0)📝
src/program/generate.cpp(+3 -0)📄 Description
Problem and result
On one GPU with experts in RAM, every decode layer waits for the CPU pool's expert rows before its combine, and the
GPU idles while the CPU computes. This PR adds an opt-in setting,
STRATA_VERIFY_DEFER_CPU=1, that lets a layer go onwithout the CPU's light expert rows and add them one step later, so the CPU computes them while the GPU runs the next
layer's mixer.
STRATA_VERIFY_DEFER_CPUunset or0: unchanged. No allocation, no graph node, no kernelchoice and no host step changes. (With
STRATA_VERIFY_PROFILEor the #649 trace on, the profile has one more stampat the end of the mixer's out-projection: "late rows", near 0 then.)
STRATA_VERIFY_DEFER_CPU=1: the CPU rows of routing weight below 0.1 (STRATA_VERIFY_DEFER_CPU_BELOW)join layer l at layer l+1's FFN half; the heavier ones are waited for in their own layer. This changes the
output. On 0.2.0-beta, on an RTX 2080 Ti alone, it is +15.4% decode tok/s at low context at a teacher-forced KL of
0.098 against the default (Validation). On the same run the placement floor (the default with 6% more expert
slots) is 0.030 and the shipped route tail skip's own KL is 0.064, so on this card the deferral costs about 1.5x the
tail skip. On the earlier base of this PR (v0.1.44.1, an RTX 3080) it was +15.8% at a KL of 0.088, about the tail
skip's 0.083 there.
This PR is now rebased on
main(0.2.0-beta) after the tracker reset; the earlier description was for v0.1.44.1.Related discussion
Approach
With
STRATA_VERIFY_DEFER_CPU=1:STRATA_VERIFY_DEFER_CPU_BELOW, 0.1 by default)and does not wait for them. It waits only for the heavy rows: the pool computes the experts of the CPU entries whose
weight is >= w first, raises a new mapped flag (
h_pflag_, to the layer's ring), then computes the rest. The rowscome out as in one pass: the pool cuts its phases by output rows, so only the order of the jobs changes. post(l)
combines the heavy rows with a new kernel
copy_rows_by_weight(the plan's GPU rows zeroed ascopy_rows_from_mappeddoes).residual with layer l's own routing weights and pending-write coefficient,
2*sigmoid(inject/hc)(new kerneldefer_add_rows), then does its FFN-side read as usual.doorbell_publish, the variant--remote-expert-optuses), andrun/servicehand the pool the weights and a partial hook for the deferredlayers.
Nothing the late addition reads is overwritten before it: pre(l+1)'s attention-side read writes
inj_(not layer l'sinj2_), and its router (w_), the next plan (plan_,skip_) and its doorbell come after the addition. So thehost's next expert step never rewrites the doorbell payload or
h_ymiss_earlier than without deferral, and no bufferis doubled.
Not deferred: the stage's last layer, and layer 0 when layer 1 runs the PLE block. Windows that run without deferral
(one line at the first capture says which and why): batch windows,
--spec-splittoken groups,--remote-expert-opt,STRATA_PCIE_BALANCE, the all-resident graph (no CPU rows), a stage with no layer to defer, a control vector on thestage.
The split is turned off, and every CPU row joins late, when the verifier takes the device plan
(
STRATA_VERIFY_DEVICE_PLAN=1) and with--peer-deviceor a helper cache (--expert-cache-device1..3), whose rowsland after the CPU's (one start-up line).
runandserviceraise the partial flag after every pool call, so a layerthe pool did not split never leaves a GPU wait behind. The new flag is released with the others before the engine
ends (#267) and shows in the stall diagnostics.
STRATA_VERIFY_DEFER_CPU=checkruns the same steps but adds the rows back right after layer l's own combine: nodeferral, the default's sums in another order.
What changed in the rebase on 0.2.0-beta (two places where 0.2's code meets the deferral):
STRATA_PCIE_BALANCE=1times each layer's wait for the CPU rows in its GPU fit, and a deferred layer does not makethat wait. With both set,
initturns the deferral off with one line, anddefer_okrefuses a window with balancestamps.
STRATA_COLD_OVERLAP=1,2or3) compute a layer's CPU experts in batches, inside the jobloop, when some of their reads are still pending. Such a layer is not split: it waits for all its CPU rows (one
line, said once). With mode 0 or 4 (4 is the Linux default for the GGUF read in place, which reads everything before
the pool runs) nothing changes for the split.
Compatibility: SYCL (
sycl/) has its own copies of every touched source and header exceptverify_kernels.hpp,which only gains declarations, so nothing it compiles changes. On Metal the calls of the new entry points are
compiled out (
#if !defined(STRATA_GPU_METAL)); the Metal window returns frominitbefore the env is read. HIPcompiles the same CUDA sources.
Docs: a DETAILS.md section next to the route tail skip and the PCIe share.
Rebased onto 0.2.4.1 (2026-10-24)
This head is the branch rebased onto
main8183c6b6(v0.2.4.1 and one docs commit, engine 0.1.49.1). The rebase appliedwith no conflicts, and
git range-diffagainst the 0.2.3 head (af16b23a) shows every commit as the same patch.Checked on this head (Linux, the build of the runs below): the build and five CPU tests (
conv_cache_test,spec_prob_test,batch_rows_test,conversation_validation_test,conversation_transfer_test) passed. Not runon this head: the Windows build and ctest.
GPU runs on this head (2026-10-24). The same RTX 2080 Ti and runs as in the 0.2.3 section below (this head's
Linux build against
main's, the same model, slices and prompts). The CI container on the host used 0 cores inevery arm. In the 0.2.3 section below, "this head" means the 0.2.3 head (af16b23a).
main: top-20 logits, 15,175 positions=1against unset: KL mean ± sd / top-1 agreement=checkagainst unset=1withSTRATA_VERIFY_DEFER_CPU_BELOW=1against unset=1(median of 3 rounds)=1(median of 3 prompts)The KL rows are the same as on 0.2.3 because the logits are:
main's top-20 file and the=1file of this head arebyte-identical to 0.2.3's (md5 of each run's file).
The speed rows are four arms in the order unset,
=1,=1, unset, and each cell is the mean of its two arms. At lowcontext the two arms of each agree within 0.3 tok/s (unset 53.29 / 53.55,
=161.13 / 61.37). At ~32K they spreadby about 2 tok/s (unset 46.9 / 44.8,
=148.6 / 46.6), while on 0.2.3 they did not (unset 45.8 / 45.7,=150.8 /51.5). Both
=1arms here are 2.2-4.9 tok/s below both of 0.2.3's, with unset about the same, so the smaller ~32Kgain on this head looks real; its cause is not known, and the ~32K arms were not run again.
Rebased onto 0.2.3 (2026-10-23)
This head is the branch rebased onto
main5c8dd322(v0.2.3, engine 0.1.48), plus two commits for 0.2.3's DFlash2drafter.
The conflict. Git stopped at one conflict, in
record_window's post(l). Upstream's new tap block (the DFlash2drafter's hidden states) and the
=checklate_add sit at the same spot. The late_add goes first, so in=checkatapped layer output holds the layer's own CPU rows, as it does on the default path.
The two new commits. With
=1, a deferred layer's light rows join only in pre(l+1). A tap copies layer l'soutput in post(l), so it would miss those rows, and the drafter (
--draft dflash2) or theSTRATA_TAP_FILEdumpwould read different hidden states. With the taps on, there is now no deferral:
initsays so in one start-up line and clears the flags.defer_oksays no for every window, as it does forSTRATA_PCIE_BALANCE.docs/DETAILS.mdlists the taps among the cases that run without deferral. The drafter is CLI-only and opt-in, sothe default path and the
--servepath are unchanged.Checked on this head (Windows, MSVC 19.44 + CUDA 13.0):
hc_persist_parity)The other 5 fail the same way on v0.2.3 itself in the same environment:
hc_persist_parityandhc_persist_default_off: the test callssetenv, which MSVC does not have.gemm_bf16_parityandgr_upmix_parity: the CUDA DLLs are not on ctest's PATH. With them on the PATH,gemm_bf16_paritypasses andgr_upmix_parityfails 21 cases on both.ple_parity: it needs a model file.GPU runs on this head (2026-10-23). The same RTX 2080 Ti and runs as in Validation (this head's Linux build
against v0.2.3's, the same model, slices and prompts):
main: top-20 logits, 15,175 positions=1against unset: KL mean ± sd / top-1 agreement=checkagainst unset=1withSTRATA_VERIFY_DEFER_CPU_BELOW=1against unset=1(median of 3 rounds)=1The speed rows on this head are a second run: in the first, a build on the same host took 15-22 cores during both
=1arms and none during the unset arms. In the second, the host was idle in all four arms.Not run on this head:
--draft dflash2withSTRATA_VERIFY_DEFER_CPU=1(the refusal is read from the code only).In the older sections below, "this branch" and "this head" mean the 0.2.0-beta head (57cc1beb).
Validation
Revision: this branch, built and tested at
57cc1bebonmaine88ee39d(v0.2.0-beta + 12 commits); the tip58c72607differs from it only in three lines ofdocs/DETAILS.md. Baseline for the tests:e88ee39ditself, builtand run the same way.
Passed:
Linux CUDA build, all targets: Ubuntu 24.04 (a Proxmox container), GCC 13.3, CUDA 13.0.88, sm_75;86, Release,
native experts,
ninja -C build all(368 steps) rc=0, both for this branch and the baseline. The touched sourcesrecompiled with their warnings shown: the three warnings (an unused variable in
raise_flag, a#pragma clangand an unreferenced kernel in
verify_kernels.cu) are all in code this change does not touch.Windows CUDA build: MSVC 2022 (14.44) + CUDA 13.0, sm_86, Release, Ninja,
ninja -k 0 all:strata.exeandevery other target built; one target failed, under Failed.
CPU tests on Linux,
CUDA_VISIBLE_DEVICES=-1 ctest --timeout 300 -j 4(no GPU visible), this branch against thebaseline:
maine88ee39dEvery test has the same outcome in both (compared by name). Among the passing ones
file_expert_source_test,split_lend_complement_testandvmm_testlink the engine library with the changedexpert_source.cppandverify.cpp;conv_cache_test,spec_prob_test,batch_rows_test,conversation_validation_testandconversation_transfer_testare the ones the earlier revision of this PR ran. No test exercises the deferralitself (it needs a GPU).
CPU tests on Windows, the same command on the Windows build (this branch only; the baseline was not built on
Windows): 23 passed, 4 skipped, 56 failed of 83. The 23 are the Linux list's passing tests that Windows registers
(
conversation_transfer_test,pinned_shared_testandsplit_lend_complement_testare Linux only); the failuresare the GPU tests.
GPU, this branch's Linux build against the baseline's, one RTX 2080 Ti 11 GB (PCIe 3.0 x16) + Ryzen 9 5900XT,
Linux; GSQ-RCO IQ3_S (ISTA-DASLab),
--servewith the setup's config, expert cache auto (1,917 slots in every arm),one fresh engine per arm, port and config the same for both builds:
Default path: the baseline and this branch with
STRATA_VERIFY_DEFER_CPUunset, teacher-forced(
STRATA_LOGPOS, top 20,--short-read 100000 --pcie-frac 0), 12 slices of plain text, 15,175 positions:the two dumps are byte-identical, and the branch's log has no
STRATA_VERIFY_DEFERline.Quality, the same 12 slices, against this branch unset; every
=1/=checkrun printed itsSTRATA_VERIFY_DEFER_CPUline and no window timeout or stall line. The two reference rows were run later thesame day on the same card: their unset reference was run again and was byte-identical to the first (every
position's top 20), so all rows share one reference. KL by position in tokens of each slice:
--expert-cache: 2,032 against auto's 1,917; the placement floor)STRATA_ROUTE_TAIL_SKIP=0(scale)=1 BELOW=1(every CPU row)=1, the default 0.1=check, the default 0.1=1sits above the tail skip's scale here (0.098 against 0.064; on v0.1.44.1 and the 3080 they were 0.088against 0.083), and one slice carries much of it (0.637; the floor's worst slice is 0.131).
=check(thedefault's sums in another order, the same placement) stays at a quarter of
=1and below the placement floor.It is above the v0.1.44.1 figure (0.0134), which was 4 slices on another card; this run did not separate the two.
The other sizes, the same 12 slices,
=1(the default 0.1) against each size's own unset run, each with its ownautomatic cache (the same slot count in both arms of a size):
The order follows the earlier table's (v0.1.44.1, below) except Coder, which dropped from 0.149 to 0.089; its
worst slice went from 0.795 to 0.380.
Speed: 12 prompts x 200 tokens, three rounds, the median of the three rounds' mean decode tok/s; then 3 prompts of
~32K tokens read from 0, 200 tokens each, the median. Order: unset,
=1,=1, unset:STRATA_VERIFY_DEFER_CPU=1STRATA_VERIFY_DEFER_CPU=1Low context: +15.4% (the medians of the two arms each, 53.98 against 62.27; unset vs unset 0.35 apart,
=1vs
=10.69). At ~32K: +7.1% (47.25 against 50.60), with a wider spread between the two unset runs (2.1).Failed:
*_parity,cuda_device_selftest) fail with no GPU visible, the same 54 on the baseline. Notcaused by this change; they were run without a GPU on purpose. On Windows the GPU tests fail the same way.
hc_persist_paritydoes not compile (src/kernels/hc_persist_parity.cpp:55,setenv/unsetenvare POSIX). The file is not touched by this change, so its two tests are "Not Run" there.Not run:
the RTX 3080 tables below stay those of v0.1.44.1.
=checkrow and thebyte-identical repeat of unset above take its place on 0.2.0-beta.
fmaf,__expf,float4and plain launches, andcopy_rows_by_weightiscopy_rows_from_mapped_kernelwith one more test.STRATA_VERIFY_DEVICE_PLAN=1with deferral,STRATA_COLD_OVERLAP=1/2/3with the split,STRATA_PCIE_BALANCE=1with deferral (the line and the fallback), two GPUs, AMD.
Earlier measurements (v0.1.44.1, before this rebase)
Measured on the revision this PR had before the tracker reset (base
296b59d2, v0.1.44.1), not on 0.2.0-beta, onanother card (an RTX 3080), so they do not compare number for number with the 2080 Ti runs above.
Speed. GSQ-RCO IQ3_S (ISTA-DASLab), RTX 3080 10 GB alone (PCIe 4.0 x8, 13.0 GB/s) + Ryzen 9 5900XT, DDR4-3000,
Linux;
--servewith the setup's config as it is (expert cache auto: 1,404 slots in every arm, the PCIe shareautomatic), one fresh engine per arm. Low context: 12 prompts x 200 tokens, three rounds, mean decode tok/s per
round, the median of the three. High context: 3 prompts of ~29-30K tokens read from 0, 200 tokens each, the median of
the three.
STRATA_VERIFY_DEFER_CPU=1 STRATA_VERIFY_DEFER_CPU_BELOW=1(every CPU row)STRATA_VERIFY_DEFER_CPU=1(the default 0.1; two runs: 68.42, 67.52)At ~30K the default 0.1 gives back part of the gain; the high-context medians are noisier (the first of the three
prompts was the slowest in every arm). Prompt reads are unchanged (deferral is decode only: 956-963 tok/s at ~30K).
A later run (2026-10-17, the same PC,
--max-context 262144, 1,285 slots): unset 58.7, the default 67.6 (+15.2%).Quality. Teacher-forced log-probabilities (
STRATA_LOGPOS, top 20), read through the verify windows(
--short-read 100000) so every position takes the decode path,--pcie-frac 0; top-20 KL(reference || run) andtop-1 agreement.
STRATA_ROUTE_TAIL_SKIP=0is the scale: how far the shipped default (route tail skip on) is from theengine without it. 12 slices of plain text, 15,175 positions (2026-10-17). The KL varies far more from one slice to
the next than between settings, so the table gives the mean over the 12 slices, its spread, and the median:
=0(unset), v0.1.44.1=0with 9% more expert slots (the placement floor)STRATA_ROUTE_TAIL_SKIP=0(scale)=1 BELOW=1(every CPU row)=1, the default 0.1The default 0.1 against
=0, other sizes (one PC, 12 slices, v0.1.44.1):The late addition's arithmetic (4 slices, 5,257 positions, v0.1.44.1; reference unset, run twice for the floor).
=checkis the same sums in another order:=check, every CPU row=check, the default 0.1STRATA_ROUTE_TAIL_SKIP=0(scale)Default path on v0.1.44.1:
296b59d2and the PR's branch with the env unset, the same 4-slice run, werebyte-identical (5,257 positions, top 20).
Limits
=checkadds the rows back in post(l), so it exercises the copy and the arithmetic of the late addition but notwhere the wait sits in pre(l+1). Nor does any check show that post(l) waits for the heavy rows and not later: a
missing or late partial flag ends in a 20 s window timeout (the GPU waits for it), not in wrong rows; a flag raised
too early would read rows the pool is still writing. The flag is raised only after the heavy jobs' pool call
returned, with the same fences as the layer's own flag. Both rest on reading the code.
--pipeline-windows,--peer-device, helper caches): checked by reading the codeonly, not run. Each stage is its own verifier with its own flags, plan and late rows, and defers its own layers but
its last, so nothing is deferred across the hand-off between cards.
STRATA_VERIFY_DEVICE_PLAN=1, the PLE block and a stage starting at layer 0,pre(1) copies the PLE rows without waiting for flag 1 when post(0) skipped its wait through the device plan. This
change never defers layer 0 under PLE, so it does not touch that path.
How to try it
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.