add topk_softplus kernel#2995
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new MoE routing primitive (topk_softplus, intended for DeepSeek v4-style sqrt(softplus) routing) and wires it through the C++/pybind interface, Python API, and op tests/benchmarks.
Changes:
- Add
topk_softpluspybind exposure and C++ declaration. - Add a Python
aiter.topk_softplusentrypoint (JIT-compiled viamodule_moe_topk). - Extend
op_tests/test_moe_topk_sigmoid.pywithtopk_softpluscorrectness + benchmark paths and a--testselector.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| op_tests/test_moe_topk_sigmoid.py | Adds torch reference + fused invocation for topk_softplus, plus pytest correctness and CLI benchmarking updates. |
| csrc/include/rocm_ops.hpp | Extends MOE_TOPK_PYBIND to bind topk_softplus. |
| csrc/include/moe_op.h | Adds the C++ API declaration for aiter::topk_softplus. |
| aiter/ops/topk.py | Adds a compile_ops("module_moe_topk") Python stub for topk_softplus. |
| aiter/jit/optCompilerConfig.json | Adds a new source file entry to module_moe_topk build inputs for the topk_softplus implementation. |
Comments suppressed due to low confidence (1)
csrc/include/rocm_ops.hpp:1181
- Minor: the binding default for
routed_scaling_factoruses a double literal (1.0) while the C++ signature takes afloat. Consider using1.0ffor consistency with other bindings in this header and to avoid an unnecessary implicit conversion.
py::arg("local_expert_mask") = std::nullopt, \
py::arg("num_local_tokens") = std::nullopt, \
py::arg("dispatch_policy") = 0);
#define MOE_SORTING_OPUS_PYBIND \
m.def("moe_sorting_opus_fwd", \
&moe_sorting_opus_fwd, \
py::arg("topk_ids"), \
py::arg("topk_weights"), \
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+229
to
+230
| gating_output = torch.gather(gating_output, dim=-1, index=permutation) | ||
| bias = torch.randn(num_experts, dtype=dtype, device="cuda") * 0.1 |
Comment on lines
+165
to
+166
| gating_output = torch.gather(gating_output, dim=-1, index=permutation) | ||
| bias = torch.randn(num_experts, dtype=dtype, device="cuda") * 0.1 |
Contributor
Author
valarLip
approved these changes
May 6, 2026
Liang-jianhao97
pushed a commit
that referenced
this pull request
May 7, 2026
* add topk_softplus kernel * Update op_tests/test_moe_topk_sigmoid.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * format * add kernel --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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
for deepseek v4
Technical Details
topk_softplus implements the DeepSeek V4-Pro sqrtsoftplus routing: sqrt(softplus(x)) + bias → topk selection → subtract bias → renormalize → scale. The original kernel uses shared memory to stage all expert scores, then performs topk sequential full scans of the shared-memory array (each scan finds one global maximum via warp reduce and marks the winner as -INF).
Test Plan
python op_tests/test_moe_topk_sigmoid.py --test softplus --num-experts 384 256 --num-tokens 1 1024 --topk 6
Test Result
Submission Checklist