Add gelu_tanh activation to no-quant CK 2-stage fused MoE#3972
Open
jonahbernard wants to merge 4 commits into
Open
Add gelu_tanh activation to no-quant CK 2-stage fused MoE#3972jonahbernard wants to merge 4 commits into
jonahbernard wants to merge 4 commits into
Conversation
Plumb a GeluTanh activation through the CK 2-stage MoE path: - ActivationType::GeluTanh enum + pybind export (aiter_enum.h, rocm_ops.hpp) - explicit ActivationType->name and AITER->CK enum-value maps; the integer values differ (Silu 0->1, Gelu 1->0, GeluTanh 3->3), handled by aiter_act_to_ck() in the host dispatch and ACT_TO_INT in codegen - ActOP widened from bool to int so codegen can emit the gelu_tanh instances - generate the no-quant bf16/fp16 gelu_tanh instances Requires the matching CK gelu_tanh_and_mul kernel support (rocm-libraries gelu-tanh-moe-bf16); submodule bump deferred until that lands and mirrors.
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
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
DiffusionGemma / Gemma4 MoE models use the tanh approximation of GELU (
gelu_tanh) in their expert MLPs. The AITER fused 2-stage CK MoE kernel previously supported onlysiluandgelu(erf) activations, so on ROCm these models either fell back to the slower unfused Triton implementation or could not run the fused path with the correct activation. This PR addsgelu_tanhas an activation in thebf16(no-quant) CK 2-stage MoE path so Gemma MoE can use the fused kernel with the mathematically correct activation.Technical Details
Paired with this PR into CK: ROCm/rocm-libraries#8886
csrc/ck_gemm_moe_2stages_codegen/): addedgelu_tanhto the activation tables.ACT_TO_INT = {"gelu": 0, "silu": 1, "gelu_tanh": 3}and matchingINT_TO_ACT; widenedActOPfrombooltoint. Ingen_instances.py, the no-quant loop now iteratesacts + ["gelu_tanh"]so the new instance is generated only for thef16/b16no-quant families (it stays out of the quant families).gelu_tanhadded to the-actCLI choices.gemm_moe_ck2stages.cu): AITER'sActivationTypeenum (Silu=0, Gelu=1, Swiglu=2, GeluTanh=3) differs from CK'sActivationenum (gelu_and_mul=0, silu_and_mul=1, …, gelu_tanh_and_mul=3). Replaced the oldactivation = !activationbool flip with an explicitaiter_act_to_ck()remap (Silu 0→1,Gelu 1→0,GeluTanh 3→3) at both stage1 and stage2 dispatch.aiter/ops/moe_op.py): addedActivationType.GeluTanh: "gelu_tanh"toact2str_dict.aiter/ops/quant.py,get_torch_act): addedGeluTanh → F.gelu(x, approximate="tanh")so the test oracle matches the CKFastGelu.aiter/utility/dtypes.py,str2ActivationType): fixed snake_case→CamelCase parsing so-a gelu_tanhresolves toActivationType.GeluTanh(previously"gelu_tanh".capitalize()→"Gelu_tanh"→AttributeError).Test Plan
Verified on a gfx950 box using the standalone CK 2-stage MoE accuracy test (
op_tests/test_moe_2stage.py), no-quantbf16,GeluTanhactivation. The test compares the fused AITER/CKkernel against a torch reference using
F.gelu(x, approximate="tanh").-q 0= no-quant (a16w16), the path this PR addsgelu_tanhto.-e 32 -k 5keepstopk ≤ experts.Test Result
6.99e-06Submission Checklist