Skip to content

feat(nvidia): add topk_softmax operator#805

Merged
voltjia merged 1 commit into
masterfrom
feat/nvidia-topk-softmax
Jul 23, 2026
Merged

feat(nvidia): add topk_softmax operator#805
voltjia merged 1 commit into
masterfrom
feat/nvidia-topk-softmax

Conversation

@voltjia

@voltjia voltjia commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add a public topk_softmax operator aligned with vLLM _moe_C::topk_softmax.
  • Add a native NVIDIA CUDA correctness implementation and focused coverage for bias, padding, renormalization, streams, descriptor reuse, index dtypes, and multi-GPU device guarding.
  • Preserve the existing topksoftmax_infinilm operator 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.

InfiniOps execution API vLLM schema Evidence
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) -> () Registered schema, C++ declaration, Python wrapper, CUDA implementation

InfiniOps preserves the same tensor roles, mutation semantics, and void / Python None return; optional bias and padding may still be None. Arguments are regrouped by the repository-wide CONTRIBUTING.md convention: gating_output, bias, and is_padding are input tensors; renormalize is a scalar attribute; and the three mutated tensors are outputs. The resulting order is therefore all inputs first, then renormalize, 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 pass renormalize explicitly instead of applying vLLM's Python-wrapper default. Python torch.bool padding 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 platform
  • fix - bug fix
  • perf - performance improvement (no behavioral change)
  • refactor - code restructuring without behavior change
  • test - adding or fixing tests only
  • docs - documentation only
  • build / ci - build system or CI configuration
  • chore - tooling, formatting, or other non-code changes
  • Breaking change

Platforms Affected

  • CPU (WITH_CPU)
  • NVIDIA (WITH_NVIDIA)
  • Iluvatar (WITH_ILUVATAR)
  • MetaX (WITH_METAX)
  • Cambricon (WITH_CAMBRICON)
  • Moore (WITH_MOORE)
  • Ascend (WITH_ASCEND)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Smoke Test Result

Commit 720097e2f608d0db470086151dfbe2ee05eea0d0 was tested from a clean detached checkout on ssh nvidia using accelerator-dev/nvidia:latest (sha256:dd94fce2f83a...), NVIDIA A100-SXM4-80GB, PyTorch 2.10.0a0+b4e4ee81d3.nv25.12, CUDA/NVCC 13.1, CMake 3.31.6, and Ninja 1.13.0.

INFINI_RT_ROOT=/opt/infinirt JOBS=16 \
  bash scripts/dev/test.sh nvidia --smoke -- --maxfail=1 -q

54 passed, 13 skipped, 7221 deselected in 11.80s

This operator is intentionally not added to the permanent smoke subset. moe_sum remains the representative vLLM MoE smoke operator, avoiding unbounded smoke-suite growth.

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA Yes operator-pruned build and existing smoke passed focused topk_softmax: 46 passed; full suite intentionally not run
Iluvatar No N/A - not affected N/A
MetaX No N/A - not affected N/A
Cambricon No N/A - not affected N/A
Moore No N/A - not affected N/A
Ascend No N/A - not affected N/A
Focused validation
cmake -S . -B build-nvidia-topk-softmax -G Ninja \
  -DPython_EXECUTABLE="$(command -v python3)" \
  -DINFINI_RT_ROOT=/opt/infinirt \
  -DWITH_CPU=OFF -DWITH_TORCH=OFF -DWITH_NVIDIA=ON \
  -DWITH_ILUVATAR=OFF -DWITH_HYGON=OFF -DWITH_CAMBRICON=OFF \
  -DWITH_METAX=OFF -DWITH_MOORE=OFF -DWITH_ASCEND=OFF \
  -DAUTO_DETECT_DEVICES=OFF -DAUTO_DETECT_BACKENDS=OFF \
  -DGENERATE_PYTHON_BINDINGS=ON \
  -DINFINI_OPS_OPS=topk_softmax
cmake --build build-nvidia-topk-softmax --target ops -j 16
cmake --install build-nvidia-topk-softmax \
  --prefix build-nvidia-topk-softmax/install/infini
PYTHONPATH=build-nvidia-topk-softmax/install \
  python3 -m pytest tests/test_topk_softmax.py --devices nvidia -q

46 passed in 2.31s

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

  • Review optional bias, padding, renormalization, and all three outputs against the pinned vLLM references.
  • bias and is_padding are optional input tensors, so they precede the scalar renormalize attribute; all three output tensors follow the attribute.
  • The CUDA source retains attribution to the pinned Apache-2.0 vLLM implementation.
  • topksoftmax_infinilm is not renamed, removed, or modified.
  • This PR adds no provider, submodule, third-party CMake integration, or smoke registration.

@voltjia
voltjia marked this pull request as ready for review July 23, 2026 06:31
@voltjia
voltjia requested a review from a team July 23, 2026 06:31
@voltjia
voltjia merged commit f51f248 into master Jul 23, 2026
15 of 20 checks passed
@voltjia
voltjia deleted the feat/nvidia-topk-softmax branch July 23, 2026 06:32
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.

1 participant