[MoE] Added Gelu with tanh approx for CK XDL 2-stage MoE - #4620
Open
a-sidorova wants to merge 1 commit into
Open
[MoE] Added Gelu with tanh approx for CK XDL 2-stage MoE#4620a-sidorova wants to merge 1 commit into
a-sidorova wants to merge 1 commit into
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end support for the tanh-approximation GELU activation (GeluTanh) in the Composable Kernel (CK) XDL 2-stage MoE path, including C++/pybind enum exposure, CK stage-1 activation mapping, and codegen/test reference wiring.
Changes:
- Introduces
ActivationType::GeluTanh = 4and exposes it via pybind. - Maps
GeluTanhto CK’s stage-1act_op=4(gelu_tanh_and_mul) and wires"gelutanh": 4into CK 2-stage codegen. - Adds a torch reference implementation (
F.gelu(..., approximate="tanh")) and improves CLI activation parsing to be case-insensitive.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| csrc/include/aiter_enum.h | Adds the new ActivationType::GeluTanh enum value. |
| csrc/include/rocm_ops.hpp | Exposes GeluTanh through the pybind ActivationType enum. |
| csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages.cu | Maps AITER activation to CK stage-1 act_op, adding GeluTanh -> 4. |
| csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages_common.py | Extends ACT_OP_MAP/naming to include gelutanh: 4. |
| csrc/ck_gemm_moe_2stages_codegen/gen_instances.py | Adds gelutanh CLI option and an AOT prebuild loop for plain-f8 quant instances. |
| aiter/utility/dtypes.py | Makes activation parsing case-insensitive for mixed-case enum members like GeluTanh. |
| aiter/ops/quant.py | Adds torch reference mapping for GeluTanh using tanh-approx GELU. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
20
to
+23
| # CK stage1 activation op values. swiglu (OAI swiglu_oai) maps to CK act value 3; | ||
| # value 2 is intentionally skipped (reserved for a future activation variant). | ||
| ACT_OP_MAP = {"gelu": 0, "silu": 1, "swiglu": 3} | ||
| # gelutanh (gelu_tanh_and_mul) maps to CK act value 4; value 2 is intentionally | ||
| # skipped (reserved for a future activation variant). | ||
| ACT_OP_MAP = {"gelu": 0, "silu": 1, "swiglu": 3, "gelutanh": 4} |
Comment on lines
165
to
173
| def str2ActivationType(s): | ||
| """Convert string to ActivationType.""" | ||
| members = getattr(ActivationType, "__members__", None) | ||
| if members is not None: | ||
| s_lower = s.lower() | ||
| for name, member in members.items(): | ||
| if name.lower() == s_lower: | ||
| return member | ||
| raise argparse.ArgumentTypeError(f"invalid activation type: {s}") | ||
| return getattr(ActivationType, s.capitalize()) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Enable the tanh-approximation GELU activation (
gelu_tanh,0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3))))) in the AITER Composable Kernel XDL 2-stage MoE path. The MoE gridwise epilogue supports onlysilu/gelu/swiglu; this ports CK'sgelu_tanh_and_mul(ROCm/rocm-libraries#9396) into AITER so models whose MoE experts use the GELU tanh approximation (e.g. Gemma-family MoE) can run on this path.JIRA ID : ROCM-27619
Technical Details
Wires a new
GeluTanhactivation end-to-end into the CK 2-stage MoE codegen, following the existingswiglu_oaiport (78e45124):csrc/include/aiter_enum.h: addActivationType::GeluTanh = 4.csrc/include/rocm_ops.hpp: exposeGeluTanhon the pybindActivationTypeenum.csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages.cu: mapActivationType::GeluTanh -> 4(CKgelu_tanh_and_mul) inmap_activation_to_ck_stage1.gemm_moe_ck2stages_common.py: add"gelutanh": 4toACT_OP_MAP(drives CKActOPcodegen and kernel-instance naming).gen_instances.py: addgelutanhto the-actchoices and a targeted plain-f8 AOT prebuild loop (mirrors the swiglu loop; not required for correctness since runtime JIT generates on demand).CK submodule bump
3rdparty/composable_kernelto the merged feat(ck): Added Gelu with Tanh approx to XDL 2-stage MoE epilogue rocm-libraries#9396, which provides the CK-side gelu with tanh approx epilogue. This PR must be built / merged together with that CK commit.Test/reference support so the change can be validated:
aiter/ops/quant.py(get_torch_act): add theGeluTanhreference using the tanh-approx GELU (F.gelu(x, approximate="tanh")) to match CK'sFastGeluepilogue.aiter/utility/dtypes.py(str2ActivationType): case-insensitive enum lookup so mixed-case members likeGeluTanhresolve from CLI (-a gelutanh).The activation is applied in fp32 in the stage-1 epilogue; GEMM compute and quantization are untouched. CK-side support comes from ROCm/rocm-libraries#9396 (
gelu_tanh_and_mul = 4).Test Plan
Run the CK 2-stage MoE test with the new activation on the plain-f8 (a8w8) path: