Repository navigation
[CK] aiter#6643: relu2 for legacy ck_gemm_moe_2stages kernel - #7139
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR 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 |
There was a problem hiding this comment.
🟡 Changes recommended
The new CK ActOP=5 mapping depends on missing composable_kernel submodule support, and the gate-only branch lacks automated regression coverage for width, expert-stride, and scaling behavior.
2 open issues
What changed in this PR
Adds host-side and code-generation wiring for non-gated ReLU² in the legacy CK two-stage MoE kernel, targeting Nemotron 3 Super BF16/FP8 support.
Changes:
- Accepts
relu2in the kernel generator and maps it to CK activation value 5. - Uses the full stage-1 weight width for ReLU² while preserving the half-width calculation for gated activations.
| File | Description |
|---|---|
csrc/ck_gemm_moe_2stages_codegen/gen_instances.py |
Adds relu2 to generator activation choices. |
csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages.cu |
Maps ReLU² to CK and adjusts its stage-1 output width. |
csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages_common.py |
Registers the ReLU² activation value for code generation. |
Review effort: Balanced
|
Thanks for the MI350X validation details. Before the next review pass, could you complete the PR Self-Review section for the current head (a2c3224)? The bot currently reports all five sections missing. Please include the supported architecture/dtype/shape boundary and what remains unverified; the validation already described above can be summarized there. This is a shadow-mode readiness prompt, not a hard review gate. Separately, this PR currently points to a commit from ROCm/composable_kernel#3792 that is not on CK develop, so Check Repository Dependency and Aiter Test Gate are failing. Once the CK change lands, please update the submodule and rerun CI. Given the multi-expert expert_stride bug found during testing, please add an automated ReLU² multi-expert regression case alongside the existing gated path. |
There was a problem hiding this comment.
🟡 Changes recommended
The new regression is skipped by CI, fails before correctness validation when invoked, and does not cover the modified legacy CK path.
9 open issues
Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Regression helper is never called by the script · New Pass false for use_g1u1 to avoid unsupported metadata request · New Regression tests MXFP4, not the modified legacy CK path · New CK-Tile metadata lookup lacks kernelName · New Add regression coverage for gate-only MoE paths
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The new regression is skipped by CI, raises NotImplementedError when invoked, and targets CK-Tile rather than the modified legacy CK path, leaving that path untested.
9 open issues
Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script Add regression coverage for gate-only MoE paths
Review effort: Balanced
@zufayu: Thanks for the review and suggestions. Updated the suggested changes:
|
There was a problem hiding this comment.
🟡 Changes recommended
The new ReLU² regression is never invoked by CI, would fail before correctness checks, and targets CK-Tile rather than the modified legacy CK kernels, leaving the changed implementation without effective regression coverage.
10 open issues
Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Default profile overwrites an explicitly supplied token count · New CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script Add regression coverage for gate-only MoE paths
Review effort: Balanced
|
Checked the three new commits. One real fix, one that needs to be redone, plus a new unrelated CI failure: ✅ Fixed correctly: ❌ Item #1 (dispatch regression) is not actually fixed — New, unrelated failure: |
There was a problem hiding this comment.
🟡 Changes recommended
Missing ReLU² boundary validation permits out-of-bounds writes and incorrect routing-weight calculations, while an invalid tuning placeholder can crash kernel selection.
19 open issues
Reject sorted weights in direct ReLU² stage-1 calls · New Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script Add regression coverage for gate-only MoE paths Test the claimed production model dimensions
Review effort: Balanced
…1x32 rejection" This reverts commit 39e83d8.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues allow out-of-bounds writes for half-width ReLU² outputs, incorrect routed weighting, and dispatch crashes from an incomplete tuned configuration.
20 open issues
Reject sorted weights in direct ReLU² stage-1 calls Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Reject ReLU² routed weights in direct stage-1 calls · New Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script Add regression coverage for gate-only MoE paths Test the claimed production model dimensions
Review effort: Balanced
@zufayu: Thanks for the review. Item #1: Fixed. Item #2: Fixed earlier in a8b9c25 (both gates use get_gfx_runtime()). All CI green, including OPUS Tests (MI350X DPX). Ready for review. |
There was a problem hiding this comment.
🟡 Changes recommended
Direct ReLU² stage-1 calls can write beyond undersized output buffers and incorrectly square routing weights, leaving critical memory-safety and correctness issues unresolved.
22 open issues
Reject sorted routing weights for ReLU² stage 1 · New Reject sorted weights in direct ReLU² stage-1 calls Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Filter the incomplete gate-only tuning placeholder · New Reject ReLU² routed weights in direct stage-1 calls Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script
And 2 more that still need to be addressed.
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
A placeholder tuning row can cause a TypeError during kernel dispatch, while regression coverage omits the production configuration and CI execution of unsafe-argument checks.
23 open issues
Reject sorted routing weights for ReLU² stage 1 Reject sorted weights in direct ReLU² stage-1 calls Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Call the unsafe-args test from the CI entry point · New Filter the incomplete gate-only tuning placeholder Reject ReLU² routed weights in direct stage-1 calls Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request
And 3 more that still need to be addressed.
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
A retained placeholder row has blank kernel names that load as NaN and cause TypeError for matching dispatch requests instead of using the normal fallback.
22 open issues
Reject sorted routing weights for ReLU² stage 1 Reject sorted weights in direct ReLU² stage-1 calls Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Filter the incomplete gate-only tuning placeholder Reject ReLU² routed weights in direct stage-1 calls Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script
And 2 more that still need to be addressed.
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
An incomplete tuned-configuration row is still loaded with NaN kernel names, causing matching dispatches to raise TypeError instead of falling back to the legacy heuristic.
23 open issues
Reject sorted routing weights for ReLU² stage 1 Reject sorted weights in direct ReLU² stage-1 calls Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Enforce BF16 and QuantType.No at both ReLU² entry points · New Filter the incomplete gate-only tuning placeholder Reject ReLU² routed weights in direct stage-1 calls Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request
And 3 more that still need to be addressed.
Review effort: Balanced
|
Looked into why this is (op_tests/tuning_tests/test_csv_validation.py:235, run 46720783117 / job 143023295201) This is the new Fix: re-run tuning for the Everything else is green — |
There was a problem hiding this comment.
🔵 Needs a closer look
Direct ReLU² entry points lack BF16/no-quant guards before JIT, and the regression uses nonproduction dimensions that miss the intended Nemotron tiling boundaries.
22 open issues
Reject sorted routing weights for ReLU² stage 1 Reject sorted weights in direct ReLU² stage-1 calls Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Enforce BF16 and QuantType.No at both ReLU² entry points Reject ReLU² routed weights in direct stage-1 calls Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script
And 2 more that still need to be addressed.
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
ReLU² wrapper and module-selection entry points lack BF16/QuantType.No validation, allowing unsupported dtype and quantization combinations to reach JIT.
23 open issues
Reject sorted routing weights for ReLU² stage 1 Reject sorted weights in direct ReLU² stage-1 calls Reject outputs narrower than the ReLU² weight width Reject unsupported no-quant FP4 dtypes before dispatch Pin CK revision with ActOp=5 and expert-stride fixes Reject unsupported ReLU² blockscale combinations Validate ReLU² output width before direct stage-1 dispatch Reject sorted weights for direct ReLU² stage-1 calls Update CK submodule before enabling gate-only activation mapping Enforce BF16 and QuantType.No at both ReLU² entry points Reject ReLU² routed weights in direct stage-1 calls Use runtime GPU detection for gfx950 regression gates Gate gfx950 regression tests on the runtime architecture Validate no-quant activation and weight dtypes before dispatch Clear cached two-stage configs around the tracker regression Default profile overwrites an explicitly supplied token count CK-Tile metadata lookup lacks kernelName Regression tests MXFP4, not the modified legacy CK path Pass false for use_g1u1 to avoid unsupported metadata request Regression helper is never called by the script
And 3 more that still need to be addressed.
Review effort: Balanced
@zufayu : You're right that the gate_only_legacy row had no real measured timing (us=0.0/tflops=0.0/bw=0.0). Since this config can't genuinely be timed yet, I removed the placeholder row entirely rather than leaving it in the tuned CSV with fake zero values. Fixed in 82cf131. Verified locally before pushing. |
|
Resolved 3 of the 6 outstanding Copilot threads that are actually addressed by later commits:
Left 3 open because I can't confirm from reading the code that they're resolved — these need your input (or a fix) before merge, since the repo's ruleset requires every thread resolved:
@zufayu @shantipriya-amd flagging so one of you can either fix these or explain why they're not real gaps and resolve the threads. |
|
Resolving the remaining 3 threads to unblock merge — deferring to a follow-up PR rather than holding this one further:
@shantipriya-amd could you open a tracking issue (or a follow-up PR) for these two so they don't get lost? Everything else in this PR is in good shape — thanks for sticking with the long review cycle. |



