main
py 93 lines 3.32 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Utility functions for Helion kernel management."""
4
5 import regex as re
6 import torch
7
8 from vllm.logger import init_logger
9 from vllm.platforms import current_platform
10
11 logger = init_logger(__name__)
12
13 # Maps known variant GPU names (after lowercase/underscore normalization)
14 # to their canonical form.
15 #
16 # Names that are already canonical after normalization are NOT listed here.
17 # For example, "NVIDIA H200" normalizes to "nvidia_h200" which needs no
18 # further mapping, and AMD ROCm names like "AMD_Instinct_MI300X" come from
19 # a controlled lookup table in rocm.py and normalize cleanly to
20 # "amd_instinct_mi300x". Only names with variant suffixes (form factor,
21 # memory size, memory type, etc.) that should be stripped need entries.
22 #
23 # To add a new GPU variant: run `canonicalize_gpu_name()` without the alias
24 # to see the normalized name, then add a mapping here if it contains variant
25 # suffixes that should be stripped (e.g. Blackwell/Rubin variants).
26 _GPU_NAME_ALIASES: dict[str, str] = {
27 # H100 variants
28 "nvidia_h100_pcie": "nvidia_h100",
29 "nvidia_h100_sxm5": "nvidia_h100",
30 "nvidia_h100_80gb_hbm3": "nvidia_h100",
31 "nvidia_h100_nvl": "nvidia_h100",
32 # H200 variants
33 "nvidia_h200_nvl": "nvidia_h200",
34 "nvidia_h200_141gb_hbm3e": "nvidia_h200",
35 # A100 variants
36 "nvidia_a100_sxm4_80gb": "nvidia_a100",
37 "nvidia_a100_sxm4_40gb": "nvidia_a100",
38 "nvidia_a100_pcie_80gb": "nvidia_a100",
39 "nvidia_a100_pcie_40gb": "nvidia_a100",
40 "nvidia_a100_80gb_pcie": "nvidia_a100",
41 # V100 variants (Tesla-branded)
42 "tesla_v100_sxm2_32gb": "tesla_v100",
43 "tesla_v100_sxm2_16gb": "tesla_v100",
44 "tesla_v100_pcie_32gb": "tesla_v100",
45 "tesla_v100_pcie_16gb": "tesla_v100",
46 # AMD ROCm variants (from _ROCM_DEVICE_ID_NAME_MAP in rocm.py)
47 "amd_instinct_mi300x_hf": "amd_instinct_mi300x",
48 # ADD MORE HERE
49 }
50
51
52 def get_gpu_name(device_id: int | None = None) -> str:
53 if device_id is None:
54 logger.warning_once(
55 "get_gpu_name() called without device_id, defaulting to 0. "
56 "This may return the wrong device name in multi-node setups."
57 )
58 device_id = 0
59 return current_platform.get_device_name(device_id)
60
61
62 def canonicalize_gpu_name(name: str) -> str:
63 """Canonicalize GPU name for use as a platform identifier.
64
65 Converts to lowercase, replaces separators with underscores,
66 and maps known variant names to their canonical form via _GPU_NAME_ALIASES.
67 e.g., "NVIDIA H100 80GB HBM3" -> "nvidia_h100"
68 "NVIDIA A100-SXM4-80GB" -> "nvidia_a100"
69 "AMD Instinct MI300X" -> "amd_instinct_mi300x"
70 """
71 if not name or not name.strip():
72 raise ValueError("GPU name cannot be empty")
73 name = re.sub(r"[\s/-]+", "_", name.lower())
74 if name in _GPU_NAME_ALIASES:
75 return _GPU_NAME_ALIASES[name]
76 return name
77
78
79 def get_canonical_gpu_name(device_id: int | None = None) -> str:
80 return canonicalize_gpu_name(get_gpu_name(device_id))
81
82
83 def get_fp8_dtype() -> torch.dtype:
84 return current_platform.fp8_dtype()
85
86
87 def get_int8_min_max() -> tuple[int, int]:
88 qtype_traits = torch.iinfo(torch.int8)
89 return qtype_traits.min, qtype_traits.max
90
91
92 def get_int8_min_scaling_factor() -> float:
93 return torch.finfo(torch.float32).eps