Skip to content

refactor topk softplus bias and opt - #3067

Merged
yzhou103 merged 6 commits into
ROCm:mainfrom
yzhou103:opt_topk_softplus_bias
May 8, 2026
Merged

yzhou103 merged 6 commits into
ROCm:mainfrom
yzhou103:opt_topk_softplus_bias

Conversation

@yzhou103

@yzhou103 yzhou103 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Motivation

optimization and add support sigmoid and softmax topk

Technical Details

Test Plan

Test Result

Submission Checklist

@yzhou103
yzhou103 requested review from a team and Copilot May 7, 2026 07:49
@github-actions

github-actions Bot commented May 7, 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 3067 --add-label <label>

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

Refactors the MoE fused top-k routing implementation by replacing the dedicated topk_softplus kernel with a unified “topk gating” kernel that supports multiple scoring functions (sqrtsoftplus, sigmoid, softmax) and adds an optimized register-only path for common expert counts.

Changes:

  • Replaces topk_softplus_kernels.cu with a new unified kernel implementation in topk_gating_kernels.cu (adds score-function dispatch + opt/fallback variants).
  • Extends the Python API to expose a unified topk_gating(...) wrapper and forwards score_func into the existing topk_softplus binding.
  • Expands the sigmoid/softplus op test matrix (more expert counts + adds topk=6) and updates benchmarks.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
op_tests/test_moe_topk_sigmoid.py Expands correctness/benchmark configs; uses topk_gating(..., score_func="sigmoid") for larger expert counts.
csrc/kernels/topk_softplus_kernels.cu Removes the previous dedicated softplus kernel implementation.
csrc/kernels/topk_gating_kernels.cu Adds unified fused top-k gating kernels with score-function selection and an optimized register-only variant.
csrc/include/rocm_ops.hpp Updates pybind signature/docs to include score_func for topk_softplus.
csrc/include/moe_op.h Extends topk_softplus C++ signature to accept score_func.
aiter/ops/topk.py Adds Python-level topk_gating wrapper + validates/threads through score_func.
aiter/jit/optCompilerConfig.json Updates build sources to compile the new unified gating kernel file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread csrc/kernels/topk_gating_kernels.cu Resolved
Comment thread csrc/kernels/topk_gating_kernels.cu Resolved
Comment thread op_tests/test_moe_topk_sigmoid.py Resolved
Comment thread aiter/ops/topk.py Resolved
@yzhou103

yzhou103 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author
image

@yzhou103
yzhou103 merged commit 9cfbdc8 into ROCm:main May 8, 2026
44 of 45 checks passed
valarLip pushed a commit that referenced this pull request May 8, 2026
chuanbowang2026 pushed a commit that referenced this pull request May 9, 2026
test_moe_topk_sigmoid.py was renamed to test_moe_topk_gating.py in #3067
but split_tests.sh was not updated, causing CI to fail with file not found.
valarLip pushed a commit that referenced this pull request May 10, 2026
* perf(topk): optimize radix top-k kernel for MI308X and MI355X
- Tune BitsPerPass: MI308X mb=10/ob=11, MI355X mb=11/ob=12
- Add multi-block persistent radix kernel with cross-block atomic barrier
- Add __syncthreads after MB histogram flush before atomicInc
- Fix rowStarts offset for non-zero prefix in prefill path
- Add row_len<=k fast path for multi-block kernel
- Fix stride bug in MB row_len<=k guard
- Fix in_idx_buf+rowStart double-add semantic issue

* fix(topk): restore topk_plain entry after removing standalone_stable_radix_11bits

topk_plain_kernels.cu still called the deleted aiter::standalone_stable_radix_11bits,
breaking op_tests/test_topk_plain.py. Add a non-template radix_topk_dispatch in
topk_per_row_kernels.cu that dispatches between mb and ob paths via
should_use_mulblocks, and route topk_per_row_kernel_launcher through it.

* fix(ci): update renamed test file in split_tests.sh
test_moe_topk_sigmoid.py was renamed to test_moe_topk_gating.py in #3067
but split_tests.sh was not updated, causing CI to fail with file not found.

* perf(topk): add wave-cap for multiblock grid_dim on high-CU parts (MI35X/MI355X)

---------

Co-authored-by: root <[email protected]>
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.

4 participants