Purpose
Adds non-gated ReLU² support to the legacy
ck_gemm_moe_2stages_codegenMoE kernel for the Nemotron model path. This closes issue #6643 for the BF16 path; FP8 per-tensor ReLU² support is tracked as a separate follow-up.The legacy kernel family only supports gated activations, so ReLU² needed a gate-only path added for weight loading, static assertions, and epilogue math. This is separate from the CK-Tile MXFP4 ReLU² work in a different kernel family.
Dependency
This PR depends on ROCm/rocm-libraries#16705, which adds ReLU² support to the CK XDL 2-stage MoE templates. (Originally submitted as ROCm/composable_kernel#3792, but that repo's develop branch is now a frozen read-only mirror following migration to the ROCm/rocm-libraries monorepo, so the fix was resubmitted there instead.) That PR has merged (commit
39483cc9a, 2026-11-25).3rdparty/composable_kernelis pinned to39483cc9aaffef7add858caa66e9eacccb495971, which contains the merged #16705 change. The submodule still points atROCm/composable_kernel.git(.gitmodulesunchanged) rather than the newROCm/rocm-librariesmonorepo; per reviewer guidance, no.gitmodulesmigration is required for this PR because the merged CK change has already propagated to the read-onlyROCm/composable_kernelmirror. A broader repoint of aiter's CK submodule toROCm/rocm-librariesis a separate, aiter-wide infra change out of scope here.Test plan
module_moe_ck2stages(gate-only ReLU²) on gfx950.torch.relu(x)**2at the production configuration (E=512,topk=22,model_dim=1024,inter_dim=2688) across a representative token sweep (1, 16, 32, 64, 128).ck_moe_stage1_fwdentry point and unsupported quant/dtype combinations before JIT.Test results
Verified on MI350X (gfx950):
module_moe_ck2stages_abi2_b16_b16_preshuffle_on_b16_relu2_no_mulWeightStage2compiles cleanly against the pinned CK commit.test_relu2_gate_only_regressionpasses at the production shape across all tested token counts (1/16/32/64/128), confirming correct gate-only ReLU² output end to end.test_relu2_stage1_rejects_unsafe_argsandtest_relu2_rejects_unsupported_quant_configspass.Reviewed revision
2be598f
Behavior and intent
This PR adds the legacy CK gate-only ReLU² path. The supported invariant is: gate-only ReLU² must stay on the no-g1u1, gate-separated,
QuantType.No, BF16-only path, with no per-expert bias and nosorted_weightspassed into stage 1 (routed weights are applied in stage 2 instead). Unsupported inputs (wrong dtype, wrong quant type, half-width output,sorted_weightsin stage1,fp4x2preshuffle) are rejected before kernel dispatch via explicit guards inget_moe_stage_moduleandck_moe_stage1_fwd.Validation and unverified scope
Validated:
IsGateUpcorrectly threaded throughexpert_strideand row/descriptor computations).get_moe_stage_moduleandck_moe_stage1_fwd.gate_only_legacytuning placeholder row.PR-specific question
Which architecture, dtype, and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
The changed path is the legacy
ck_moe_stage1gate-only ReLU² path on gfx950, using no-quant BF16 activations and weights — distinct from the already-landed CK-Tile MXFP4 ReLU² path (unaffected by this change). The invariant is that ReLU² must stay on the no-g1u1, gate-separated path and cannot reach the unsupported gate+up configuration; this is enforced by explicitNotImplementedError/ValueErrorguards rather than relying on shape alone.Changed op tests
op_tests/test_moe_2stage.py:test_relu2_gate_only_regressionnow targets the production configuration (E=512, topk=22, model_dim=1024, inter_dim=2688) and confirms legacy kernel dispatch and numerical correctness across token counts 1–128.test_relu2_stage1_rejects_unsafe_args(new): rejects a half-width output buffer,sorted_weightsin stage1, FP8 activation/weight, and non-QuantType.Noquant types.test_relu2_rejects_unsupported_quant_configs(new): rejects ReLU² + per_1x128 FP8 blockscale and ReLU² + per_1x32 with a non-fp4x2 weight dtype before JIT, while confirming genuinely supported combinations still dispatch.aiter/ops/moe_op.py: narrowedget_moe_stage_module'spreshuffle_modeguard for ReLU² to only reject thefp4x2weight case (see root-cause note above).