Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Platforms] Add device_type in Platform #10508

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Platforms] add device_type in Platform
Signed-off-by: MengqingCao <cmq0113@163.com>
  • Loading branch information
MengqingCao committed Nov 21, 2024
commit 49a97a06db0ece1a988e0895ee7274f63eb49249
17 changes: 2 additions & 15 deletions vllm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,21 +1191,8 @@ class DeviceConfig:
def __init__(self, device: str = "auto") -> None:
if device == "auto":
# Automated device type detection
if current_platform.is_cuda_alike():
self.device_type = "cuda"
elif current_platform.is_neuron():
self.device_type = "neuron"
elif current_platform.is_hpu():
self.device_type = "hpu"
elif current_platform.is_openvino():
self.device_type = "openvino"
elif current_platform.is_tpu():
self.device_type = "tpu"
elif current_platform.is_cpu():
self.device_type = "cpu"
elif current_platform.is_xpu():
self.device_type = "xpu"
else:
self.device_type = current_platform.device_type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will raise exception (attribute error) directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to set it in UnspecifiedPlatform too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tell me in what cases UnspecifiedPlatform would be called? I cannot confirm the device_type of that.

Copy link
Contributor Author

@MengqingCao MengqingCao Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will raise exception (attribute error) directly.

UnspecifiedPlatform inherits from Platform, thus I think this won't happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we install a cpu version pytorch in gpu environment (like arm64 chips, GH200), i think this will happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep the original error message raise RuntimeError("Failed to infer device type") , but i'm afraid this will become an attribute after this pr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your explanation, I got your point. Sorry for missing this case.

if self.device_type is None:
raise RuntimeError("Failed to infer device type")
else:
# Device type is assigned explicitly
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

class CpuPlatform(Platform):
_enum = PlatformEnum.CPU
device_type: str = "cpu"

@classmethod
def get_device_name(cls, device_id: int = 0) -> str:
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def device_id_to_physical_device_id(device_id: int) -> int:

class CudaPlatform(Platform):
_enum = PlatformEnum.CUDA
device_type: str = "cuda"

@classmethod
def get_device_capability(cls, device_id: int = 0) -> DeviceCapability:
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/hpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class HpuPlatform(Platform):
_enum = PlatformEnum.HPU
device_type: str = "hpu"

@classmethod
def get_default_attn_backend(cls, selected_backend: _Backend) -> _Backend:
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def to_int(self) -> int:

class Platform:
_enum: PlatformEnum
device_type: str

def is_cuda(self) -> bool:
return self._enum == PlatformEnum.CUDA
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class NeuronPlatform(Platform):
_enum = PlatformEnum.NEURON
device_type: str = "neuron"

@classmethod
def get_device_name(cls, device_id: int = 0) -> str:
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class OpenVinoPlatform(Platform):
_enum = PlatformEnum.OPENVINO
device_type: str = "openvino"

@classmethod
def get_default_attn_backend(cls, selected_backend: _Backend) -> _Backend:
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/rocm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

class RocmPlatform(Platform):
_enum = PlatformEnum.ROCM
device_type: str = "cuda"

@classmethod
def get_default_attn_backend(cls, selected_backend: _Backend) -> _Backend:
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/tpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class TpuPlatform(Platform):
_enum = PlatformEnum.TPU
device_type: str = "tpu"

@classmethod
def get_default_attn_backend(cls, selected_backend: _Backend) -> _Backend:
Expand Down
1 change: 1 addition & 0 deletions vllm/platforms/xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class XPUPlatform(Platform):
_enum = PlatformEnum.XPU
device_type: str = "xpu"

@classmethod
def get_default_attn_backend(cls, selected_backend: _Backend) -> _Backend:
Expand Down