Skip to content

add topk_softplus kernel#2995

Merged
valarLip merged 5 commits into
mainfrom
add_topk_softplus_kernel
May 6, 2026
Merged

add topk_softplus kernel#2995
valarLip merged 5 commits into
mainfrom
add_topk_softplus_kernel

Conversation

@yzhou103

@yzhou103 yzhou103 commented May 1, 2026

Copy link
Copy Markdown
Contributor

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

@yzhou103
yzhou103 requested review from a team and Copilot May 1, 2026 02:13
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests
ci:atom ATOM benchmark (DeepSeek-R1 + GPT-OSS)
ci:vllm vLLM benchmark
ci:all All of the above

Add labels via the sidebar or gh pr edit 2995 --add-label <label>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_softplus pybind exposure and C++ declaration.
  • Add a Python aiter.topk_softplus entrypoint (JIT-compiled via module_moe_topk).
  • Extend op_tests/test_moe_topk_sigmoid.py with topk_softplus correctness + benchmark paths and a --test selector.

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_factor uses a double literal (1.0) while the C++ signature takes a float. Consider using 1.0f for 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 thread aiter/jit/optCompilerConfig.json
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
@yzhou103

yzhou103 commented May 6, 2026

Copy link
Copy Markdown
Contributor Author
image

@valarLip
valarLip merged commit 4dcf99d into main May 6, 2026
30 checks passed
@valarLip
valarLip deleted the add_topk_softplus_kernel branch May 6, 2026 09:54
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants