Skip to content

[HIP] [CK] Re-submit Relu2 Tier 2 MoE GEMM support (clean CK pin) - #6376

Merged
yifehuan merged 40 commits into
ROCm:mainfrom
shantipriya-amd:feature/relu2-moe-gemm-tier2
Oct 12, 2026
Merged

yifehuan merged 40 commits into
ROCm:mainfrom
shantipriya-amd:feature/relu2-moe-gemm-tier2

Conversation

@shantipriya-amd

Copy link
Copy Markdown
Contributor

Summary

Re-submission of #5708 (Relu2 Tier 2 CK-Tile MoE GEMM support), which was reverted
because the CK submodule pin it introduced was not fetchable from CK's develop
branch (built on two local, un-upstreamed commits rather than an official commit).

Per reviewer guidance on #5708, this PR follows the 3-step recovery path:

  1. The two orphan CK commits (Add MoeRelu2 activation functor and
    Fix half_t intrinsics) were submitted and merged upstream to CK develop
    via [composablekernel] Add MoeRelu2 activation functor and fix half_t intrinsics rocm-libraries#13071.
  2. The CK submodule was repinned to the official develop commit containing
    both changes (96afae1d54fc79c26857de7e1683b0dde1ff3c6f) via [CK] Repin CK submodule to fetchable develop commit (relu2/half_t fix) #6178.
  3. This PR re-submits the original Relu2 Tier 2 code on top of that clean,
    fetchable CK pin -- rebased onto current main to pick up the repin and
    all intervening changes.

What's in this PR

