[MoE] Add gelu_tanh activation to MoE stage1 GEMM kernels#823
Open
jonahbernard wants to merge 6 commits into
Open
[MoE] Add gelu_tanh activation to MoE stage1 GEMM kernels#823jonahbernard wants to merge 6 commits into
jonahbernard wants to merge 6 commits into
Conversation
…/gui_layout Wire gelu_tanh into the split-K MoE stage1 path and add full-cross-product coverage for silu_and_mul_fq (act x quant_mode x bias x gui_layout). The new test exposed and fixed a bias-path closure-capture bug (const_expr guards).
jonahbernard
force-pushed
the
add-gelu-tanh-moe-stage1
branch
from
July 10, 2026 14:44
8c09421 to
4030fc3
Compare
coderfeli
reviewed
Jul 11, 2026
| # 1 + tanh(y): y>=0 -> 2/den ; y<0 -> 2*e/den | ||
| numerator = (y > zero).select(two, two * e) | ||
| return half * x * (numerator * (one / den)) | ||
|
|
Collaborator
There was a problem hiding this comment.
Could you help to move the act out of this moe gemm kernel file?
Author
There was a problem hiding this comment.
hi @coderfeli !
- do you want both
siluandgelu_tanhmoved out of this moe gemm kernel file? - which directory and file do you want them moved to?
- do you want the act kernels moved out of
mixed_moe_gemm_2stage.pyas well?
thank you!
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
We need MXFP4 MoE kernels that use the gelu tanh activation to run Gemma-based models with high performance in vLLM.
Technical Details
I added 2 functions:
_gelu_tanh_mul_vec4inmixed_moe_gemm_2stage.py, which is called insidedef _act_vec4(gate_v4, up_v4)gelu_tanh(x)inmoe_gemm_2stage.pyand it is called in 2 places: 1)write_row_to_ldsand 2)_stage1_store_row.write_row_to_ldsand_stage1_store_roware the two stage1 epilogue variants.For split-K support, in
kernels/silu_and_mul_fq.py, I added a compile-time branch that gates onact == gelu_tanhto thebuild_silu_and_mul_fq_moduleand skips the silu/swiglu-specific code viacontinueat the end of that gelu tanh specific branch.Test Plan
Parameterized the
test_moe_gemm_2stagePyTest oversiluandgelu_tanh. Additionally, added a branch in the PyTorch reference implementation intorch_moe_gemm1that runs PyTorch'sgelu_tanhwhentorch_moe_gemm1is called withactivation=gelu_tanh.To test the split-K path, I added a new test
test_silu_and_mul_fqthat runssilu_and_mul_fqparameterized over:activation:silu,swiglu,gelu_tanhquant_mode:none,fp8,fp4enable_bias:False,Truegui_layout:False,Trueshape:(token_num, topk, inter_dim)When I was adding this test, I discovered a bug in the kernel: a plain if enable_bias: instead of if const_expr(enable_bias):, so the flyc closure transform didn't capture the bias vars into the nested scf.IfOp blocks
Test Result
Command to run tests:
pytest tests/kernels/test_moe_gemm.py -k "test_moe_gemm_2stage and gelu_tanh" -vResults:
== 684 passed, 1620 skipped, 2344 deselected, 1 warning in 150.78s (0:02:30) ===Command to run split-k tests:
Results:
=== 144 passed, 1 warning in 16.00s ==Submission Checklist