mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5287] [Engine] Let STRATA_ROUTE_PRIOR and STRATA_ROUTE_RESIDENT run on models with fewer than 512 experts #3154
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#3154
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 @kaban-baku on GitHub (Nov 5, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5287
Area
[Engine] (speed, kernels, models, the server and API)
What do you want to do?
I would like the two routing biases (STRATA_ROUTE_PRIOR and STRATA_ROUTE_RESIDENT) to work on MoE models with fewer than 512 experts, such as the official GSQ-RCO Coder (256 experts) and GGUFs with pruned experts.
Today, src/core/verify.cpp (lines 2231 and 2233 in v0.2.10) only calls either bias when
NE == 512 && K == 10, and the kernels (route_prior.cu, and route_resident_k in native_router.cu) are written for 512 experts per warp. On a model with fewer experts, setting STRATA_ROUTE_PRIOR does nothing, and the log does not say so. The description of PR #1668 also notes that it stays off on the Coder.On small cards the expert cache hit rate decides the decode speed, so this would help 8 GB users who run pruned models or the Coder.
Proposed behavior
NE == 512condition of the native router itself unchanged (following the discussion in PR #238).Confirmed with compute-sanitizer memcheck on the unchanged v0.2.10 build. On the 384-expert model with STRATA_ROUTE_RESIDENT=1 and STRATA_ROUTE_RESIDENT_MTP=1, the engine logs "the MTP draft's router is biased toward layer 47's resident experts", and memcheck reports one "Invalid global read of size 4 bytes" in route_resident_k, launched from MtpDrafter::draft (mtp.cpp:1816). memcheck reports the address as "437 bytes after the nearest allocation" of 73,728 bytes; 73,728 bytes is 48 layers x 384 experts x 4 bytes, the size of the residency table for this model. After that the CUDA context failed (cudaErrorUnknown) and the request returned an error. memcheck stops at the first error, so this is one report, not a count. I have not yet checked what happens without the sanitizer and will add that in a comment. With the fix, the same settings log "off for this model (n_expert=384)" and generate normally.
How this relates to earlier discussions
PR #54 added the pruned Coder with "the model file as the authority on its expert count". PR #238, which widened the native router itself, was closed because it "moves the Coder's single-token path to the native router, which can change its output", with the request to "keep the 512-only guard (or show the Coder byte-identical)". This proposal is meant to stay within that condition:
Output at 512 stays the same
At 512 the template argument is 16 and the code is the same expression as before. I built the unchanged and the changed source with CUDA 12.4 for sm_86 and compared them with
cuobjdump -sass: the instruction streams of route_prior_k (1,848 instructions) and route_resident_k (696 instructions) are identical. With the prior on, generated text already differs from run to run on the unchanged build (the bias depends on what is in VRAM, which depends on timing), so I rely on the identical instructions rather than on comparing text.I added route_bias_ne_parity, which checks NE = 256, 384 and 512 against a CPU reference (IDs exact, weights within 2e-5). The existing route_resident_parity also passes (240 cases, 0 mismatches).
I tested this with CUDA only. The same kernel files are also compiled for HIP, which I could not build here; the PR would say so and stay a draft until that is checked.
Numbers
RTX 3070 Ti Laptop 8 GB, 64 GB RAM (
--resident-budget-gib 24), Windows 11, v0.2.10 built locally (CUDA 12.4), context 131072,--kv-resident 20480, MTP, STRATA_ROUTE_PRIOR=1.5. Two short prompts, 1,200 output tokens each, mean of 4 requests, measured twice.Next
If you agree with this scope, I will open a PR with numbers compared against the unchanged build. The change is about 60 lines, not counting the test.
What do you do today instead?
Stay on the 512-expert model. There is no way to use the biases with a pruned model.
@kaban-baku commented on GitHub (Nov 5, 2026):
Follow-up on the STRATA_ROUTE_RESIDENT_MTP point. I ran the same unchanged v0.2.10 build without the sanitizer (384-expert model, STRATA_ROUTE_RESIDENT=1, STRATA_ROUTE_RESIDENT_MTP=1, two prompts with 152 and 811 output tokens). It did not crash, and the text looked normal. So in a normal run the out-of-bounds read goes unnoticed: the MTP draft is presumably biased by whatever lies past the 384-wide table. I could not see a clear effect on draft acceptance from one run each (on the long prompt, 228 of 370 drafts were accepted with the setting and 389 of 499 without it, but the generated text differed between the runs, so I would not read much into that).