Same Relu2 (gate-only, non-gated) CK-Tile two-stage MoE GEMM support as #5708:

  • aiter/fused_moe.py: Relu2 dispatch in get_2stage_cfgs / _fused_moe_impl,
    including the gate_mode/bias/use_g1u1/doweight_stage1 guard rails specific
    to the CK-Tile kFFN_gemm1_gate_only stage1 instance.
  • csrc/ck_tile_gemm_moe_2stages/*: CK-Tile instance generation and kernel
    wiring for the Relu2 activation.
  • csrc/kernels/activation_kernels.cu, csrc/include/aiter_enum.h,
    csrc/include/rocm_ops.hpp: Relu2 ActivationType plumbing.
  • aiter/ops/quant.py, csrc/kernels/quant_mxfp4.cu,
    csrc/kernels/quant_mxfp6_gemm.cu: supporting quant-path changes.
  • op_tests/test_moe_2stage.py: Relu2 test coverage.

No functional changes versus #5708 beyond what was needed to rebase cleanly
onto current main (CK submodule pin, upstream file moves/renames, and a few
small fixes squashed into the branch's commit history -- e.g. gating
enable_bias to Swiglu only, rejecting split_k=0 in the Relu2 non-split
dispatch branch, and rejecting unsupported scatter/activation-scale Relu2
CK-Tile paths).

CK submodule

Pinned to 96afae1d54fc79c26857de7e1683b0dde1ff3c6f (CK develop), confirmed
fetchable and containing both upstreamed commits from
ROCm/rocm-libraries#13071.

Related

Signed-off-by: Shantipriya Parida <shantipriya.parida@amd.com>
… output_dtype

Signed-off-by: Shantipriya Parida <shantipriya.parida@amd.com>
Copilot AI balanced review requested due to automatic review settings October 10, 2026 15:17

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.

🔵 Needs a closer look

Unsupported Relu2 configurations fall into incompatible backends, and the default Relu2 test sweep generates unsupported cases.

1 open finding
1 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Reject unsupported Relu2 capabilities before generic fallback

aiter/​fused_moe.py:3730

These exclusions only skip the Relu2 CK-Tile branch; they do not reject the unsupported call. For example, a Relu2 call with has_stage2_scatter=True or activation scales falls through to the generic dispatch: with ksplit > 1 it selects a split CK-Tile path for which no Relu2 instance is generated, and otherwise it selects ck_moe_stage1, whose activation mapper rejects Relu2. This turns the intended guard rail into a later launch failure. Reject unsupported Relu2 capabilities before fallback, or route them to a backend that implements Relu2.

Medium severity Restrict Relu2 to supported quantization triple

op_tests/​test_moe_2stage.py:1255

This enables Relu2 for every quantization triple handled by the generic branch, although the new runtime path only supports _PER1X32_BF16_FP4. Running the natural sweep with -a relu2 and no -q therefore starts with QuantType.No, reaches the legacy CK stage1 path, and fails because that mapper does not support Relu2; the sweep never reaches the supported q6 case. Filter Relu2 out unless the triple is _PER1X32_BF16_FP4, or explicitly require q6 for Relu2 sweeps.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 10, 2026 15:49

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.

🟡 Changes recommended

Relu2 is not exercised by default CI, and the added numerical checks do not currently fail on incorrect results.

3 open findings

🧠 Review effort: Balanced

Comment thread op_tests/test_activation.py Resolved
Comment thread op_tests/test_moe_2stage.py Resolved

@yifehuan yifehuan 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.

LGTM

Copilot AI balanced review requested due to automatic review settings October 12, 2026 06:42

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.

🟡 Changes recommended

The new bounds and fused-MoE tests do not currently exercise or assert the intended regressions reliably.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread op_tests/test_activation.py Resolved
@zufayu

zufayu commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

merge it if all ci passed

@yifehuan
yifehuan merged commit 7cb93dd into ROCm:main Oct 12, 2026
Klaud-Cold pushed a commit to SemiAnalysisAI/InferenceX that referenced this pull request Oct 13, 2026
The 1012 nightly bundles an aiter whose MoE dispatch rejects MiniMax-M3
(ROCm/aiter#6376) and faults at TP4 warmup. Pin nightly_202610100929 by
digest and keep ATOM_PA_FLYDSL_PLAN, which its ATOM still reads.

1012 nightly 内置的 aiter 的 MoE 分发会拒绝 MiniMax-M3(ROCm/aiter#6376),
且在 TP4 预热时出现非法内存访问。改为按摘要固定 nightly_202610100929,
并保留该 ATOM 仍会读取的 ATOM_PA_FLYDSL_PLAN。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zhiding512 added a commit that referenced this pull request Oct 13, 2026
Callers behind an EP dispatch pass the received token count as
num_local_tokens. Since #5804 the runtime then bounds the layout-v2
GEMM2 atomics by it, a compile-time choice the old mxfp4_moe.py had to
be taught by hand; on inline-sort rows the runtime instead drops the
tuned config for heuristic FlyDSL kernels that no AOT compiled.

Each row is now replayed with num_local_tokens too. Of the old script's
use_valid_token_count kernels, the replay has every one the runtime
reaches; the 227 it lacks come from bias variants of Silu/SiTUv2 rows
(the runtime enables bias for Swiglu only since #6376), from inline-sort
rows the runtime abandons under num_local_tokens, and from a token=3
row that get_padded_M never selects.

Signed-off-by: zhimding <zhimding@amd.com>
@zufayu

zufayu commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@shantipriya-amd, we are reverting this through #6460 because it introduced a gfx950 MiniMax-M3-MXFP4 regression.

The failing runtime combination is SwiGLU + has_bias=false + split_k=1. The generated CK-Tile dispatchers do not cover the required non-split/no-bias path, so the new fail-loud guard reports it as unsupported. Please do not work around this by removing the guard.

Please continue the fix in a follow-up PR. Before re-landing, it should:

  • cover the required non-split/no-bias SwiGLU dispatch path;
  • remove the empty primary-dispatcher undefined behavior;
  • add a targeted test for (SwiGLU, has_bias=false, split_k=1);
  • pass MiniMax-M3-MXFP4 TP4/TP8 validation through ci:vllm.

This is a temporary rollback of the regression, not a rejection of the Relu2 support. We can re-land it once the missing dispatch coverage is fixed and validated.

yifehuan pushed a commit that referenced this pull request Oct 16, 2026
…ispatch (follow-up to #6376 revert) (#6478)

* Add relu2 (Squared ReLU) elementwise activation kernel

Signed-off-by: Shantipriya Parida <shantipriya.parida@amd.com>

* Address Copilot review: export Relu2 in Python enum, guard test_relu2 output_dtype

Signed-off-by: Shantipriya Parida <shantipriya.parida@amd.com>

* Add relu2 (Squared ReLU) support to CK-Tile fused MoE GEMM (Tier 2)

* relu2 MoE: fix test harness gate-mode and add fail-loud guard

* test_moe_2stage: route relu2 in generic legacy sweep as gate-only

* fix(moe): restrict a16w4 relu2 CK-Tile dispatch to bf16 on gfx942/gfx950

* fix(moe): compare against ActivationType::Relu2, not internal ActivationOp id, in moe_dispatch heuristic

* fix(quant): remove duplicate hip_bfloat16 template specialization in quant_mxfp4.cu

* fix(quant): remove duplicate hip_bfloat16 template specialization in quant_mxfp6_gemm.cu

* fix(moe): remove duplicate hip_bfloat16 template specializations in topk_softmax_kernels.cu

* fix(moe): fix unsupported Relu2 combinations before tuned-config lookup

* fix(moe): guard moe_dispatch against unhandled activation/bias/split_k combos

* fix(moe): constrain Relu2 CK-Tile selector to bf16 activation dtype

* fix(moe): require both weights preshuffled for Relu2 CK-Tile dispatch

* Fix OOB write in relu2 vectorized kernel

* Fix duplicate hip_bfloat16 explicit specialization in topk_softmax_kernels_group.cu

* Guard relu2() against empty-tensor launches

* Fix Relu2 dtype selector being shadowed by Swiglu/INTERLEAVE branch

* fixed code checkin issue

* fix for CI fix

* fix(fused_moe): gate enable_bias on activation == Swiglu

* style: black-format enable_bias fix

* fix(fused_moe): clamp get_ksplit()

* fix(moe): allow split_k=1 for swiglu_mxfp4_bf16_cktile CK-Tile dispatch

* fix(moe): revert split_k=1 floor for swiglu_mxfp4_bf16_cktile

* Fix CK-Tile split_k HasBias mismatch (Swiglu) and Relu2 bias test gap

* Fix gfx942 Relu2 fp4 dispatch gap and global ksplit regression

* Apply Black formatting to gen_instances.py has_bias line

* Remove out-of-scope moe_sum_kernel conversion-safety changes

* fix(fused_moe): guard FlyDSL fallback configs against unsupported activations

* Remove out-of-scope dtype2acctype conversion-safety changes from topk_softmax_kernels_group.cu

* Fix bias regression: relu2 change silently disabled bias for SiTUv2/SiLU

* Reject unsupported scatter and activation-scale Relu2 CK-Tile paths

* Apply Black formatting to fused_moe.py

* fix(fused_moe): only enable_bias for Swiglu, not just non-Relu2

* fix(moe): reject split_k=0 in Relu2 non-split dispatch branch

* test_moe_2stage: fix Relu2 a16w4 test configuration

* test_activation: add Relu2 bounds-safety regression tests

* fix(moe): generate missing SwiGLU non-split no-bias CK-Tile MXFP4 kernel instance

* style: apply black formatting

* fix(moe): route MXFP4 gate-up SwiGLU dispatch around broken split_k=1 CK-Tile kernel

* fix(fused_moe): narrow fp4x2 CK-Tile exclusion to bf16/fp16 activation only

* fix(fused_moe): route split_k by w1 gate_up_interleave layout, not q_dtype_a (fixes PR #6478 accuracy regression)

* style(fused_moe): apply black formatting

---------

Signed-off-by: Shantipriya Parida <shantipriya.parida@amd.com>
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