Skip to content

[HIP] [Bugfix] Fix topk_sigmoid pybind conversion - #6592

Merged
rjrock merged 3 commits into
ROCm:mainfrom
rjrock:bugfix/pybind_topk_sigmoid
Oct 21, 2026
Merged

rjrock merged 3 commits into
ROCm:mainfrom
rjrock:bugfix/pybind_topk_sigmoid

Conversation

@rjrock

@rjrock rjrock commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Motivation

The sigmoid fused_topk tests in vllm fail with VLLM_ROCM_USE_AITER=1 set.

Technical Details

moe_topk_ck_pybind.cu declares topk_sigmoid with torch::Tensor parameters in its PYBIND11_MODULE binding, but includes torch/all.h, which provides the core ATen/torch C++ API without pybind11’s tensor type caster.

Without that caster, pybind11 cannot convert a Python torch.Tensor argument to torch::Tensor, so calls to topk_sigmoid fail at the binding layer. Including torch/extension.h provides the required conversion support.

Test Plan

Added test_topk_sigmoid_binding_loads to op_tests/test_topk_softmax.py, which calls topk_sigmoid directly to catch this regression.

Test Result

PASSED

Submission Checklist

@rjrock
rjrock requested a review from a team October 15, 2026 16:56
@github-actions

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:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6592 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [Bugfix] Fix topk_sigmoid pybind conversion [HIP] [Bugfix] Fix topk_sigmoid pybind conversion Oct 15, 2026
@github-actions github-actions Bot added the HIP label Oct 15, 2026
@rjrock rjrock changed the title [HIP] [Bugfix] Fix topk_sigmoid pybind conversion [Bugfix] Fix topk_sigmoid pybind conversion Oct 15, 2026
@github-actions github-actions Bot changed the title [Bugfix] Fix topk_sigmoid pybind conversion [HIP] [Bugfix] Fix topk_sigmoid pybind conversion Oct 15, 2026
@zufayu
zufayu requested a review from junhaha666 October 16, 2026 01:09
@rjrock

rjrock commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip any chance you could take a look at this?

@rjrock

rjrock commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@vgokhale could you review this when you have time?

Comment thread op_tests/test_topk_sigmoid.py Resolved
…ion.h

moe_topk_ck_pybind.cu declares topk_sigmoid with torch::Tensor
parameters for its PYBIND11_MODULE binding, but included torch/all.h,
which provides the core ATen/torch C++ API without pybind11's tensor
type caster. Without that caster, pybind11 cannot convert a Python
torch.Tensor argument into the C++ torch::Tensor parameter, so calling
topk_sigmoid from Python fails at the binding layer. torch/extension.h
pulls in the same pybind11 tensor conversion support, fixing the
binding.

Add test_topk_sigmoid_binding_loads to op_tests/test_topk_softmax.py,
which calls topk_sigmoid directly to catch this regression.

Signed-off-by: Ryan Rock <[email protected]>
@rjrock
rjrock force-pushed the bugfix/pybind_topk_sigmoid branch from 093f0b2 to 0d5fb3e Compare October 21, 2026 01:36
@junhaha666

junhaha666 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@rjrock Could you remove the newly added op_tests/test_topk_sigmoid.py?

For sigmoid routing, I recommend migrating callers to the HIP topk_gating implementation introduced in #3100, using:

aiter.topk_gating(
    topk_weights,
    topk_indices,
    gating_output,
    correction_bias=None,
    score_func="sigmoid",
    need_renorm=False,
)

This HIP path is already covered by op_tests/test_moe_topk_gating.py. #3100 reported the following improvements over the CK topk_sigmoid on MI355 with BF16 input, 128 experts, and top-8:

  • 1 token: 5.09 → 2.12 μs, approximately 2.4× faster.
  • 1024 tokens: 6.06 → 3.73 μs, approximately 1.62× faster.

The binding fix remains useful for existing CK callers, while migrating to the HIP implementation would also provide the performance benefit.

@rjrock
rjrock merged commit c741503 into ROCm:main Oct 21, 2026
@rjrock
rjrock deleted the bugfix/pybind_topk_sigmoid branch October 21, 2026 15:41
@rjrock

rjrock commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@rjrock Could you remove the newly added op_tests/test_topk_sigmoid.py?

For sigmoid routing, I recommend migrating callers to the HIP topk_gating implementation introduced in #3100, using:

aiter.topk_gating(
    topk_weights,
    topk_indices,
    gating_output,
    correction_bias=None,
    score_func="sigmoid",
    need_renorm=False,
)

This HIP path is already covered by op_tests/test_moe_topk_gating.py. #3100 reported the following improvements over the CK topk_sigmoid on MI355 with BF16 input, 128 experts, and top-8:

  • 1 token: 5.09 → 2.12 μs, approximately 2.4× faster.
  • 1024 tokens: 6.06 → 3.73 μs, approximately 1.62× faster.

The binding fix remains useful for existing CK callers, while migrating to the HIP implementation would also provide the performance benefit.

Hi @junhaha666, I squash-merged including the new test. There were no topk_sigmoid tests, so I think it's useful to keep the new test in this PR.

Thanks for the pointer on topk_gating! I will look into migrating topk_sigmoid calls to topk_gating.

@rjrock

rjrock commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@valarLip @junhaha666 please reconcile @vgokhale approving with your decision to revert. Why do you think a test is unnecessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants