From 6e9cc73f674d913113cc1fd5d50f53a2ee94aa8e Mon Sep 17 00:00:00 2001 From: Ning Xie Date: Wed, 18 Jun 2025 08:21:50 +0800 Subject: [PATCH] [MISC] correct DeviceConfig device field static type analysis (#19699) Signed-off-by: Andy Xie --- vllm/config.py | 7 +++++-- vllm/engine/arg_utils.py | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vllm/config.py b/vllm/config.py index d986ab6b0edbd..7a9bc8a4f7afa 100644 --- a/vllm/config.py +++ b/vllm/config.py @@ -2285,7 +2285,7 @@ Device = Literal["auto", "cuda", "neuron", "cpu", "tpu", "xpu", "hpu"] class DeviceConfig: """Configuration for the device to use for vLLM execution.""" - device: SkipValidation[Union[Device, torch.device]] = "auto" + device: SkipValidation[Optional[Union[Device, torch.device]]] = "auto" """Device type for vLLM execution. This parameter is deprecated and will be removed in a future release. @@ -2327,7 +2327,10 @@ class DeviceConfig: "to turn on verbose logging to help debug the issue.") else: # Device type is assigned explicitly - self.device_type = self.device + if isinstance(self.device, str): + self.device_type = self.device + elif isinstance(self.device, torch.device): + self.device_type = self.device.type # Some device types require processing inputs on CPU if self.device_type in ["neuron"]: diff --git a/vllm/engine/arg_utils.py b/vllm/engine/arg_utils.py index f599d7a3bb5ed..a0e099a191109 100644 --- a/vllm/engine/arg_utils.py +++ b/vllm/engine/arg_utils.py @@ -1018,7 +1018,8 @@ class EngineArgs: from vllm.platforms import current_platform current_platform.pre_register_and_update() - device_config = DeviceConfig(device=current_platform.device_type) + device_config = DeviceConfig( + device=cast(Device, current_platform.device_type)) model_config = self.create_model_config() # * If VLLM_USE_V1 is unset, we enable V1 for "supported features"