Repository navigation
Conversation
…-7 key DeepSeek-V4.1-Flash at TP4 with the shared expert fused as expert 385 looks up (model_dim 5120, inter_dim 640, E 385, top-7) with FP8 activations and MXFP4 weights. No table has rows for it, so prefill runs the heuristic pair with a BF16 stage-1 output, a separate FP8 quant and the atomic stage 2. Add rows for 4096, 8192 and 16384 tokens: FP8 stage-1 output with the layout stage 2 and its reduce epilogue. The XCD-swizzled stage 1 that gemm_moe_tune.py picks under uniform routing is slower with the shared expert on every token.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
|
This looks like the same bug as #8382, at your 385-expert, top-7 key. We reproduced it on MI355X (gfx950) at (5120, 640, 385, top-7) with
Cause. With a non-zero pad, the XCD remap in the xcd4 stage 1 counts one fewer N block than the kernel launches. With pad 64 and tile_k 256, the launch has 10 N blocks and the remap hands out 9. Stage-1 columns 576-639 and their scales are never written. The stage 2 here reads all 640 columns, so whatever those bytes hold reaches every output row. Whether a call fails depends on what the reused memory held, not on routing. That may be why the tuner's runs looked clean, but we did not check this. Fix. The fix is proposed in #8512. It is a one-term change so that the remap covers every launched N block. With the patch, the xcd4 kernel failed 0 of 32 calls and left no columns unwritten, against 32 of 32 unpatched. Its output was bit-identical to the non-swizzled kernel's. That run was at the 384-expert key; we did not rerun the patch at the 385 key. Effect on this PR. The non-swizzled stage 1 does not run the remap, so this cause does not affect the rows proposed here. However, we only tested Question. Did your NaN runs, and the Not tested:
|
|
@fhuizing Hi, our draft #8213 adds a row for the same key (5120, 640, 385 experts, top-7) at 16384 tokens, plus one at 32768, in The two 16384 rows:
These numbers cannot be compared: the base, the FlyDSL version and the routing all differ. Also, our row needs #7918 ( Proposal: your 16384 row stays, because it works on Two more notes. Our planned rows for 512 to 2048 tokens will not overlap yours. We also see the NaN you reported for the |
|
Hi @fhuizing, a follow-up to my comment of 11-23. I ran the op-level comparison I proposed, so here are the numbers. Setup. One MI355X per token count, the whole CUDA graph replay, us per call
Eager gives the same picture (+7 to +21 % at 4096, +25 to +26 % at 8192, +24 to +25 % at 16384). Your 4096 and 8192 rows are still 10 to 27 % faster than no row, so they help; ours help more. Why. At 8192 tokens our stage 1 ( Limits. This is op level only (no serving run). It ran on FlyDSL 0.4.0 and on our routing, not on your synthetic shared-expert routing and FlyDSL 0.5.0. Our rows need the XCD-swizzled stage 1 of #7918, which is not merged yet; yours work on main today. If you prefer another timing method (routing, number of calls, GPU count), tell me and I will run it. Proposal.
I can rerun with your method, or on a build with FlyDSL 0.5.0, if that helps. |
Summary
Add gfx950 tuned rows for the DeepSeek-V4.1-Flash TP4 A8W4 MoE key (model_dim 5120, inter_dim 640, 385 experts, top-7) at 4096, 8192 and 16384 tokens, to
aiter/configs/model_configs/dsv41_fp8fp4_tuned_fmoe.csv.Motivation
With the shared expert fused as expert 385 (
--enforce-shared-experts-fusion), SGLang looks up (5120, 640, 385, top-7) with FP8 activations and MXFP4 weights. No table has rows for this key, so prefill falls back to the heuristic pair: a stage 1 with BF16 output, a separate FP8 quant of the intermediate, and the atomic stage 2. MoE is about 31% of prefill GPU time in a DSv4.1-Flash TP4 trace on MI355X (19 full-M calls per 16k chunk).Changes
flydsl_moe1_afp8_wfp4_bf16_t128x128x256_bnt0_gui+flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm128(block_m 128).flydsl_moe1_afp8_wfp4_bf16_t64x128x256_w4_bnt0_gui+flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm64(block_m 64).gemm_moe_tune.py(uniform random routing) picks the XCD-swizzled*_xcd4_fp8stage 1. With the shared expert on every token that stage 1 is 15% slower than the unswizzled one, and the pair it picked is 3–7% slower than the heuristic end to end. The rows here were chosen with shared-expert routing instead (see below).Performance (if applicable)
fused_moeend to end (sort, input quant, both stages, reduction), BF16 hidden states,gate_mode=INTERLEAVE,quant_dtype_a=fp8,intermediate_pad=64. Routing: top-6 of 384 routed experts plus expert 384 on every token. Skew 0 is uniform routed popularity; skew 1 adds an N(0, 1) per-expert logit bias. Median of 30 interleaved reps after 10 warm-up calls, one process.TFLOP/s counts the padded inter_dim (640). Kernel breakdown at 16384 tokens, skew 0: stage 1 1383 → 1202 us (no separate 2 x 84 us quant), stage 2 953 us atomic → 663 us GEMM + 270 us reduction.
Testing
Documentation
Tuned-table rows only.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
ab3e993
Behavior and intent
Only the (5120, 640, 385, top-7) A8W4 key changes kernels, for padded token tiers 4096, 8192 and 16384. Other keys and token counts are untouched.
Validation and unverified scope
On MI355X (gfx950, FlyDSL 0.5.0):
AITER_LOG_TUNED_CONFIG=1:fused_moelogsusing 2stage (kernelName1=..., kernelName2=...)with the new rows for 4096, 8192 and 16384 tokens.python op_tests/test_moe_2stage.py --no-legacy --csv-filter t128x128x256_bnt0_gui t64x128x256_w4_bnt0_gui: the three new rows pass the strict check against the torch reference (no NaN, logits_diff 1.35e-4, the same as the existing DSv4.1 2304-inter rows at 1.37e-4).pytest op_tests/tuning_tests/test_csv_validation.py op_tests/tuning_tests/test_config_shape_collision.py: 52 passed.Not verified: serving end to end, and real DSv4.1 routing (the routing above is synthetic; the gain depends on expert-popularity skew, from 1.035x to 1.133x at 16384 tokens). Shapes at 2048 tokens and below were not measured and keep the heuristic.
Seen while testing, not changed here:
flydsl_moe1_afp8_wfp4_bf16_*_xcd4_fp8stage 1 returns NaN output under the routing above, both withflydsl_moe2_afp8_wfp4_bf16_t64x128x128_atomic(16384 tokens) and withflydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm64(8192 tokens). The tuner's uniform routing does not show it.PR-specific question
Will answer once the automated PR Self-Review comment is posted.
Changed op tests
None.