[GH-ISSUE #5287] [Engine] Let STRATA_ROUTE_PRIOR and STRATA_ROUTE_RESIDENT run on models with fewer than 512 experts #3154

Open
opened 2026-11-07 14:38:30 +07:00 by bsakaguchi · 1 comment
Owner

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

  • Pass the expert count NE to the two bias kernels and widen the call condition to "NE is a multiple of 32 between 64 and 512, and K == 10".
  • When a bias is requested on an expert count outside that range, log "residency-biased routing is off for this model (n_expert=N)".
  • Leave the NE == 512 condition of the native router itself unchanged (following the discussion in PR #238).
  • Change no defaults (the prior stays off unless the user sets it, as since 0.2.8).
  • Keep STRATA_ROUTE_RESIDENT_MTP limited to 512-expert models and log "off for this model" otherwise. The MTP head is loaded with the canonical 512-expert geometry (draft_geometry), while the residency row passed to it comes from the main model's last layer. On a model with fewer experts that row has only n_expert entries, so the 512-wide kernel reads past it and compares expert IDs that do not match.
    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:

  • The 512-only condition of the native router stays. The Coder's single-token path keeps using the generic router.
  • The biases are off by default. With them off, the Coder and pruned models run exactly the same code as before, so their output does not change. With a bias on, the selection changes, which is how the biases are already described at 512 (opt-in, changes the output).
  • At 512, the instructions are the same as before even with a bias on (below).

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.

Model Build Hit rate Decode (tok/s)
Qwen3.8-Flash-Next IQ3_S (512) unchanged = changed 68% 22.0 / 22.6
GGUF pruned to 384 experts unchanged 42.6% / 42.1% 26.5 / 26.8
GGUF pruned to 384 experts changed 68.3% / 68.0% 37.3 / 37.0
GSQ-RCO Coder (256) unchanged 38.4% / 42.3% 37.1 / 40.8
GSQ-RCO Coder (256) changed 71.8% / 70.3% 46.4 / 44.5

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.

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 - Pass the expert count NE to the two bias kernels and widen the call condition to "NE is a multiple of 32 between 64 and 512, and K == 10". - When a bias is requested on an expert count outside that range, log "residency-biased routing is off for this model (n_expert=N)". - Leave the `NE == 512` condition of the native router itself unchanged (following the discussion in PR #238). - Change no defaults (the prior stays off unless the user sets it, as since 0.2.8). - Keep STRATA_ROUTE_RESIDENT_MTP limited to 512-expert models and log "off for this model" otherwise. The MTP head is loaded with the canonical 512-expert geometry (draft_geometry), while the residency row passed to it comes from the main model's last layer. On a model with fewer experts that row has only n_expert entries, so the 512-wide kernel reads past it and compares expert IDs that do not match. 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: - The 512-only condition of the native router stays. The Coder's single-token path keeps using the generic router. - The biases are off by default. With them off, the Coder and pruned models run exactly the same code as before, so their output does not change. With a bias on, the selection changes, which is how the biases are already described at 512 (opt-in, changes the output). - At 512, the instructions are the same as before even with a bias on (below). #### 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. | Model | Build | Hit rate | Decode (tok/s) | |---|---|---|---| | Qwen3.8-Flash-Next IQ3_S (512) | unchanged = changed | 68% | 22.0 / 22.6 | | GGUF pruned to 384 experts | unchanged | 42.6% / 42.1% | 26.5 / 26.8 | | GGUF pruned to 384 experts | changed | 68.3% / 68.0% | 37.3 / 37.0 | | GSQ-RCO Coder (256) | unchanged | 38.4% / 42.3% | 37.1 / 40.8 | | GSQ-RCO Coder (256) | changed | 71.8% / 70.3% | 46.4 / 44.5 | #### 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.
Author
Owner

@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).

<!-- gh-comment-id:6655626635 --> @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).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3154
No description provided.