Repository navigation
[FlyDSL][MoE] Fix gfx1250 HERD decode routing and extend it past 512 experts - #7130
Conversation
The small-batch TP route (_fused_tp_route) reads topk from the route tensor, so a HERD step's K+1 candidates went through it undropped while the quant kernel still used K as the source topk. That mismaps tokens and keeps all K+1 weights. Every HERD decode window on DSV4-Flash and GPT-OSS (M*K <= 2048, E <= 512) took this path. Route HERD steps through herd_route_psum_remap instead.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
fused_moe(herd_topk=K) dropped the K+1 candidates inside the grouped MoE route kernel unless AITER_HERD_FUSED_DROP=0. That kernel runs in one workgroup with one LDS slot per expert, so E > 512 (Kimi-K3, E=896) raised in herd_route_psum_remap. Drop in the grouped MoE route when E fits that kernel, and finalize the candidates in fused_moe first otherwise. Both produce the same routes, so the AITER_HERD_FUSED_DROP switch goes away. gfx950 is unchanged. The HERD tests that toggled the switch now run E=128 and E=896.
…ave32 herd_topk_candidates' FlyDSL sigmoid selector ballots over a 64-lane wave and raises on wave32, so test_candidate_scoring[sigmoid] failed on gfx1250, where the FFM CI shard runs test_flydsl_herd.py. Wave32 GPUs now select sigmoid candidates with topk_gating_fwd, the kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.
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 |
…experts (#7130) * [FlyDSL][MoE] Keep HERD routes off the fused TP route The small-batch TP route (_fused_tp_route) reads topk from the route tensor, so a HERD step's K+1 candidates went through it undropped while the quant kernel still used K as the source topk. That mismaps tokens and keeps all K+1 weights. Every HERD decode window on DSV4-Flash and GPT-OSS (M*K <= 2048, E <= 512) took this path. Route HERD steps through herd_route_psum_remap instead. * [FlyDSL][MoE] Pick the gfx1250 HERD drop by expert count fused_moe(herd_topk=K) dropped the K+1 candidates inside the grouped MoE route kernel unless AITER_HERD_FUSED_DROP=0. That kernel runs in one workgroup with one LDS slot per expert, so E > 512 (Kimi-K3, E=896) raised in herd_route_psum_remap. Drop in the grouped MoE route when E fits that kernel, and finalize the candidates in fused_moe first otherwise. Both produce the same routes, so the AITER_HERD_FUSED_DROP switch goes away. gfx950 is unchanged. The HERD tests that toggled the switch now run E=128 and E=896. * [FlyDSL][MoE] Select sigmoid HERD candidates with the HIP gating on wave32 herd_topk_candidates' FlyDSL sigmoid selector ballots over a 64-lane wave and raises on wave32, so test_candidate_scoring[sigmoid] failed on gfx1250, where the FFM CI shard runs test_flydsl_herd.py. Wave32 GPUs now select sigmoid candidates with topk_gating_fwd, the kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.
…experts (ROCm#7130) * [FlyDSL][MoE] Keep HERD routes off the fused TP route The small-batch TP route (_fused_tp_route) reads topk from the route tensor, so a HERD step's K+1 candidates went through it undropped while the quant kernel still used K as the source topk. That mismaps tokens and keeps all K+1 weights. Every HERD decode window on DSV4-Flash and GPT-OSS (M*K <= 2048, E <= 512) took this path. Route HERD steps through herd_route_psum_remap instead. * [FlyDSL][MoE] Pick the gfx1250 HERD drop by expert count fused_moe(herd_topk=K) dropped the K+1 candidates inside the grouped MoE route kernel unless AITER_HERD_FUSED_DROP=0. That kernel runs in one workgroup with one LDS slot per expert, so E > 512 (Kimi-K3, E=896) raised in herd_route_psum_remap. Drop in the grouped MoE route when E fits that kernel, and finalize the candidates in fused_moe first otherwise. Both produce the same routes, so the AITER_HERD_FUSED_DROP switch goes away. gfx950 is unchanged. The HERD tests that toggled the switch now run E=128 and E=896. * [FlyDSL][MoE] Select sigmoid HERD candidates with the HIP gating on wave32 herd_topk_candidates' FlyDSL sigmoid selector ballots over a 64-lane wave and raises on wave32, so test_candidate_scoring[sigmoid] failed on gfx1250, where the FFM CI shard runs test_flydsl_herd.py. Wave32 GPUs now select sigmoid candidates with topk_gating_fwd, the kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.
Summary
Three fixes to the gfx1250 HERD path from #6527:
fused_moe(herd_topk=...)raised for E > 512 (Kimi-K3, E=896). The drop is now chosen by expert count, andAITER_HERD_FUSED_DROPis removed.test_flydsl_herd.pycases failed on gfx1250.1. Keep HERD routes off the fused TP route
With fused drop,
fused_moe(herd_topk=K)keeps the K+1 candidate tensors and sets only the scalartopkto K;herd_route_psum_remapdrops one candidate per token later. #6668 added_fused_tp_routefor TP batches withtoken_num * topk <= 2048andE <= 512, and the merge put the HERD route underelif not _fused_tp_route:. That condition holds for the whole HERD window (16..128 tokens) on DeepSeek-V4-Flash (E=256, K=6) and GPT-OSS (E=128, K=4). On those steps:fused_route_psum_remapread K+1 from the tensor shape, built a K+1-wide route map, and kept every candidate with its raw weight;source_topk = K, so routerread tokenr // K, the wrong token for most routes.On b5078fc,
test_fused_moe_outputs_match_router_drop[16]returns NaN rows.Fix:
_fused_tp_routenow excludes HERD steps, so they takeherd_route_psum_remap. Non-HERD TP batches keep the fused route.2. Pick the gfx1250 HERD drop by expert count
The fused drop runs in one workgroup with one LDS slot per expert, so
herd_route_psum_remapaccepts at most 512 experts (_FUSED_ROUTE_PSUM_MAX_EXPERTS). With the defaultAITER_HERD_FUSED_DROP=1, E > 512 raised there.fused_moenow decides from E:herd_finalize_candidatesfirst (1024 threads for E > 512), then take the ordinary route.contiguous_psum_remapscans experts in chunks and supports up to 2048.Both paths produce the same routes, so the
AITER_HERD_FUSED_DROPswitch is removed. gfx950 is unchanged: there HERD finishes in the router and never reachesfused_moe(herd_topk).3. Sigmoid HERD candidates on wave32
The FlyDSL sigmoid selector in
herd_topk_candidatesballots over a 64-lane wave and raises on wave32, sotest_candidate_scoring[sigmoid]failed on gfx1250. The FFM CI shard runsop_tests/test_flydsl_herd.py. Wave32 GPUs now select sigmoid candidates withtopk_gating_fwd, the kernel sqrtsoftplus already uses. On gfx1250 it matches a torch reference for Top-17 of 896 experts with bf16 and fp32 bias. Wave64 is unchanged.Tests
op_tests/test_flydsl_herd.py: the three tests that toggledAITER_HERD_FUSED_DROPnow run (E, K) = (128, 4) and (896, 16), covering the fused drop and the finalize-first path:test_herd_topk_is_only_for_gfx1250test_fused_moe_outputs_match_router_droptest_fused_moe_herd_skips_pad_rowsROCm/ATOM#2713 routes Kimi-K3 HERD candidates through
fused_moe(herd_topk=16)with E=896, which needs fix 2.