mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1357] mtp: the per-token drafter router call is missing the n_expert == 512 guard its three sibling call sites carry #550
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#550
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 @rwkeyes on GitHub (Oct 7, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1357
While porting this engine I hit a guard asymmetry in the MTP drafter's router call and wanted to flag it. Found by reading, not by reproducing a crash.
The callee's documented requirement
include/strata/kernels/native_router.hpp:10-16states the contract explicitly:So
native_router_top10requires a 512-wide logits row, and the CUDA implementation hardcodes that:src/kernels/cuda/native_router.cu:49doeslogits += (size_t) blockIdx.x * 512;, and:163validates the spans as512 * 4bytes.The guard asymmetry
Three of the four call sites test the expert count first. One does not:
src/core/layer.cpp:372native_router_enabled() && g.n_expert == 512 && k == 10src/core/verify.cpp:1110dec_batch && n > 1 && w_router != nullptr && native_router_enabled() && NE == 512 && K == 10src/core/mtp.cpp:877T > 1 && native_router_enabled() && g.n_expert == 512 && K == 10src/core/mtp.cpp:883if (native_router_enabled())— nothing elseThe
elseat:883is reached precisely when the:877test fails — that is, when the model does not have 512 experts — and it then passes a row of widthg.n_expertto a callee that reads 512 floats from it. The correct guard sits eight lines above, which makes this look like an oversight rather than intent.What it does
For
g.n_expert < 512the call reads past the end of each row: for every token but the last, into the next token's logits; for the last row, past the allocation. Wherever that memory is mapped, the values are another token's logits, so the router's selection and weights are silently wrong for the drafter. That makes this a correctness defect, not only a bounds one. A 256-expert model — which the drafter otherwise supports, sincemtp.cpp:296sizes its expert store fromg.n_expert— over-reads 256 floats (1 KB) per row.The SYCL tree has it identically
sycl/src/core/mtp.cpp:679:No
n_expert == 512guard there either.Scope, stated honestly
This is latent, and I want to be precise about that: the header itself says the path is an experiment that is off by default (and it does not modify the legacy router), and I could not find any caller of
native_router_set_enabledoutside the router's own translation units. So a stock session will not reach it. Reaching it takesnative_router_enabled()true, a model whosen_expert != 512, and the MTP drafter enabled (--mtp-*). I could not run that configuration — I found this by reading the source and checking the callee's contract, not by hitting a failure.Suggested fix
Mirror the
:877condition on theelse, and use the geometry-aware entry, which is documented as handling exactly this and as producing identical results where both apply (include/strata/kernels/router_top10.hpp:17,20-21—router_top10(logits, n_tokens, n_expert, k, ids, weights, stream), with the ARM fast path being "the default there for 64 < n_expert <= 512, k <= 32; bitwise the same results"):Relatedly,
src/kernels/native_multi_parity.cppcurrently exercisesnative_router_top10_multiagainst the single-token call forn = 1..19; a non-512 case there would have caught this, since the single-token call is the one that over-reads.Happy to send a patch if that would help. Context for how I hit it: I maintain a Vulkan port of these kernels for Intel Arc hardware, and needed the geometry-aware router entry to implement this path correctly.
@Niko1221 commented on GitHub (Oct 7, 2026):
Confirmed by reading, and your reading of the table is right: the window path and the other two call sites test
n_expert == 512 && K == 10, the per-token fallback in the MTP drafter tested onlynative_router_enabled(), so a non-512 model read 512 floats from a row ofn_expert. Fixed in 0.1.40.3 with the same condition; anything else takes the genericrouter_top10, as you suggested. The SYCL copy atsycl/src/core/mtp.cpphas the same guard now.We also added your non-512 check to
native_multi_parity:router_top10on 256-wide rows must match a host reference (ids in order, renormalised softmax weights). That is the fallback's contract; the drafter call itself needs a 256-expert model to reach, which we do not have. Thank you for the report and the pointer to the header's contract.The commit carries
Reported-by: rwkeyes.