You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HIP] [CK] Add relu2 (Squared ReLU) activation support to CK-Tile fused MoE GEMM - #5708
The fused MoE GEMM path (csrc/ck_tile_gemm_moe_2stages/) didn't support relu2 at all.
This PR adds real relu2 support to the fused MoE GEMM path, so NemotronH's MoE layers can run through aiter's fast CK-Tile kernels instead of falling back to a legacy path that doesn't support relu2 at all.
This is Tier 2 of a 3-PR series adding end-to-end relu2 support:
This PR -- aiter CK-Tile fused MoE GEMM support for relu2 (depends
on Tier 1)
vLLM AITER backend integration (depends on this PR). The PR inprogress.
Technical Details
Root cause: moe_dispatch (the CK-Tile MoE GEMM's kernel-selection function) had no case for relu2's internal activation id, so relu2 calls fell through the if/else chain with no matching branch and no return -- genuine undefined behavior, not a crash or NaN.
This PR adds the missing dispatch branch, along with the supporting relu2 activation functor, codegen routing, and Python-side wiring needed to reach it (aiter.fused_moe's get_2stage_cfgs now selects the CK-Tile relu2 path instead of falling back to a legacy codegen path that has no relu2 support at all).
Kernel-level: test_fmoe (isolated CK-Tile GEMM, vs. torch-eager reference) at E=8/topk=2 across token counts {16,32,64,128,256}, and at E=512/topk=22 (NemotronH's production MoE scale).
End-to-end: NemotronH's real checkpoint is unquantized bf16 and only reaches this fused-GEMM dispatch path when weights are quantized to fp4x2/per_1x32 at load time, so this was validated via --quantization mxfp4 online quantization in vLLM. Ran vllm bench serve (1024/1024 and 8192/1024, concurrency 128, 256 prompts) and lm_eval GSM8K (5-shot, n=1319) as an A/B test toggling only the moe_dispatch fix (identical mxfp4 quantization and hardware otherwise, fix reverted vs. applied).
Test Result
GPU Kernel Test
a16w4 (weight-only mxfp4) passes cleanly at NemotronH-realistic dimensions
Testing relu2/gate-only with only the weight quantized to mxfp4 (activation left as unquantized bf16 — AQDType=bf16, WQDType=fp4x2) at model_dim=8192, inter_dim=5120, E=8, topk=2 (NemotronH-realistic dims):
Metric: logits_diff — aiter's own calc_diff cosine-similarity-based distance between the CK-Tile kernel's GEMM output and an unquantized PyTorch fp32 reference computed with identical routing/weights
Metric: logits_diff — aiter's own calc_diff cosine-similarity-based distance between the CK-Tile kernel's GEMM output and an unquantized PyTorch fp32 reference computed with identical routing/weights
Hardware: 8x AMD Instinct MI350 (gfx950), aiter editable install at commit f42721f0e (amd-aiter-0.1.23.dev98+gf42721f0e), CK submodule at 1f66d862231703a0f354e5771e58573139bb6efb
token
quant config
logits_diff
result
16
a16w4 (activation unquantized)
6.515e-05
PASS
32
a16w4 (activation unquantized)
6.583e-05
PASS
64
a16w4 (activation unquantized)
6.260e-05
PASS
128
a16w4 (activation unquantized)
6.571e-05
PASS
256
a16w4 (activation unquantized)
6.500e-05
PASS
All five token counts pass cleanly at production scale — logits_diff in the 6.3e-05–6.6e-05 range, the same order of magnitude as the smaller E=8/topk=2 sweep above.
Submission Checklist
The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
The test plan, such as providing test command.
The test results, such as pasting the results comparison before and after, or e2e results
(Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model. (N/A -- no user-facing docs/config affected by this internal dispatch fix)
All standard extended tests (excludes ci:atom_full)
Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5708 --add-label <label>
PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.
ReLU2 incorrectly converts NaN activations to zero
csrc/kernels/activation_kernels.cu:2072
[verified] fmaxf(f, 0.0f) is non-NaN-propagating: a NaN input is converted to zero, while the reference added in op_tests/test_activation.py:190-192 preserves NaN through F.relu. The public relu2 op therefore disagrees with its stated relu(x)^2 semantics for NaN activations. Author must use a NaN-preserving ReLU formulation and add an edge-case check.
BF16/FP4 Relu2 test never exercises the new dispatch path
op_tests/test_moe_2stage.py:1179
[verified] The new use_g1u1=(act_type != Relu2) wiring is not applied to the a16w4 case used by the PR's claimed relu2 test: _PER1X32_BF16_FP4 above still yields only hard-coded ActivationType.Swiglu. Consequently, running test_fmoe with -a relu2 for BF16 activations and FP4 weights never exercises the new CK-Tile relu2 dispatch. Author must add relu2 to that case and make the test assert the path's result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
NemotronH's MoE layers use Squared ReLU (
relu(x)^2) as their activation function. Tier 1 ([HIP] [Activation] Add standalone relu2 (Squared ReLU) elementwise kernel for non-gated MoE MLPs #5689) added a standalonerelu2kernel so aiter could compute this activation directly instead of falling back to eager PyTorch, but that PR only covered the simple elementwise case, not the fused MoE GEMM path.The fused MoE GEMM path (
csrc/ck_tile_gemm_moe_2stages/) didn't support relu2 at all.This PR adds real relu2 support to the fused MoE GEMM path, so NemotronH's MoE layers can run through aiter's fast CK-Tile kernels instead of falling back to a legacy path that doesn't support relu2 at all.
This is Tier 2 of a 3-PR series adding end-to-end relu2 support:
on Tier 1)
Technical Details
Root cause:
moe_dispatch(the CK-Tile MoE GEMM's kernel-selection function) had no case for relu2's internal activation id, so relu2 calls fell through the if/else chain with no matching branch and noreturn-- genuine undefined behavior, not a crash or NaN.This PR adds the missing dispatch branch, along with the supporting relu2 activation functor, codegen routing, and Python-side wiring needed to reach it (
aiter.fused_moe'sget_2stage_cfgsnow selects the CK-Tile relu2 path instead of falling back to a legacy codegen path that has no relu2 support at all).Test Plan
Model:
nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16, 8x AMD Instinct MI350 (gfx950), TP=8.test_fmoe(isolated CK-Tile GEMM, vs. torch-eager reference) at E=8/topk=2 across token counts {16,32,64,128,256}, and at E=512/topk=22 (NemotronH's production MoE scale).--quantization mxfp4online quantization in vLLM. Ranvllm bench serve(1024/1024 and 8192/1024, concurrency 128, 256 prompts) andlm_evalGSM8K (5-shot, n=1319) as an A/B test toggling only themoe_dispatchfix (identical mxfp4 quantization and hardware otherwise, fix reverted vs. applied).Test Result
GPU Kernel Test
a16w4 (weight-only mxfp4) passes cleanly at NemotronH-realistic dimensions
Testing relu2/gate-only with only the weight quantized to mxfp4 (activation left as unquantized bf16 —
AQDType=bf16,WQDType=fp4x2) atmodel_dim=8192, inter_dim=5120, E=8, topk=2(NemotronH-realistic dims):Test configuration:
model_dim=8192, inter_dim=5120, E=8, topk=2— matches NemotronH's real hidden/intermediate dimsRelu2(gate-only,gateMode=GateMode.SEPARATED,use_g1u1=False)qType=per_1x32(mxfp4),AQDType=bf16(activation left unquantized),WQDType=fp4x2(weight quantized to mxfp4)strict_accuracy=True)logits_diff— aiter's owncalc_diffcosine-similarity-based distance between the CK-Tile kernel's GEMM output and an unquantized PyTorch fp32 reference computed with identical routing/weightsf42721f0e(amd-aiter-0.1.23.dev98+gf42721f0e)Every token count passes cleanly —
logits_diffin the 2.3e-05–5.8e-05 range, consistent with ordinary MXFP4 weight-quantization rounding noise.a16w4 passes cleanly at production MoE scale (E=512, topk=22)
Same weight-only mxfp4 configuration as above, now at NemotronH's production expert count and routing width:
Test configuration:
model_dim=8192, inter_dim=5120, E=512, topk=22Relu2(gate-only,gateMode=GateMode.SEPARATED,use_g1u1=False)qType=per_1x32(mxfp4),AQDType=bf16(activation left unquantized),WQDType=fp4x2(weight quantized to mxfp4)strict_accuracy=True)logits_diff— aiter's owncalc_diffcosine-similarity-based distance between the CK-Tile kernel's GEMM output and an unquantized PyTorch fp32 reference computed with identical routing/weightsf42721f0e(amd-aiter-0.1.23.dev98+gf42721f0e), CK submodule at1f66d862231703a0f354e5771e58573139bb6efbAll five token counts pass cleanly at production scale —
logits_diffin the 6.3e-05–6.6e-05 range, the same order of magnitude as the smaller E=8/topk=2 sweep above.Submission Checklist
supported_models.mdandexamplesfor a new model. (N/A -- no user-facing docs/config affected by this internal dispatch fix)