Repository navigation
[FlyDSL] [CI] [MoE] gemm2: bound atomic rows by the sort's valid token count - #7294
Conversation
With num_local_tokens, moe_sorting fills each expert block with the pad sentinel MOE_SORTING_MOCK_ID(tokens, topk), whose token id is the REAL token count. When the caller's M is padded (cudagraph), that id is still < M, so the a16w4 and mxfp4 atomic gemm2 epilogs (bounded by token_id < M) scatter every pad slot into row `tokens`. Add use_valid_token_count to both kernels: rows are bounded by min(cumsum[1], M), as the v2 dispatcher already does. fused_moe_2stages enables it whenever num_local_tokens is passed. Off by default; the compiled kernels are unchanged when it is off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
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 |
op_tests/flydsl_tests/ is outside split_tests.sh discovery, and the file has no __main__, so add it to the explicit list and the pytest branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts with ROCm#6552 (a16wmix SiLU honours swiglu_limit), ROCm#7294 (gemm2 use_valid_token_count) and the a8w8 literal-file CI case: - gemm1 epilogue: plain silu keeps ROCm#6552's clamp_gate_up; the optional activation_bf16 rounding is applied before the activation. situ_params is now built for every activation, as on main. - gemm2 and flydsl_a16w4_gemm2: keep both reuse_lds and use_valid_token_count; their kernel-name tags stay distinct. - moe_kernels: keep the silu_clamped/activation_bf16 validation with main's bf16-weight comment. - aiter_test.sh: keep the pytest case for test_flydsl_moe_a16wfp4.py next to main's test_gemm_a8w8.py case. silu_clamped and ROCm#6552's clamped silu share the same clamp: gate is upper-bounded and up is clamped to [-limit, limit] before silu(gate) * up. silu_clamped additionally requires a positive limit and is the only mode that accepts activation_bf16. Assisted-by: GitHub Copilot Signed-off-by: yinfengLiu <[email protected]>
…942-fp8-mfma Conflicts in the a16wmix port, resolved by keeping both sides. The fp8 kernels are separate definitions, so two main changes are carried into them: - gemm1 (ROCm#6552): SiLU clamps before silu_mul_batch, so the fp8 kernel builds situ_params for every activation, as the bf16 kernel now does. The fp8 dequant still runs before the activation. - gemm2 (ROCm#7294): the fp8 kernel bounds scatter rows by min(cumsum[1], M) under use_valid_token_count, as the bf16 kernel does.
…n count (ROCm#7294) * [FlyDSL][MoE] gemm2: bound atomic rows by the sort's valid token count With num_local_tokens, moe_sorting fills each expert block with the pad sentinel MOE_SORTING_MOCK_ID(tokens, topk), whose token id is the REAL token count. When the caller's M is padded (cudagraph), that id is still < M, so the a16w4 and mxfp4 atomic gemm2 epilogs (bounded by token_id < M) scatter every pad slot into row `tokens`. Add use_valid_token_count to both kernels: rows are bounded by min(cumsum[1], M), as the v2 dispatcher already does. fused_moe_2stages enables it whenever num_local_tokens is passed. Off by default; the compiled kernels are unchanged when it is off. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [CI] Shard and run gemm2 valid-token-count test under pytest op_tests/flydsl_tests/ is outside split_tests.sh discovery, and the file has no __main__, so add it to the explicit list and the pytest branch. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: ganyi <[email protected]>
Problem
With
num_local_tokens,moe_sortingfills each expert block's tail with the pad sentinelMOE_SORTING_MOCK_ID(tokens, topk), whose token id is the real token count. When the caller'sMis padded (e.g. a cudagraph batch), that id is still< M, so the a16w4 (moe_2stage_a16wmix/gemm2.py) and native mxfp4 (mxfp4_gemm2.py) atomic epilogs, which bound rows bytoken_id < M, scatter every pad slot into rowtokens.Seen in ATOM Kimi-K3 (TP8, bs=100 decode in a 128-row cudagraph):
gemm2_a16w4_portwent 5.45 → 24.9 ms/step from the atomic pileup into one row.Fix
Add
use_valid_token_count(defaultFalse) to both gemm2s, as the v2 dispatcher already has. When it is set, rows are bounded bymin(cumsum[1], M), and the kernel name gets a_valid_tokenssuffix. When it is off, the compiled kernels are unchanged. It only applies to the atomic epilog (a16w4: non-reduce; mxfp4:epilog == "atomic").fused_moe_2stagesenables it for the flydsl / flydsl-v2 / native-mxfp4 stage2 whenevernum_local_tokensis passed.Test
op_tests/flydsl_tests/test_gemm2_valid_token_count.py(gfx950): M=128 padded with 100 real tokens, blocks padded with the sentinel. For both kernels:[0, 100);Not yet run end to end (serving / accuracy) with this branch.
🤖 Generated with Claude Code