From 203f8fa637cd9cca57c00fc3ad5f7be3ce9e9ed9 Mon Sep 17 00:00:00 2001 From: Zihua Wu <13583761+lucifer1004@users.noreply.github.com> Date: Wed, 14 Oct 2026 21:23:24 -0700 Subject: [PATCH] [#20365][fix] Use the fused DSpark RMSNorm/RoPE kernels on SM107 The RMSNorm/RoPE support gate reused the SM100/SM103 table of the DSV4 DSpark attention kernel, so the drafter always took the eager path on SM107. Give the SIMT RMSNorm/RoPE kernels their own architecture set that includes SM107 and leave the attention gate unchanged. Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com> --- .../custom_ops/dspark_rmsnorm_rope_custom_op.py | 14 +++++++++++++- .../test_dspark_cute_dsl_rmsnorm_rope.py | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tensorrt_llm/_torch/custom_ops/dspark_rmsnorm_rope_custom_op.py b/tensorrt_llm/_torch/custom_ops/dspark_rmsnorm_rope_custom_op.py index 56bc9f62d707..e34acd211300 100644 --- a/tensorrt_llm/_torch/custom_ops/dspark_rmsnorm_rope_custom_op.py +++ b/tensorrt_llm/_torch/custom_ops/dspark_rmsnorm_rope_custom_op.py @@ -25,6 +25,10 @@ 100: "sm_100", 103: "sm_103", } +# The RMSNorm/RoPE kernels are plain SIMT CuTe kernels with no architecture-specific +# instructions, so they run on more GPUs than the DSV4 DSpark attention kernel gated +# by _DSV4_DSPARK_ARCH_BY_SM. +_DSPARK_RMSNORM_ROPE_SM_VERSIONS = frozenset((100, 103, 107)) @functools.cache @@ -35,6 +39,14 @@ def _get_dspark_arch_str(sm_version: int | None = None) -> str | None: return _DSV4_DSPARK_ARCH_BY_SM.get(sm_version) +@functools.cache +def _is_dspark_rmsnorm_rope_sm_supported(sm_version: int | None = None) -> bool: + """Return whether the fused RMSNorm/RoPE kernels support this GPU.""" + if sm_version is None: + sm_version = get_sm_version() + return sm_version in _DSPARK_RMSNORM_ROPE_SM_VERSIONS + + def _has_regular_row_stride(x: torch.Tensor) -> bool: """Return whether leading dimensions flatten to non-overlapping strided rows.""" if x.is_contiguous(): @@ -70,7 +82,7 @@ def is_fused_dspark_rmsnorm_rope_supported( caller has no tensor to offer in the first place. """ operands = (x, freqs) if weight is None else (x, weight, freqs) - if _get_dspark_arch_str() is None or not all(t.is_cuda for t in operands): + if not _is_dspark_rmsnorm_rope_sm_supported() or not all(t.is_cuda for t in operands): return False if x.dtype != torch.bfloat16 or (weight is not None and weight.dtype != torch.bfloat16): return False diff --git a/tests/unittest/_torch/speculative/test_dspark_cute_dsl_rmsnorm_rope.py b/tests/unittest/_torch/speculative/test_dspark_cute_dsl_rmsnorm_rope.py index 74f1448e31ab..c661d9d8dfde 100644 --- a/tests/unittest/_torch/speculative/test_dspark_cute_dsl_rmsnorm_rope.py +++ b/tests/unittest/_torch/speculative/test_dspark_cute_dsl_rmsnorm_rope.py @@ -12,8 +12,8 @@ pytestmark = pytest.mark.skipif( not torch.cuda.is_available() or not IS_CUTLASS_DSL_AVAILABLE - or get_sm_version() not in (100, 103), - reason="DSpark fused RMSNorm+RoPE requires an SM100 or SM103 CUDA GPU", + or get_sm_version() not in (100, 103, 107), + reason="DSpark fused RMSNorm+RoPE requires an SM100, SM103, or SM107 CUDA GPU", ) @@ -67,6 +67,19 @@ def _reference( return output.to(x.dtype) +def test_fused_dspark_rmsnorm_rope_supported_architectures(): + from tensorrt_llm._torch.custom_ops.dspark_rmsnorm_rope_custom_op import ( + _get_dspark_arch_str, + _is_dspark_rmsnorm_rope_sm_supported, + ) + + assert all(_is_dspark_rmsnorm_rope_sm_supported(sm) for sm in (100, 103, 107)) + assert not any(_is_dspark_rmsnorm_rope_sm_supported(sm) for sm in (90, 101, 110, 120)) + assert _is_dspark_rmsnorm_rope_sm_supported() + # The DSV4 DSpark attention kernel keeps its own, narrower gate. + assert _get_dspark_arch_str(107) is None + + @pytest.mark.parametrize( "invalid_case", [