Skip to content

[HIP] [CK] Add relu2 (Squared ReLU) activation support to CK-Tile fused MoE GEMM - #5708

Merged
yzhou103 merged 59 commits into
ROCm:mainfrom
shantipriya-amd:feature/relu2-moe-gemm-tier2
Oct 1, 2026
Merged

yzhou103 merged 59 commits into
ROCm:mainfrom
shantipriya-amd:feature/relu2-moe-gemm-tier2

Conversation

@shantipriya-amd

@shantipriya-amd shantipriya-amd commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

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 standalone relu2 kernel 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:

  1. [HIP] [Activation] Add standalone relu2 (Squared ReLU) elementwise kernel for non-gated MoE MLPs #5689 -- standalone aiter elementwise kernel (no dependencies)
  2. This PR -- aiter CK-Tile fused MoE GEMM support for relu2 (depends
    on Tier 1)
  3. 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).

Test Plan

Model: nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16, 8x AMD Instinct MI350 (gfx950), TP=8.

  • 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):

Test configuration:

  • Shape: model_dim=8192, inter_dim=5120, E=8, topk=2 — matches NemotronH's real hidden/intermediate dims
  • Activation: Relu2 (gate-only, gateMode=GateMode.SEPARATED, use_g1u1=False)
  • Quantization: qType=per_1x32 (mxfp4), AQDType=bf16 (activation left unquantized), WQDType=fp4x2 (weight quantized to mxfp4)
  • Token counts swept: 16, 32, 64, 128, 256 (single forward call each, strict_accuracy=True)
  • 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)
token quant config logits_diff result
16 a16w4 (activation unquantized) 4.686e-05 PASS
32 a16w4 (activation unquantized) 3.695e-05 PASS
64 a16w4 (activation unquantized) 5.848e-05 PASS
128 a16w4 (activation unquantized) 2.331e-05 PASS
256 a16w4 (activation unquantized) 4.611e-05 PASS

Every token count passes cleanly — logits_diff in 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:

  • Shape: model_dim=8192, inter_dim=5120, E=512, topk=22
  • Activation: Relu2 (gate-only, gateMode=GateMode.SEPARATED, use_g1u1=False)
  • Quantization: qType=per_1x32 (mxfp4), AQDType=bf16 (activation left unquantized), WQDType=fp4x2 (weight quantized to mxfp4)
  • Token counts swept: 16, 32, 64, 128, 256 (single forward call each, strict_accuracy=True)
  • 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)

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all 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.

@shantipriya-amd
shantipriya-amd marked this pull request as ready for review September 24, 2026 10:39
@shantipriya-amd
shantipriya-amd requested review from a team and a lite review from Copilot September 24, 2026 10:39
@github-actions github-actions Bot changed the title Add relu2 (Squared ReLU) activation support to CK-Tile fused MoE GEMM [HIP] [CK] Add relu2 (Squared ReLU) activation support to CK-Tile fused MoE GEMM Sep 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical dispatch and routing/dtype issues, plus standalone-kernel correctness gaps, remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity · 1 Medium severity

Open (4)
What changed in this PR

Adds Squared ReLU (relu2) support across standalone activation APIs and CK-Tile fused MoE GEMM paths.

Changes:

  • Adds Relu2 enums, bindings, Python APIs, and reference implementation.
  • Adds CK-Tile code generation, dispatch, and fused-MoE routing.
  • Updates conversion helpers and related tests.
File Summary
op_tests/​test_moe_2stage.py Adds Relu2 gate-only test configurations; some dtype combinations remain unsupported.
op_tests/​test_activation.py Adds standalone Relu2 correctness and benchmark coverage.
csrc/​kernels/​topk_softmax_kernels.cu Updates dtype conversion handling.
csrc/​kernels/​topk_softmax_kernels_group.cu Updates grouped top-k conversion handling.
csrc/​kernels/​quant_mxfp6_gemm.cu Adds conversion helpers.
csrc/​kernels/​quant_mxfp4.cu Adds conversion helpers.
csrc/​kernels/​activation_kernels.cu Implements the standalone Relu2 kernel.
csrc/​include/​rocm_ops.hpp Exposes Relu2 bindings.
csrc/​include/​aiter_enum.h Adds the public Relu2 enum.
csrc/​include/​activation.h Declares Relu2.
csrc/​ck_tile_gemm_moe_2stages/​moe_cktile2stages.cu Adds CK-Tile Relu2 dispatch logic.
csrc/​ck_tile_gemm_moe_2stages/​moe_cktile2stages_common.py Defines Relu2 code-generation mapping.
csrc/​ck_tile_gemm_moe_2stages/​include/​moe_cktile2stages_common.cuh Selects the Relu2 functor.
csrc/​ck_tile_gemm_moe_2stages/​gen_instances.py Generates gate-only Relu2 instances.
aiter/​ops/​quant.py Adds the eager Relu2 reference activation.
aiter/​ops/​activation.py Exposes the Python Relu2 API.
aiter/​fused_moe.py Routes eligible Relu2 MoE configurations to CK-Tile.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/fused_moe.py Resolved
Comment thread csrc/kernels/activation_kernels.cu Resolved
Comment thread op_tests/test_moe_2stage.py Resolved
@shantipriya-amd

Copy link
Copy Markdown
Contributor Author

@amd-ruitang3 : Could you review this PR when you are free ?

Copilot AI review requested due to automatic review settings September 24, 2026 12:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical compilation and runtime correctness issues, plus unresolved Relu2 dispatch, bias, layout, and test-path problems, must be fixed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 7 High severity · 1 Medium severity

Open (8)
Resolved since last review (1)

Comment thread csrc/kernels/activation_kernels.cu Resolved
Comment thread csrc/kernels/quant_mxfp4.cu Resolved
Comment thread csrc/kernels/quant_mxfp6_gemm.cu Resolved
Comment thread csrc/kernels/topk_softmax_kernels.cu Resolved
Copilot AI review requested due to automatic review settings September 24, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved dispatch guards, ROCm specialization conflicts, NaN semantics, and incomplete Relu2 test coverage block approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 8 High severity · 1 Medium severity

Open (9)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity 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.

Comment thread aiter/fused_moe.py Resolved
Comment thread aiter/fused_moe.py Resolved
Copilot AI review requested due to automatic review settings September 24, 2026 13:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unsupported relu2 combinations, dropped weights or biases, unsafe activation launches, and incomplete MoE test coverage remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 10 High severity · 1 Medium severity

Open (11)
Previously missed (1)

In code that hasn't changed since last review

Low severity 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.

Comment thread aiter/fused_moe.py Resolved
Copilot AI review requested due to automatic review settings September 24, 2026 13:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Comment thread aiter/fused_moe.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

yzhou103
yzhou103 previously approved these changes Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Moderate issues remain in optional-flag normalization, shape validation, and Relu2 test-case routing.

Review effort: Lite
Findings: None

Resolved since last review (4)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved dispatch, split-K, architecture/alignment, bias-generation, and test-reference issues require fixes.

Review effort: Lite
Findings: 1 High severity

Open (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Relu2 test coverage contains unsupported configurations and dtype mismatches that must be corrected before approval.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)

Comment thread op_tests/test_moe_2stage.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved architecture and shape routing guards, specialization generation regressions, and missing production Relu2 test coverage remain.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (1)

Comment thread aiter/fused_moe.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved moderate and critical dispatch, shape-validation, specialization, and test-coverage issues remain.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)

@shantipriya-amd

Copy link
Copy Markdown
Contributor Author

Hi @zufayu @yzhou103: Thanks for all your support in review and approval. Could you help review and merge this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants