Repository navigation
[CK] [JIT] [aiter] Clamp FP8 per_Token / per_Tensor SiLU on #7019's runtime swiglu_limit - #7361
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
98b9d26 to
bdb1808
Compare
bdb1808 to
b325833
Compare
|
Rebased onto current
|
b325833 to
f332c2b
Compare
|
@yzhou103 could you review this when you have a chance? It adds CI on this head: Black, Ruff, Check Repository Dependency, C++ interface (MI300X, MI35X), OPUS, and Triton pass. The Aiter Test Gate failed because |
f332c2b to
0661db5
Compare
… runtime limit Reuse the per_1x128 runtime SiLU limit from ROCm#7019 for FP8 per_Token and per_Tensor instead of a separate silulimit / swiglustep stage1 module. - RUNTIME_SILU_LIMIT_QUANT_TYPES in moe_limits lists per_1x128, per_Token and per_Tensor; the dispatch, module, codegen, prebuild and tuner gates use it. - The non-blockscale CK stage1 template passes RuntimeSwigluLimit and the limit to DeviceMoeGemm, with the same checks as the blockscale one, and the plain FP8 heuristic dispatch forwards the flag. - get_2stage_cfgs discards tuned rows that cannot clamp before a FlyDSL whole-graph row resolves. per_Token / per_Tensor also require FP8 and inter_dim % 128 == 0. - The gfx942 per_Token rows tuned at swiglu_limit=7 move into the tuned_swiglu_limit_fmoe family. Signed-off-by: jatseng-ai <[email protected]> Co-authored-by: Cursor <[email protected]>
0661db5 to
25589d9
Compare
|
@yzhou103 thanks for the pointer. I've rebased #7361 onto latest main (after #7019) and reworked it to reuse #7019's runtime swiglu_limit infrastructure: |
Replace the pytest-only test_moe_ptpc_swiglu_limit.py with a @benchmark sweep (run_perftest, asserted checkAllclose and per-row error against the fp32 torch reference, us/TFLOPS/TB/s/err, markdown summary) and a dispatch check with an injected tagged row, both run by the standard CI invocation. Co-authored-by: Cursor <[email protected]>
Add gfx950 to _PLAIN_FP8_LIMIT_GFX so the numerical sweep and the dispatch/guard checks run on MI35x. The dispatch check's injected tagged row uses the gfx950 stage-1 and stage-2 instance names (TypeCast CDE op, N=128 stage-2 tile) on gfx950, and also asserts the stage-2 name. Co-authored-by: Cursor <[email protected]>
…nd (#8178) #7361's guard ran before #7820's gfx942 FlyDSL path, so a clamped per-token FP8 SiLU at an inter_dim that is not a multiple of 128 raised (DeepSeek-V4.1-Flash TP4 on MI308X, inter_dim 576) and tuned impl__flydsl_gfx942__ rows were dropped, although that backend applies the clamp. Keep those rows, and check the CK limits only when no FlyDSL backend takes the call.
#7361 extended the runtime SiLU clamp to FP8 per_Token and per_Tensor and moved the dispatch check. Keep its behaviour for those types (non-split, ksplit 0) and keep CK split-K under a limit for per_1x128 only, the one type with a split-K stage 1 that clamps in silu_and_mul after the reduction. Signed-off-by: Rony Leppänen <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The MI300X red after this merged is not a defect in this PR. Do not revert it (#8294 is already closed). Two follow-ups, both in #8353: (1) CK-capable clamped per-token SiLU was hitting the gfx942 FlyDSL default ( |
A clamped per-token SiLU that CK can apply (FP8, inter_dim a multiple of 128) fell through to the gfx942 FlyDSL whole-graph default. That backend's batch-1 and decode epilogues clamp BF16 activations, so the result misses the per-token reference, and its metadata has stage1=None -- the AttributeError in run 44408312107. Keep the whole-graph default only where CK rejects the shape (inter_dim not a multiple of 128, including V4.1-Flash at 576). The new predicate is the same one the NotImplementedError gate below uses, which is what defines what CK's runtime-limit stage-1 accepts. A tuned impl__flydsl_gfx942__ row still wins. This does not revert ROCm#7361. Fixes ROCm#8334 Co-authored-by: Cursor <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
With the routing above fixed, MI300X shard 5 fails one case later: at 304 CUs, per-token limit 7 uses the tuned gfx942 MulABScale rows from ROCm#7361. ci:mi300x prebuilds with GPU_ARCHS=gfx942;gfx950 and get_gfx() returns only the last entry, so the wheel never built those instances -- "Unknown or incompatible CK MoE kernel". Limit 1.0 has no tuned row, takes the gfx950 heuristic, and passes. _instance_arches() is get_gfx() plus any other MoE target in GPU_ARCHS, so the lookup carries every arch's instances. _kernels_for_arch() holds the per-arch call pair and the generator body keeps the shape it has on main. gfx942-only tiles are instantiated for the host and the gfx942 device pass and left out of the gfx950 one, guarded whenever both targets are built. Heuristic dispatch still follows get_gfx(); this only widens the lookup. Co-authored-by: Cursor <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
On gfx942 a clamped per-token FP8 SiLU that CK can clamp (FP8, inter_dim a multiple of 128) is routed to the FlyDSL whole-graph default from ROCm#7820 / ROCm#8178. That backend's metadata has stage1=None, so test_plain_fp8_swiglu_limit_dispatch, which reads md.stage1.keywords, crashes with AttributeError: 'NoneType' object has no attribute 'keywords' -- MI300X shard 5 on main, most recently run 45246107786. The route is also the wrong one for these calls: the whole-graph backend clamps the BF16 activations it reads, a different quantization point from the per-token path the call and the tuned rows from ROCm#7361 ask for. (The accuracy claim in ROCm#8334 about that backend is retracted; it is accurate against its own reference, see ROCm#8350.) Keep the whole-graph default only where CK rejects the shape (inter_dim not a multiple of 128, including V4.1-Flash at 576). The new predicate is the same one the NotImplementedError gate below uses, which is what defines what CK's runtime-limit stage-1 accepts. A tuned impl__flydsl_gfx942__ row still wins. This does not revert ROCm#7361. Fixes ROCm#8334 Co-authored-by: Cursor <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
On gfx942 a clamped per-token FP8 SiLU that CK can clamp (FP8, inter_dim a multiple of 128) is routed to the FlyDSL whole-graph default from ROCm#7820 / ROCm#8178. That backend's metadata has stage1=None, so test_plain_fp8_swiglu_limit_dispatch, which reads md.stage1.keywords, crashes with AttributeError: 'NoneType' object has no attribute 'keywords' -- MI300X shard 5 on main, most recently run 45246107786. The route is also the wrong one for these calls: the whole-graph backend clamps the BF16 activations it reads, a different quantization point from the per-token path the call and the tuned rows from ROCm#7361 ask for. (The accuracy claim in ROCm#8334 about that backend is retracted; it is accurate against its own reference, see ROCm#8350.) Keep the whole-graph default only where CK rejects the shape (inter_dim not a multiple of 128, including V4.1-Flash at 576). The new predicate is the same one the NotImplementedError gate below uses, which is what defines what CK's runtime-limit stage-1 accepts. A tuned impl__flydsl_gfx942__ row still wins. This does not revert ROCm#7361. Fixes ROCm#8334 Co-authored-by: Cursor <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
On gfx942 a clamped per-token FP8 SiLU that CK can clamp (FP8, inter_dim a multiple of 128) is routed to the FlyDSL whole-graph default from #7820 / #8178. That backend's metadata has stage1=None, so test_plain_fp8_swiglu_limit_dispatch, which reads md.stage1.keywords, crashes with AttributeError: 'NoneType' object has no attribute 'keywords' -- MI300X shard 5 on main, most recently run 45246107786. The route is also the wrong one for these calls: the whole-graph backend clamps the BF16 activations it reads, a different quantization point from the per-token path the call and the tuned rows from #7361 ask for. (The accuracy claim in #8334 about that backend is retracted; it is accurate against its own reference, see #8350.) Keep the whole-graph default only where CK rejects the shape (inter_dim not a multiple of 128, including V4.1-Flash at 576). The new predicate is the same one the NotImplementedError gate below uses, which is what defines what CK's runtime-limit stage-1 accepts. A tuned impl__flydsl_gfx942__ row still wins. This does not revert #7361. Fixes #8334 Co-authored-by: Cursor <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ship its gfx942 instances, and de-flake split-K graph replay (#8531) Three independent failures a CI run hits: - MI300X shard 5 crashed with AttributeError: 'NoneType' object has no attribute 'keywords'. A clamped per-token FP8 SiLU on gfx942 took the FlyDSL whole-graph default, whose metadata has stage1=None. Keep that default only where CK rejects the shape (inter_dim not a multiple of 128). - With routing fixed, a 304-CU limit-7 call selects the tuned gfx942 256x16...MulABScale row from #7361, which a GPU_ARCHS=gfx942;gfx950 wheel never built: Unknown or incompatible CK MoE kernel. Emit every built arch's CK MoE instance list into the lookup; heuristic dispatch still follows get_gfx(). - MI35X shard 6 flaked on test_flydsl_hgemm's bit-exact split-K graph replay. BF16 output with split_k > 1 accumulates via BufferAtomicPkAdd, so the result is atomic-order dependent (#8374). Accept one BF16 ULP there only, with a finiteness check and a guard that the replay did not reuse the captured input. Supersedes #8353 and #8351. Fixes #8334
FP8
per_Tokenandper_TensorMoE withActivationType.Silunow apply a finite positiveswiglu_limit, clamped before SiLU (gate to≤ L, up to[-L, L]), at any limit. Onmainthe limit is accepted and silently ignored on these paths. This revision is rebased ontomainafter #7019 and reuses #7019's per_1x128 runtime-limit infrastructure instead of a separate module.[MEASURED]/[READ in source]What this does
aiter/ops/moe_limits.pyaddsRUNTIME_SILU_LIMIT_QUANT_TYPES(per_1x128,per_Token,per_Tensor). The gates [HIP] [CK] [JIT] Enable swiglu_limit for FP8 per_1x128 blockscale MoE #7019 added for per_1x128 use it:get_2stage_cfgs,ck_moe_stage1,get_moe_stage_module/ck_moe_stage1_fwd, thegen_instances.py --runtime-swiglu-limitcheck, the prebuild variant list inmoe_recipes.py,gemm_moe_tune.py --swiglu_limit, and theck_moe_stage1launcher check ingemm_moe_ck2stages.cu.[READ in source]gemm_moe_ck2stages_common.cuh) already tookRuntimeSwigluLimitand the limit from [HIP] [CK] [JIT] Enable swiglu_limit for FP8 per_1x128 blockscale MoE #7019 but did not pass them on. It now passes both toDeviceMoeGemm/MakeArgument, with the sameTORCH_CHECKs as the blockscale template. The plain FP8 stage-1 heuristic dispatch (A8W8_gemm1_heuristic_dispatch,A16W16_A8W8_gemm1_gfx950_heuristic_dispatch) forwards the flag like the blockscale one. CK reads the limit only whenRuntimeSwigluLimitis true, so SwiGLU OAI instances keep their constant.[READ in source]module_moe_ck2stages_abi2_f8_f8_preshuffle_on_b16_silu_{per_token,per_tensor}_mulWeightStage2_runtime_swiglu_limit, the same module family [HIP] [CK] [JIT] Enable swiglu_limit for FP8 per_1x128 blockscale MoE #7019 uses for per_1x128.None,0.0and+infmean no clamp (normalize_swiglu_limit) and select the same kernel as an absent limit.[MEASURED]get_2stage_cfgsnow discards tuned rows that cannot clamp (ASM 1-stage, non-CK, split-K, non-_silu_) before a FlyDSL whole-graph row resolves; onmainthat check ran after the whole-graph return. For per_1x128 this only affects rows that could not clamp anyway. per_Token / per_Tensor additionally raiseNotImplementedErrorfor non-FP8 weights (e.g. int8 per_Token) andinter_dim % 128 != 0.[READ in source]aiter/configs/model_configs/a8w8_plain_tuned_swiglu_limit_fmoe_gfx942.csv(15 gfx942 per_Token rows,_tag=swiglu_limit=7) joins [HIP] [CK] [JIT] Enable swiglu_limit for FP8 per_1x128 blockscale MoE #7019'stuned_swiglu_limit_fmoefamily, soAITER_CONFIG_FMOE_SWIGLU_LIMIT_FILEmerges it and the config-collision family test checks it. Limits without a tagged row use the default config / heuristic, as for per_1x128.[READ in source]f93c029e09already containsRuntimeSwigluLimitforgridwise_moe_gemm.[READ in source]Dropped from earlier revisions
The separate
silulimitstage-1 module (aiterActOP5), theswiglustep7.0-only fallback,ck_moe_has_runtime_swiglu_limit(), the CK bump to5ec75ccf32, the privateAITER_CONFIG_FMOE_SWIGLU_LIMITloader, the reuse of the 7.0-tagged tile at other limits, andAITER_MOE_FORCE_CK2STAGE.Testing
gfx942 MI300X 304 CU, head
510c02394onmaind6bda77fe, CKf93c029e09, FlyDSL 0.5.0:AITER_MOE_2STAGE_CI_PROFILE=standard python3 op_tests/test_moe_2stage.pypasses. It now runs two new FP8 per_Token / per_Tensor SiLU limit checks fromrun_plain_fp8_limit_cases(), on gfx942 and gfx950:[MEASURED]test_plain_fp8_swiglu_limit(@benchmark, markdown summary): per_Token and per_Tensor × tokens 1 / 64 / 1024 × limitNone/0.0/+inf/ 1.0 / 7.0, model 2048 / inter 768 / 128 experts / top-8.fused_moewrites into a NaN-filled output and is timed withrun_perftest, then graded against the fp32 torch reference with an assertedcheckAllclose(rtol/atol 0.05; at most 0.39% outside on clamped cases, asserted ≤ 1%) and a maximum per-row relative L2 error (asserted < 0.05; at most 0.036 measured). Each clamped case must also differ from the unclamped reference (every row ≥ 1.09) and, at L=1, from clamp(SiLU(gate)) (every row ≥ 0.35). With the limit dropped from thefused_moecall, the first clamped case fails with 99.66% of elements outside tolerance.test_plain_fp8_swiglu_limit_dispatch: a limit always dispatches non-split CK stage 1;0.0/+infdispatch like an absent limit; an injectedswiglu_limit=3tagged row is used, and an incompatible one raises; raises forinter_dim192, int8 per_Token andasm_stage1.op_tests/test_moe_2stage.py -a silu -t 1 32 1024 -dim 2048,768 -e 128 -k 8 -sl 7, with-q 1(per_Tensor) and-q 2(per_Token): both pass, logits_diff 9.2e-6 – 1.8e-5. The same runs execute [HIP] [CK] [JIT] Enable swiglu_limit for FP8 per_1x128 blockscale MoE #7019's blockscale limit cases and guards: per_1x128 logits_diff 3.8e-6 – 1.4e-5, and 0.044 against the swapped-order reference, as before.test_swiglu_limit_guardsnow usesQuantType.Noas the unsupported example, since per_Token is supported.[MEASURED]op_tests/test_moe_a16w16_default_dispatch.py,op_tests/test_moe_per_tensor_a2_init.py,op_tests/tuning_tests/test_config_shape_collision.py: 97 passed, 34 skipped (gfx950-only), 2 subtests passed.[MEASURED]gfx950 MI355X 256 CU, head
510c02394with the gate set to("gfx942", "gfx950")(the code inb171fa95f), CKf93c029e09, FlyDSL 0.5.0, torch 2.14.1+rocm7.2 in a venv (not the CI image, which has torch 2.10.0), FP8 =float8_e4m3fn:[MEASURED]…_silu_per_{token,tensor}_mulWeightStage2_runtime_swiglu_limitmodules build and load. There are no gfx950 tagged rows, so clamped calls use the default heuristic tile, which is at most about 7% slower than the no-limit path at the same shape.{RuntimeSwigluLimit}removed fromA16W16_A8W8_gemm1_gfx950_heuristic_dispatch, the runtime-limit module fails to import at the first clamped case (undefined symbolfor theRuntimeSwigluLimit=falsestage-1 instantiation).fused_moecall, the first clamped case fails with 99.85% of elements outside tolerance.-q 1/-q 2sweep at-dim 2048,768,4096,384and7168,256,-t 1 32 64 1024 4096 -e 128 -k 8, with-sl 7and without, passes in all 12 runs. Clamped logits_diff is about 1e-5. Inter 384 takes the stage-2 K=128 path and 256 the K=256 path.-q 5 … -sl 7passes.test_gfx950_stage2_selects_k_tile, which predates this PR and does not use a limit. Under torch 2.14.1 the profiler trace keeps CK kernel names mangled, so its substring never matches. Decoding the mangled names shows the expected stage-2 tile in all 8 cases. CI runs this file aspython3 <file>, and it has no__main__, so CI does not run these tests.TypeCastCDE op and an N=128 stage-2 tile. The stage-2 name assert was added after the gfx950 run. It was checked on gfx942, and on gfx950 only byget_2stage_cfgswith the arch reported as gfx950, not on hardware.Earlier measurements (previous head, not re-run on this one)
The previous head
bdb180896ran the same CKRuntimeSwigluLimitepilogue through thesilulimitmodule on CK5ec75ccf32. On model 2048 / inter 768 / 128 experts / top-8, the stage-1 implied activation matchedsilu(L)at 7, 5 and 3 in all 30 clamped cells (per_Token and per_Tensor × 5 token counts). End to end (NorthMini, dummy fp8 weights, MI300X, 6 reps), it was +3.9% (10240-in/1024-out) and +10.7% (1024-in/1024-out) against Triton clamped at 7.0, and level with stock AITER without a limit. These numbers are from the earlier module and CK commit and are not claimed for this head.[MEASURED]onbdb180896PR Self-Review
Reviewed revision
b171fa9
Behavior and intent
On
main, a finiteswiglu_limitwith FP8per_Token/per_TensorSiLU MoE is silently ignored. This PR extends #7019's runtime SiLU limit from per_1x128 to per_Token / per_Tensor: samenormalize_swiglu_limitsemantics, sameruntime_swiglu_limitmodule family, same tagged tuning file, and the non-blockscale CK template wired the way #7019 wired the blockscale one. Paths that cannot clamp raise. per_1x128 behaviour is unchanged except that a FlyDSL whole-graph row is now discarded under a limit instead of running unclamped.Validation and unverified scope
-q 1/-q 2-sl 7runs and the dispatch / a2_init / collision tests are from25589d9d5. The commits since then change onlyop_tests/test_moe_2stage.py.510c02394with the gate enabled. PR CI runs on MI35X, so it now runs the new cases.PR-specific question
Only gfx942 per_Token has tagged tuned rows. Clamped per_Tensor calls, and every clamped call on gfx950, use the default CK heuristic tile. On gfx950 that tile is within about 7% of the no-limit path. Is that acceptable for now, or should those rows be tuned (
gemm_moe_tune.py --swiglu_limit 7) in this PR?Changed op tests
op_tests/test_moe_2stage.py: addstest_plain_fp8_swiglu_limit(numerical / perf sweep in the file's existing@benchmarkflow, next to [HIP] [CK] [JIT] Enable swiglu_limit for FP8 per_1x128 blockscale MoE #7019'stest_blockscale_swiglu_limit) andtest_plain_fp8_swiglu_limit_dispatch, both run from the CI invocation on gfx942 and gfx950;_effective_swiglu_limittreats FP8 per_Token / per_Tensor SiLU as clamped for-slruns;test_swiglu_limit_guardsusesQuantType.Nofor the unsupported case, since per_Token is now supported. The earlier pytest-onlyop_tests/test_moe_ptpc_swiglu_limit.pyis removed.Made with Cursor