Files
DeepInfer/tests/test_platform_arch.py
T
shunyadandClaude Opus 5.5 9da41ad18e refactor(platform): describe NVIDIA families with a capability table
Call sites tested `not PLATFORM.is_sm120` to mean "has the SM100 fused
kernels", hard-coded SM120 constants next to their use, and treated any GPU
that is not 12.x as SM100. A new family (or 12.x variant) would need every
site revisited, and an unsupported GPU silently took SM100 paths.

- deepinfer.platform.NVIDIA_ARCHS maps compute capability major to an
  NvidiaArch entry: sm100_fused_kernels, grouped_gemm_zero_padding,
  kv_block_alignment and default_comm_sms, with the same values SM100 and
  SM120 used before.
- Platform exposes them as capabilities (has_sm100_fused_kernels, ...), with
  the previous values on Ascend; the mega MoE / gate / mHC, fused
  norm-rope-attn-rope-cast, FP8 einsum output, grouped GEMM zero padding, KV
  block alignment and default EP comm SM sites ask for the capability.
- PlatformGPU.nvidia_arch selects the entry from the first visible GPU. No
  visible GPU still means SM100; a GPU of an unsupported family now raises
  instead of running SM100 kernels. is_sm120 stays for the SM120 backends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 22:28:43 -08:00

53 lines
2.1 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""NVIDIA family selection of PlatformGPU from the first visible GPU's compute capability (no GPU needed)."""
from __future__ import annotations
import pytest
from deep_cluster import hardware
from deep_cluster.hardware import nvidia
from deepinfer.platform import NVIDIA_ARCHS, PlatformGPU
def _platform(monkeypatch: pytest.MonkeyPatch, capability: tuple[int, int] | None) -> PlatformGPU:
monkeypatch.setattr(hardware, "visible_device_ids", lambda: ("0",))
monkeypatch.setattr(nvidia, "compute_capability", lambda index=0: capability)
return PlatformGPU()
@pytest.mark.parametrize(("capability", "name"), [((10, 0), "sm100"), ((10, 3), "sm100"), ((12, 0), "sm120"), (None, "sm100")])
def test_family_from_capability(monkeypatch: pytest.MonkeyPatch, capability: tuple[int, int] | None, name: str) -> None:
platform = _platform(monkeypatch, capability)
arch = platform.nvidia_arch
assert arch.name == name
assert platform.is_sm120 is (name == "sm120")
assert platform.has_sm100_fused_kernels is arch.sm100_fused_kernels
assert platform.grouped_gemm_zero_padding is arch.grouped_gemm_zero_padding
assert platform.kv_block_alignment == arch.kv_block_alignment
assert platform.default_comm_sms == arch.default_comm_sms
def test_unsupported_family_is_an_error(monkeypatch: pytest.MonkeyPatch) -> None:
platform = _platform(monkeypatch, (9, 0))
with pytest.raises(RuntimeError, match=r"compute capability 9\.0; supported: sm100 \(10\.x\), sm120 \(12\.x\)"):
_ = platform.is_sm120
def test_capabilities_keep_the_previous_per_family_values() -> None:
sm100, sm120 = NVIDIA_ARCHS[10], NVIDIA_ARCHS[12]
assert (sm100.sm100_fused_kernels, sm100.grouped_gemm_zero_padding, sm100.kv_block_alignment, sm100.default_comm_sms) == (
True,
True,
128,
None,
)
assert (sm120.sm100_fused_kernels, sm120.grouped_gemm_zero_padding, sm120.kv_block_alignment, sm120.default_comm_sms) == (
False,
False,
512,
12,
)