[AMD] Add aiter.topk_softmax for fused_topk#20350
Conversation
Signed-off-by: apinge <tong.qiu2@amd.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for aiter.topk_softmax within the fused_topk function, aimed at enabling fused top-k operations for specific models on AMD hardware. The changes are straightforward, adding a conditional path for when _use_aiter is active. My review identifies a potential performance issue related to an unnecessary memory allocation for token_expert_indices, which is created but not subsequently used. Addressing this could improve memory efficiency.
| token_expert_indices = torch.empty( | ||
| M, topk, dtype=torch.int32, device=hidden_states.device | ||
| ) |
There was a problem hiding this comment.
The token_expert_indices tensor is allocated here but its value is not used after the call to aiter_topk_softmax. This results in an unnecessary memory allocation on every call to fused_topk when _use_aiter is enabled. A similar pattern is present in fused_topk_deepseek with aiter_biased_grouped_topk.
If this tensor is a required output parameter for the aiter kernels that is not needed by sglang, consider checking if the aiter API allows passing None to avoid the allocation. If it's a workspace, it might be possible to manage it more efficiently, for example by using a pre-allocated buffer from a memory pool.
Motivation
This PR introduces
aiter.topk_softmaxto supportfused_topkused in Qwen3.5-397B-A17B .Modifications
Accuracy Tests
Benchmarking and Profiling
Origin kernel in prefill (8k in):

Aiter kernel in prefill (8K in)
Version:
sglang 0.5.6.post3.dev2176+gc6a99e43b
aiter: 0.1.10.post4.dev0+g6a0e7b26c.d20260222
torch 2.9.1+rocm7.2.0.lw.git7e1940d4
mi350
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci