feat(nvidia): add topk_softmax operator#805
Merged
Merged
Conversation
voltjia
marked this pull request as ready for review
July 23, 2026 06:31
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.
Summary
topk_softmaxoperator aligned with vLLM_moe_C::topk_softmax.topksoftmax_infinilmoperator unchanged.Motivation
vLLM exposes a stable low-level MoE routing operator with optional correction bias and padding support, plus three mutated outputs. InfiniOps currently only has
topksoftmax_infinilm, whose parameter list and two-output semantics do not match that interface.This PR adds the canonical vLLM form as a separate operator. It does not introduce a provider, submodule, or build-time dependency on vLLM.
N/A - no linked issue. This is a focused follow-up to the MoE operator work in #803 and #804.
API Alignment
Pinned upstream revision:
vllm-project/vllm@2f75e7f.topk_softmax(gating_output, bias, is_padding, renormalize, topk_weights, topk_indices, token_expert_indices)topk_softmax(Tensor! topk_weights, Tensor! topk_indices, Tensor! token_expert_indices, Tensor gating_output, bool renormalize, Tensor? bias, Tensor? is_padding) -> ()InfiniOps preserves the same tensor roles, mutation semantics, and
void/ PythonNonereturn; optional bias and padding may still beNone. Arguments are regrouped by the repository-wideCONTRIBUTING.mdconvention:gating_output,bias, andis_paddingare input tensors;renormalizeis a scalar attribute; and the three mutated tensors are outputs. The resulting order is therefore all inputs first, thenrenormalize, then all outputs. This is more than mechanically moving vLLM's output-first arguments to the end, because doing only that would leave the attribute between input tensors. The execution API also requires callers to passrenormalizeexplicitly instead of applying vLLM's Python-wrapper default. Pythontorch.boolpadding masks use the one-byte storage adapter already merged in #799; this PR adds no dtype or binding mechanism.Type of Change
feat- new feature / new operator / new platformfix- bug fixperf- performance improvement (no behavioral change)refactor- code restructuring without behavior changetest- adding or fixing tests onlydocs- documentation onlybuild/ci- build system or CI configurationchore- tooling, formatting, or other non-code changesPlatforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)Smoke Test Result
Commit
720097e2f608d0db470086151dfbe2ee05eea0d0was tested from a clean detached checkout onssh nvidiausingaccelerator-dev/nvidia:latest(sha256:dd94fce2f83a...), NVIDIA A100-SXM4-80GB, PyTorch2.10.0a0+b4e4ee81d3.nv25.12, CUDA/NVCC13.1, CMake3.31.6, and Ninja1.13.0.This operator is intentionally not added to the permanent smoke subset.
moe_sumremains the representative vLLM MoE smoke operator, avoiding unbounded smoke-suite growth.Test Results on Supported Platforms
topk_softmax:46 passed; full suite intentionally not runFocused validation
The focused suite covers FP32/FP16/BF16 input, int32/uint32/int64 expert indices, optional bias and padding, renormalized and raw weights, deterministic ties and non-finite bias, padding sentinels, empty batches, non-default streams, descriptor reuse, and multi-GPU device guarding.
Benchmark / Performance Impact
N/A - this is an initial correctness baseline and makes no performance claim. The kernel uses one 256-thread block per token row; specialized paths or workspace strategies should be proposed separately with benchmark evidence.
Notes for Reviewers
biasandis_paddingare optional input tensors, so they precede the scalarrenormalizeattribute; all three output tensors follow the attribute.topksoftmax_infinilmis not renamed, removed, or modified.