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
NemotronH's non-gated MoE MLP layers use Squared ReLU (relu(x)^2) as their activation function. aiter currently only implements gated activations (silu_and_mul, gelu_and_mul, gelu_tanh_and_mul) and a plain (non-gated) gelu_fast, but has no plain Squared ReLU op.
Improving performance for the NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16 model requires enabling relu2, fused MoE GEMM support, and vLLM AITER backend integration. This PR's scope is limited to enabling relu2.
This PR adds a standalone relu2 elementwise kernel so non-gated MoE architectures like NemotronH can use aiter's fused activation path instead of falling back to eager PyTorch.
This is Tier 1 of a 3-PR series adding end-to-end relu2 support:
This PR standalone aiter elementwise kernel (no dependencies)
aiter CK-Tile fused MoE GEMM support for relu2 (depends on this PR). The draft PR is ready.
vLLM AITER backend integration (depends on the Tier 2 PR above)
Note: For end-to-end results and performance, refer to the related Tier 2 and Tier 3 PRs.
Technical Details
Mirrors the existing gelu_fast pattern end-to-end:
Declared the relu2(out, input) op signature alongside the other elementwise activations
Implemented relu2_kernel<T> (r = max(x, 0); return r * r, computed in fp32) and its launcher, using the same vectorized launch macro as the other elementwise activations
Added explicit tensor validation (GPU, contiguous, matching numel/dtype/device) before dispatch
Added the pybind11 binding so the op is exposed to Python
Added the Python-side @compile_ops(...) stub (JIT-compiled on first call, same as all other activation ops)
Added test_relu2 plus a driver loop matching the existing test_gelu_fast benchmark pattern
No changes to gated/MoE-fused activation paths, this is a plain elementwise op only.
Test Plan
Validated on MI350 (gfx950):
Correctness: compared aiter.relu2(out, x) against a torch.nn.functional.relu(x.float())**2 reference across 4 shapes:
(1024,4096), (1024,8192), (4096,4096), (4096,8192), bf16 dtype.
Performance: benchmarked aiter.relu2 vs. the same eager PyTorch reference across the same 4 shapes.
Test Result
M
N
aiter_us
torch_us
speedup
max_abs_diff
result
1024
4096
8.038
22.051
2.74x
0.000000
PASS
1024
8192
7.858
31.297
3.98x
0.000000
PASS
4096
4096
13.158
55.536
4.22x
0.000000
PASS
4096
8192
21.431
107.907
5.04x
0.000000
PASS
Exact-match correctness (max_abs_diff: 0.0) and 2.74x–5.04x speedup
vs. eager PyTorch across all tested shapes.
Submission Checklist
Essential Elements of an Effective PR Description 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 5689 --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.
github-actionsBot
changed the title
[Activation] Add standalone relu2 (Squared ReLU) elementwise kernel for non-gated MoE MLPs
[HIP] [Activation] Add standalone relu2 (Squared ReLU) elementwise kernel for non-gated MoE MLPs
Sep 19, 2026
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
ActivationType::Relu2 is added in the C++ enum but is not exported in the core pybind ActivationType enum (module_aiter_core), so ActivationType.Relu2 won’t actually be available from Python as implied.
Get a fresh assessment by requesting another Copilot review.
Adds a standalone elementwise Squared ReLU (relu(x)^2) activation kernel and exposes it through the existing HIP activation module plumbing, primarily to support non-gated MoE MLPs (e.g., NemotronH) without falling back to eager PyTorch.
Changes:
Implemented a new vectorized relu2 HIP kernel (fp32 math, cast back to input dtype) and its launcher.
Added C++/pybind and Python compile_ops stubs to expose relu2 to Python.
Added a test_relu2 benchmark + summary reporting alongside the existing activation benchmarks.
File
Description
op_tests/test_activation.py
Adds relu2 benchmark + PyTorch reference and reporting.
csrc/kernels/activation_kernels.cu
Implements relu2_kernel<T> and relu2 launcher using the existing vectorized activation macro.
csrc/include/rocm_ops.hpp
Exposes relu2(out, input) via pybind in the activation bindings.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟢 Approval recommended
The new relu2 path follows existing gelu_fast patterns end-to-end (C++ kernel + binding + Python stub + benchmark) without introducing unresolved correctness, API, or integration issues in the reviewed changes.
@amd-ruitang3 : Could you review this PR when you free ? It adds a standalone relu2 (Squared ReLU) activation kernel for NemotronH's non-gated MoE MLPs — Tier 1 of a 3-part enablement effort. CI is green and the Copilot review comments have already been addressed. Thanks!
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
Exporting ActivationType.Relu2 introduces an API surface that is not yet consistently handled by existing ActivationType dispatch/mapping code paths (risking runtime errors and/or switch-enum build warnings).
Get a fresh assessment by requesting another Copilot review.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
The new relu2 launcher lacks required shape/dtype/contiguity/device validation and can misbehave or write out of bounds if called with a mismatched out tensor.
Get a fresh assessment by requesting another Copilot review.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
There is at least one confirmed correctness/API concern (NaN semantics in relu2_kernel and an exported enum value that isn’t handled by downstream activation switches), which should be resolved before approval.
Get a fresh assessment by requesting another Copilot review.
relu2_kernel fmaxf masks NaN inputs instead of preserving them
csrc/kernels/activation_kernels.cu:2072
relu2_kernel uses fmaxf(f, 0.0f), which does not propagate NaNs (fmaxf(NaN, 0) returns 0). PyTorch ReLU preserves NaNs, so this can produce divergent results for NaN inputs and silently mask them. Use a comparison-based clamp that preserves NaNs instead of fmaxf.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
The PR description claims ActivationType::Relu2 was added, but the current branch does not define/export that enum value, so the implementation and stated scope are out of sync.
Get a fresh assessment by requesting another Copilot review.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
The PR description claims ActivationType::Relu2 was added/exposed, but the repo state shown lacks that enum value and its pybind export, creating a concrete mismatch that will block enum-based relu2 selection in follow-on work.
Get a fresh assessment by requesting another Copilot review.
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 non-gated MoE MLP layers use Squared ReLU (
relu(x)^2) as their activation function. aiter currently only implements gated activations (silu_and_mul,gelu_and_mul,gelu_tanh_and_mul) and a plain (non-gated)gelu_fast, but has no plain Squared ReLU op.Improving performance for the
NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16model requires enabling relu2, fused MoE GEMM support, and vLLM AITER backend integration. This PR's scope is limited to enabling relu2.This PR adds a standalone
relu2elementwise kernel so non-gated MoE architectures like NemotronH can use aiter's fused activation path instead of falling back to eager PyTorch.This is Tier 1 of a 3-PR series adding end-to-end relu2 support:
Note: For end-to-end results and performance, refer to the related Tier 2 and Tier 3 PRs.
Technical Details
Mirrors the existing
gelu_fastpattern end-to-end:relu2(out, input)op signature alongside the other elementwise activationsrelu2_kernel<T>(r = max(x, 0); return r * r, computed in fp32) and its launcher, using the same vectorized launch macro as the other elementwise activations@compile_ops(...)stub (JIT-compiled on first call, same as all other activation ops)test_relu2plus a driver loop matching the existingtest_gelu_fastbenchmark patternNo changes to gated/MoE-fused activation paths, this is a plain elementwise op only.
Test Plan
Validated on MI350 (gfx950):
aiter.relu2(out, x)against atorch.nn.functional.relu(x.float())**2reference across 4 shapes:(1024,4096), (1024,8192), (4096,4096), (4096,8192), bf16 dtype.
aiter.relu2vs. the same eager PyTorch reference across the same 4 shapes.Test Result
Exact-match correctness (
max_abs_diff: 0.0) and 2.74x–5.04x speedupvs. eager PyTorch across all tested shapes.
Submission Checklist
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model. (N/A -- no user-facing docs/config affected by this internal dispatch fix)