mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1737] [CLOSED] route-resident: one warp per token in the swap kernel #3640
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#3640
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/1737
Author: @aly8246
Created: 10/9/2026
Status: ❌ Closed
Base:
main← Head:route-resident-parallel-scan📝 Commits (2)
fc54d84route-resident: one warp per token in the swap kernel488eecbroute-resident parity: the swap against a scalar reference📊 Changes
3 files changed (+309 additions, -22 deletions)
View changed files
📝
CMakeLists.txt(+8 -0)📝
src/kernels/cuda/native_router.cu(+46 -22)➕
src/kernels/route_resident_parity.cu(+255 -0)📄 Description
route-resident: one warp per token in the swap kernel
STRATA_ROUTE_RESIDENT swaps a routed expert for one that is already resident, and the swap kernel is
the only work it adds to a window. That kernel was written one thread per token: a verify window is 1
to 8 rows, so a block had up to 8 threads doing it, each scanning 512 experts per rank with a ten-way
"already picked" check inside - call it 4 x 512 x 12 scalar operations, on the critical stream, once
per layer. It cost about as much as the waiting it removed, which is why the option measured as a wash.
This commit makes it one warp per token. Lane j reads experts j, j+32, ..., the warp reduces to the
best logit in a shuffle tree, and the ranks are still visited in order, because a swap changes the set
that is already picked. The answer is the same bits: a strictly greater logit wins, the smallest expert
index breaks ties, the already-picked test runs against the ids as they are at that rank, and the
softmax is the same expression.
What it buys on our machine, with the option at margin 0.25:
The rest of this is how those numbers were taken and where the limits of them are.
Three legs in one session (STRATA_VERIFY_PROFILE), same prompts, same 8083-slot cache, medians of the
per-window stage table:
The option takes about 4.3 ms of PCIe waiting out of a window; the serial swap handed 2.75 ms of that
back, the warp swap hands back 0.33 ms.
Twelve matched pairs of engine restarts, nine decode samples a leg, three greedy 150-token prompts, the
learned profile copied back before every leg so both arms start from the same cache. Six pairs ran the
unpatched build first and six the patched one:
All twelve pairs
The gain follows how many tail experts the option actually redirects, so a smaller cache gains more.
Four pairs with a 4000-slot cache instead of the automatic 8083 (pcie_e 1.83 against 1.78, about three
times the traffic), two pairs each way: decode +8.8% median, ms/window -7.8% median, 4 of 4.
Where it also shows up: three real agent sessions on this machine - many tool calls, 27, 49 and 102
requests - whose engine configurations differ only in --max-context. A longer context costs VRAM before
--expert-cache auto sizes the cache (the RoPE tables alone are 0.26 KB per token), so the three ran
with three different caches:
output/wall is the plugin's own tok/s (output divided by duration, so it carries the prefill) - these
sessions reuse their parked conversations heavily, so read it as "did anything move", not as a decode
rate. 8% fewer experts and about 10% more traffic across PCIe, and nothing moved: the medians sit
inside 1.3%. The same knob on the unpatched build, with the option off, is worth -9.5% of the window
for +224 slots (reserve 700 -> 250 MiB), so the sensitivity was there to lose.
Those are three single runs of a real workload, not matched pairs, and no further testing was done. The
speed improvement above is what this PR claims; the 1M figures are what one session did on this
machine.
The option's price is the margin's, not the kernel's, and this commit does not touch it. Teacher-forced
log-probabilities over 7677 positions of one 7.6k-token text (technical prose, source code and
Chinese), top-64, against the same text with the option off:
Two runs with the option off are bit-identical, so that spread is the option and not the machine. 0.25
keeps nearly all of the waitB saving for a fraction of the distortion; the default 1.0 is not worth
its price.
Parity: 400 random cases - half built with many equal logits, random lo/hi, margins from -0.5 to 1.5, 1
to 8 tokens, about 60% of the experts resident, routed ids with repeats - compared bit for bit on the
ids, the weights and the four counters, both kernels side by side. 0 mismatches.
Tests: src/kernels/route_resident_parity.cu, registered in ctest next to the other router parity tests
(TIMEOUT 120). Same case generator, against a scalar reference of the semantics - a serial walk with
the same comparisons, not a copy of the kernel this branch replaced - so it tests the code in the tree.
ids and the four counters must match bit for bit; the weights are a softmax ratio and the reference is
a second compilation of it, so they are held to 8 ulp (worst seen: 6). A case that swaps nothing has
to leave the weights untouched, which the sentinel they start from checks, and the test fails if no
case swapped at all.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.