mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2689] [CLOSED] verify: STRATA_VERIFY_DEFER_CPU=1, a layer's CPU expert rows join at the next layer's FFN half (opt-in) #4213
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#4213
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/2689
Author: @lask3802
Created: 10/15/2026
Status: ❌ Closed
Base:
main← Head:verify-defer📝 Commits (3)
dfcfb97verify: STRATA_VERIFY_DEFER=1, a layer's CPU expert rows join the residual before the next layer's FFN-side readbfd3e13verify: STRATA_VERIFY_DEFER, review: the zeroed rows by a kernel, the hits in the combine, a profile slot, docs14d557everify: STRATA_VERIFY_DEFER is now STRATA_VERIFY_DEFER_CPU📊 Changes
5 files changed (+187 additions, -5 deletions)
View changed files
📝
docs/DETAILS.md(+23 -0)📝
include/strata/core/verify.hpp(+8 -0)📝
include/strata/kernels/verify_kernels.hpp(+9 -0)📝
src/core/verify.cpp(+101 -5)📝
src/kernels/cuda/verify_kernels.cu(+46 -0)📄 Description
What it changes
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. With
STRATA_VERIFY_DEFER_CPU=1:rows are zeroed by a small kernel (
fill_zero, not a memset node, so the window graph stays kernel-to-kernel).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.So the CPU computes layer l while the GPU runs layer l+1's mixer. That mixer is the only part that runs without layer
l's CPU rows; its router, experts and everything after see them. This changes the output (see Quality).
Not deferred: the stage's last layer, and layer 0 when layer 1 runs the PLE block (pre(1) copies the PLE rows, which
the host writes just before flag 1, and relies on post(0)'s wait). Windows that run without deferral (one line at the
first capture says which and why): batch windows,
--spec-splittoken groups,--remote-expert-opt, theall-resident graph (no CPU rows), a stage with no layer to defer, a control vector on the stage.
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.
The profile (
STRATA_VERIFY_PROFILE) and the #649 trace get one more stamp (slot 15) at the end of the mixer'sout-projection: "out-proj" now ends there and the next interval is "late rows" (the late wait and add). Without
deferral "late rows" is the cost of one stamp; the stamp is a graph node only when the profile or the trace is on.
Docs: a DETAILS.md section next to the route tail skip and the PCIe share.
Where it came from: we run a two-machine setup on top of the remote stage (#1748), where the main machine's GPU waits
for its CPU pool in every layer and was the bottleneck. Deferring the CPU rows by one mixer helped there, and the same
wait exists on a single PC with one GPU, which is what this PR is about and what the numbers below are from.
What it leaves alone
0): no allocation, no graph node, no kernel choice and no host step changes. The env is read once inVerifier::init; the extra device buffer (T * k * n_embdfloats) is carved after every other buffer, only when on.run,service) is unchanged. Nothing the late addition reads is overwritten before it: pre(l+1)'sattention-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 the host's next expert step never rewrites the doorbell payload or
h_ymiss_earlier than without deferral, and no buffer is doubled.sycl/) and Metal (metal/) are not touched. SYCL builds its own, hand-mergedsycl/src/core/verify.cpp;the shared
verify_kernels.hpponly gains two declarations. Bringing the deferral to SYCL would mean merginglate_addinto that file and portingdefer_add_rowsandfill_zerotoverify_kernels.dp.cpp. On Metal thetwo calls of the new entry points are compiled out (
#if !defined(STRATA_GPU_METAL)), so no link stub is needed;the Metal window returns from
initbefore the env is read.Measured
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 share automatic), onefresh engine per arm, order unset,
=1, two arms of the follow-up PR, unset again. Low context: 12prompts 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. The arms ran on an earlier build of the
follow-up PR #2690 (this branch + its row split, which that build left off unless asked: its
=1matches this branch'swithin two runs of one binary, below).
STRATA_VERIFY_DEFER_CPU=1The prompt read does not change (deferral is decode only): 956-962 tok/s at ~30K in both arms. The high-context
numbers are noisier: the first of the three prompts was the slowest in every arm (44.8-56.3), so take +17% as +15-20%.
Quality
The output changes. Teacher-forced log-probabilities (
STRATA_LOGPOS, top 20) on the same machine and model, 4 slicesof plain text, 5,257 positions, read through the verify windows (
--short-read 100000) so every position takes thedecode path,
--pcie-frac 0; mean top-20 KL(unset || run) and top-1 agreement with unset, by position in the prompt.The row
STRATA_ROUTE_TAIL_SKIP=0is the scale: it is how far the shipped default (route tail skip on, since 0.1.42)is from the engine without it, on the same text.
=checkSTRATA_ROUTE_TAIL_SKIP=0(scale)=1=checkis the same sums in another order: above the floor, as rounding differences grow along the prompt, and aquarter of the scale.
=1is the cost of the feature: about 8 times the scale over the whole text, most of it late inthe long prompts (640+). That is why it is opt-in, and why the follow-up keeps the heavy rows on time.
For scale, DETAILS.md's own numbers (a different protocol: greedy answers):
#2690 (
STRATA_VERIFY_DEFER_CPU_BELOW, stacked on this one) keeps the heavy CPU rows on time and cuts most of this deviation for asmall part of the speed.
Two GPUs in one PC
Checked by reading the code and building it; not run, as we have no PC with two GPUs.
--layer-split,--split-device), serial windowsVerifierwith its own layer range, flags, plan, rows anddef_parts_(generate.cppstage_ver,set_stage, per-stageinitunder its device); a stage defers its own layers but its last, so the hand-off between cards always follows a combine that waited for its rows; stage 0'srunsyncs its stream beforenext_->run; the pool routes each layer to its stage's plan (drive_pool_split)--pipeline-windowsserviceserves one layer at a time on the host thread and the pool call for a layer is synchronous, as inrun--layer-split K --split-device 0(both stages on one card)ver_same); upstream refuses it with--pipeline-windows--peer-device--peer-devicewith a layer split--expert-cache-device1..3(helper caches)--remote-expert-optdefer_ok(its rows come back reduced throughremote_opt_->copy_rows); one line says soNot verified: anything on real hardware with two GPUs (timing, a second card's driver), AMD multi-GPU.
How it was checked
296b59d2and this branch, both built here, env unset, the teacher-forced run above=checkwithin rounding of the defaultSTRATA_VERIFY_DEFER_CPU=checkvs unset, the same runSTRATA_VERIFY_DEFERtoSTRATA_VERIFY_DEFER_CPU) changes no step=1, the same run=1runs and its lines appearstrata verify: STRATA_VERIFY_DEFER_CPU=1 (changes the output) ...,capturing the N-token window (...), deferredconv_cache_test spec_prob_test batch_rows_test conversation_validation_test conversation_transfer_test,CUDA_VISIBLE_DEVICES=-1What
=checkdoes not check: it adds the rows back in post(l), so it exercises the copy and the arithmetic of the lateaddition but not where the wait sits in pre(l+1). Moving the late addition after the FFN-side read, or dropping its
wait, would still pass
=check. That part rests on reading the code: a missing wait shows only when the CPU is slowenough for the GPU to reach it first, and I have no test that forces it.
Not built: HIP (no ROCm toolchain here; the new kernels use only
fmaf,__expf,float4and plain launches, asother kernels in this file that already build on HIP), SYCL (none of its sources change), Metal (no Mac).
Not tested:
STRATA_VERIFY_DEVICE_PLAN=1together with deferral, two GPUs (above), AMD.How to try it
Set it in the engine's environment (for
serve/server.py, in the environment the server starts the engine with). Thestart-up log says
STRATA_VERIFY_DEFER_CPU=1 (changes the output)and, at the first capture of each window size,capturing the N-token window (...), deferredor why not.Pre-existing, not changed here: with
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
(
if (ar_on()) wait_flag_ge(m_flag_, 1, cs)in pre). This change never defers layer 0 under PLE, so it does nottouch that path. A separate issue/PR is the right place for it.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.