forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hardware][misc] introduce platform abstraction (vllm-project#6080)
- Loading branch information
1 parent
cc5c55d
commit b78cc8e
Showing
16 changed files
with
113 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import torch | ||
|
||
from vllm.model_executor.layers.quantization import QUANTIZATION_METHODS | ||
from vllm.utils import get_device_capability_stateless | ||
from vllm.platforms import current_platform | ||
|
||
|
||
def is_quant_method_supported(quant_method: str) -> bool: | ||
# Currently, all quantization methods require Nvidia or AMD GPUs | ||
if not torch.cuda.is_available(): | ||
return False | ||
|
||
capability = get_device_capability_stateless() | ||
capability = current_platform.get_device_capability() | ||
capability = capability[0] * 10 + capability[1] | ||
return (capability >= | ||
QUANTIZATION_METHODS[quant_method].get_min_capability()) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Optional | ||
|
||
import torch | ||
|
||
from .interface import Platform, PlatformEnum | ||
|
||
current_platform: Optional[Platform] | ||
|
||
if torch.version.cuda is not None: | ||
from .cuda import CudaPlatform | ||
current_platform = CudaPlatform() | ||
elif torch.version.hip is not None: | ||
from .rocm import RocmPlatform | ||
current_platform = RocmPlatform() | ||
else: | ||
current_platform = None | ||
|
||
__all__ = ['Platform', 'PlatformEnum', 'current_platform'] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Code inside this file can safely assume cuda platform, e.g. importing | ||
pynvml. However, it should not initialize cuda context. | ||
""" | ||
|
||
from functools import lru_cache, wraps | ||
from typing import Tuple | ||
|
||
import pynvml | ||
|
||
from .interface import Platform, PlatformEnum | ||
|
||
|
||
def with_nvml_context(fn): | ||
|
||
@wraps(fn) | ||
def wrapper(*args, **kwargs): | ||
pynvml.nvmlInit() | ||
try: | ||
return fn(*args, **kwargs) | ||
finally: | ||
pynvml.nvmlShutdown() | ||
|
||
return wrapper | ||
|
||
|
||
class CudaPlatform(Platform): | ||
_enum = PlatformEnum.CUDA | ||
|
||
@staticmethod | ||
@lru_cache(maxsize=8) | ||
@with_nvml_context | ||
def get_device_capability(device_id: int = 0) -> Tuple[int, int]: | ||
handle = pynvml.nvmlDeviceGetHandleByIndex(device_id) | ||
return pynvml.nvmlDeviceGetCudaComputeCapability(handle) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import enum | ||
from typing import Tuple | ||
|
||
|
||
class PlatformEnum(enum.Enum): | ||
CUDA = enum.auto() | ||
ROCM = enum.auto() | ||
|
||
|
||
class Platform: | ||
_enum: PlatformEnum | ||
|
||
def is_cuda(self) -> bool: | ||
return self._enum == PlatformEnum.CUDA | ||
|
||
def is_rocm(self) -> bool: | ||
return self._enum == PlatformEnum.ROCM | ||
|
||
@staticmethod | ||
def get_device_capability(device_id: int = 0) -> Tuple[int, int]: | ||
raise NotImplementedError |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from functools import lru_cache | ||
from typing import Tuple | ||
|
||
import torch | ||
|
||
from .interface import Platform, PlatformEnum | ||
|
||
|
||
class RocmPlatform(Platform): | ||
_enum = PlatformEnum.ROCM | ||
|
||
@staticmethod | ||
@lru_cache(maxsize=8) | ||
def get_device_capability(device_id: int = 0) -> Tuple[int, int]: | ||
return torch.cuda.get_device_capability(device_id) |
This file contains 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
This file contains 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