ops: add selectable SiTU-GLU activation - #8
Open
Mantissagithub wants to merge 4 commits into
Open
Conversation
Signed-off-by: Mantissagithub <mantissa6789@gmail.com>
Mantissagithub
force-pushed
the
agent/add-situglu
branch
from
August 6, 2026 04:19
e0b6fb1 to
9025bd4
Compare
Mantissagithub
marked this pull request as ready for review
August 6, 2026 04:35
Signed-off-by: Mantissagithub <mantissa6789@gmail.com>
Author
|
@StuartSul, whenever you have a moment, i’d really appreciate it if you could take a look. thank you! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit 2f4d24e. Configure here.
Mantissagithub
force-pushed
the
agent/add-situglu
branch
2 times, most recently
from
August 11, 2026 13:42
5a2cfeb to
0bb6bec
Compare
Signed-off-by: Pradheep P <130392782+Mantissagithub@users.noreply.github.com>
Mantissagithub
force-pushed
the
agent/add-situglu
branch
from
August 11, 2026 13:48
0bb6bec to
0c15b17
Compare
Upstream split csrc/mok_megakernel.cuh into csrc/megakernel/*.cuh and added EP1 support, namespace standardization, and a forward-context recomputation kernel. Port the SiTU-GLU activation onto that layout: - Move the SiTU-GLU math into csrc/megakernel/situglu.cuh. - Add GluActivation as a third template parameter on dispatch_mlp_swiglu_combiner and thread it through the four GLU entrypoints, leaving the SwiGLU paths unchanged. - Reapply the activation at the two forward and three backward call sites in csrc/megakernel/swiglu.cuh. recompute_forward_context only compiles a SwiGLU kernel, so reject a situglu config there instead of returning SwiGLU intermediates, and record the activation on the returned forward context.
Author
|
rebased this onto the latest main and updated itt. would really appreciate it if you could take a look when you get a chance. cc @StuartSul @HuiyingLi, 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.

summary
This adds Sigmoid Tanh Unit GLU (SiTU-GLU) as a separate MoK activation while preserving SwiGLU as the default.
paper motivation
The Kimi K3 technical report observes that both multiplicative factors in SwiGLU are unbounded. Coincident large coordinates can therefore produce activation outliers and increase overflow risk in low-precision arithmetic. SiTU-GLU retains the sigmoid gate while smoothly capping the linear factor of the gate and the up branch independently.
Kimi K3, Section 2.3.2: SiTU-GLU motivation and Equation 12.
For gate pre-activation$g$ and up pre-activation $u$ , the operation is
Kimi K3 fixes the gate soft cap to$\beta_1=4$ and the up-branch soft cap to $\beta_2=25$ .
Kimi K3, Section 2.3.2: soft-cap values used by the model.
The scaled tanh remains approximately linear near the origin, keeping the local response close to SwiGLU. At large magnitude, both branches saturate and every output coordinate is bounded by$\beta_1\beta_2=100$ .
Kimi K3, Figure 4: SiTU-GLU follows SwiGLU near the origin while remaining bounded.
changes
MoKConfig.activationwith"swiglu"as the backward-compatible default and"situglu"as the new optionvalidation
No performance benchmarks were run for this PR. Validation is limited to the reference mathematics and successful SM100 compilation because no compatible SM100/SM103 system was available.
python3 -m pytest --noconftest tests/test_situglu.py -q→ 5 passedsm_100acode generation → passedgit diff --check→ passedThe distributed BF16/MXFP8 end-to-end test is included but has not been executed on physical SM100/SM103 hardware. Throughput and latency therefore remain unmeasured. The available local GPU is SM89, which cannot run this megakernel.
Closes #7
Note
Medium Risk
Touches production megakernel forward/backward (including MXFP8 and router grads). Default SwiGLU is preserved, but the new path is numerically sensitive and activation-checkpoint recompute is not implemented for SiTU-GLU.
Overview
Adds SiTU-GLU as an opt-in MoE activation (
MoKConfig.activation="situglu") while keeping SwiGLU as the default. The bounded GLU from the Kimi K3 report is compiled as separate BF16/MXFP8 forward and backward ops, not as a replacement of existing kernels.The megakernel is templated on
GluActivation. Device code uses FP32situglu_forward/situglu_backwardin shared and routed paths, including MXFP8 dequant/requant and router-gradient accumulation. Python registers parallel custom ops, fake impls, and mutation schemas, and stores the chosen activation onMoKForwardContextso backward cannot mix activations.recompute_forward_contextstill supports SwiGLU only. Tests cover the formula, bounds, derivatives, gradcheck, schemas, and a distributed BF16/MXFP8 e2e path.Reviewed by Cursor Bugbot for commit 45addfd. Bugbot is set up for automated code reviews on this repo. Configure here.