Repository navigation
[FlyDSL] [AMD][DSV4] fix: drop expert -1 pad routes in the fused TP route/psumkernel - #7365
Conversation
… kernel moe_route_psum_fused is the single-workgroup route + psum + remap kernel that pure-TP grouped MoE takes for small batches (token_num * topk <= 2048, E <= 512). It indexes its per-expert LDS counter with the raw expert id, so a route to expert -1 -- a pad row the router left unrouted -- bumps a slot outside the counter and leaves a wild row in topids_to_rows. Phase D then decodes that row into an expert index and reads starts[] out of bounds. The split-kernel route already has a contract for exactly this case: such routes get DROPPED_ROUTE_ROW, claim no slot, and every consumer (psum remap, the stage-1 route-indexed quant scatter, gather-reduce) skips them. The fused kernel never implemented it. This change makes it do so: Phase B writes DROPPED_ROUTE_ROW first and only routes with 0 <= e < E take a slot; Phase D leaves negative rows untouched. Valid-id behaviour is unchanged -- counts, psum, starts and row placement are bit-identical when no route is -1. Found on DeepSeek-V4.1-Flash, pure TP4 with DSpark speculative decoding and FULL CUDA graphs on gfx1250 (4x MI455X). Two faults, one cause: a memory fault in moe_route_psum_fused while capturing the DSpark draft graph (draft MoE, E=128, topk=3), and, once past that, a fault in the stage-1 moe_fused_quant_preshuffle_routeks kernel about 20 s into serving (main MoE, E=384, topk=6), which scatters to whatever row the route handed it. A standalone fused_route_psum_remap call with -1 entries reproduces the route fault directly. With the fix, the same configuration boots, captures every draft graph and completes the MLPerf agentic c8 run (600 s issue window): 420.0 tok/s/GPU, interactivity 365.7, TTFT p50 49.6 ms, TPOT p50 2.30 ms, 1105/1105 requests, zero faults. The kernel change is one compare and one store per route in a single-workgroup launch. Adds op_tests/flydsl_tests/test_route_psum_fused.py. Nothing exercised this kernel directly, and it fails badly rather than loudly: an unguarded pad route corrupts LDS and only faults when the wild row happens to land off a mapped page. The test feeds 0%, 50% and 100% pad routes at the main-model (E=384, topk=6) and draft (E=128, topk=3) shapes across the decode token range, and checks that pad routes carry DROPPED_ROUTE_ROW and that counts, psum and row placement stay exact. Co-authored-by: Cursor <[email protected]>
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
valarLip
left a comment
There was a problem hiding this comment.
LGTM. Phase B now gives -1 / out-of-range expert ids DROPPED_ROUTE_ROW without touching the LDS counter, and Phase D skips negative rows, which matches the split route + contiguous_psum_remap contract. Valid ids are unaffected and the extra cost on the hot path is negligible.
Non-blocking:
- Nit: an if/else (as in
moe_route_maps.route_kernel) would avoid the extra global store per valid route. - Follow-up: the split route (
moe_route_maps.py) only checkse >= 0, so ids>= Ecan still go out of bounds there. - Test: consider adding mixed in-row -1 / id
>= Ecases and a bitwise compare against the split path. The new test is gfx1250-only, so CI currently skips it.
A valid route was written as DROPPED_ROUTE_ROW and then overwritten. The else branch matches the split route kernel and skips that extra store. The test now mixes expert -1 with ids at or past E in the same row.
|
Addressed the non-blocking notes in 30f0c09.
|
- Restores the import of DROPPED_ROUTE_ROW from moe_route_maps, which the route remap uses for routes with no grouped row. #7494 dropped the import on a branch where only comments still named the constant; #7365, merged in between, had added a use in code, so the merged file raised NameError and test_flydsl_moe_aux.py failed on main.
- Restores the import of DROPPED_ROUTE_ROW from moe_route_maps, which the route remap uses for routes with no grouped row. #7494 dropped the import on a branch where only comments still named the constant; #7365, merged in between, had added a use in code, so the merged file raised NameError and test_flydsl_moe_aux.py failed on main.
Summary
Make the fused TP route kernel
moe_route_psum_fuseddrop routes to expert-1(pad rows), the same way the split-kernel route already does. Without this, pad routes corrupt the per-expert counter and produce out-of-range rows, which fault the GPU in the route kernel or in the stage-1 quant scatter that consumes its output.Motivation
For small pure-TP batches (
token_num * topk <= 2048,E <= 512), grouped MoE usesfused_route_psum_remap, a single-workgroup kernel that does route, psum and remap in one launch. It uses the raw expert id as an index into its LDS counter. When the router leaves a pad row unrouted, its expert id is-1, so the kernel:topids_to_rows, which Phase D then decodes into an expert index and uses to readstarts[]out of bounds.The split-kernel route (
moe_route_maps.py) already handles this. Such routes getDROPPED_ROUTE_ROW, take no slot, and every consumer skips them: psum remap, the stage-1 route-indexed quant scatter, and gather-reduce. The fused kernel never implemented that contract.We hit this on DeepSeek-V4.1-Flash with pure TP4, DSpark speculative decoding and FULL CUDA graphs on gfx1250 (4x MI455X). It showed up as two different faults from the same cause:
moe_route_psum_fusedmemory fault while capturing the DSpark draft graph (draft MoE, E=128, topk=3).moe_fused_quant_preshuffle_routeks_*memory fault about 20 s into serving (main MoE, E=384, topk=6). This kernel scatters to whatever row the route gives it.A standalone
fused_route_psum_remapcall with-1entries intopk_idsreproduces the route-kernel fault.Changes
aiter/ops/flydsl/kernels/moe_contiguous_psum.py(route_psum_fused_kernel):DROPPED_ROUTE_ROWfor every route first. Only routes with0 <= e < Etake an LDS slot and get a real row.op_tests/flydsl_tests/test_route_psum_fused.py: new test for this kernel.Behaviour for valid expert ids is unchanged: counts,
psum,startsand row placement are identical when no route is-1. The extra cost is one compare and one store per route in a single-workgroup launch.Test / Validation
Unit test (gfx1250):
pytest op_tests/flydsl_tests/test_route_psum_fused.pygives 30 passed.-1.DROPPED_ROUTE_ROW;masked_mequals the per-expert counts of valid routes;psumequals the tile-aligned starts plus counts; every valid row lies inside its expert's span, is unique, and is belowcontiguous_m.No existing test called this kernel directly. The bug is easy to miss: a pad route corrupts LDS silently and only faults when the bad row lands on an unmapped page.
Additional sweep: every
token_numfrom 1 to 341 at both shapes, valid ids only, gives the same invariants as the split path.End to end: applied on the 2026-11-02 nightly image with DeepSeek-V4.1-Flash, TP4, DSpark, FULL CUDA graphs, MLPerf agentic c8 and a 600 s issue window.
Not verified: MI250X and MI300X, since this kernel is gfx1250-only. EP paths don't use this kernel.
ruffandblackare clean on both files.PR Self-Review
Reviewed revision
30f0c09
Behavior and intent
moe_route_psum_fuseddrops routes whose expert id is outside[0, E). Those routes getDROPPED_ROUTE_ROW, take no LDS slot, and Phase D leaves them alone. Before this, a pad id of-1indexed the per-expert counter out of range and wrote a wild row, which faulted the route kernel during DSpark graph capture and the stage-1 quant scatter during serving. Valid ids are unchanged. A valid route is stored once; the dropped sentinel is the else branch, matchingmoe_route_maps.route_kernel.Validation and unverified scope
pytest op_tests/flydsl_tests/test_route_psum_fused.pyon gfx1250: the original 30 cases (E=384/topk=6 and E=128/topk=3, token counts 1/5/26/64/341, pad fractions 0/0.5/1) plus mixed in-row cases of expert-1and ids>= E. End to end on 4x MI455X, DeepSeek-V4.1-Flash, pure TP4, DSpark, FULL CUDA graphs, MLPerf agentic c8, 600 s: capture completes and 1105/1105 requests finish, 420.0 tok/s/GPU. Not verified: MI250X and MI300X (this kernel is gfx1250-only) and EP, which does not use it. The split route inmoe_route_maps.pystill only checkse >= 0; ids>= Ethere are a separate follow-up.PR-specific question
What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test? Before this PR a pad route of expert
-1, or an id>= E, corrupts the LDS counter and can write a row past the buffer. No existing test calledmoe_route_psum_fuseddirectly, so that failure was only visible as a GPU fault when the wild row left a mapped page.Changed op tests
op_tests/flydsl_tests/test_route_psum_fused.pyfeeds the fused kernel pad rows and, in one row, a mix of a valid id, expert-1, and an id>= E. It checksDROPPED_ROUTE_ROW, per-expert counts,psum, and that kept rows stay inside their span and are unique. Nothing else launches this kernel, so the coverage is not redundant.