diff --git a/tests/ut/test_platform.py b/tests/ut/test_platform.py index 06cc14c4..0f91ca4d 100644 --- a/tests/ut/test_platform.py +++ b/tests/ut/test_platform.py @@ -110,6 +110,15 @@ class TestNPUPlatform(TestBase): self.assertEqual(self.platform.get_device_name(device_id), device_name) mock_get_device_name.assert_called_once_with(0) + @patch("torch.npu.get_device_properties") + def test_get_device_uuid(self, mock_get_device_properties): + device_id = 0 + device_properties = MagicMock() + device_properties.uuid = "01020304-0000-0000-0000-01020304" + mock_get_device_properties.return_value = device_properties + self.assertEqual(self.platform.get_device_uuid(device_id), device_properties.uuid) + mock_get_device_properties.assert_called_once_with(0) + @patch("torch.inference_mode") def test_inference_mode(self, mock_inference_mode): mock_inference_mode.return_value = None diff --git a/vllm_ascend/platform.py b/vllm_ascend/platform.py index c0af4d00..d3c926b6 100644 --- a/vllm_ascend/platform.py +++ b/vllm_ascend/platform.py @@ -162,6 +162,13 @@ class NPUPlatform(Platform): def get_device_name(cls, device_id: int = 0) -> str: return torch.npu.get_device_name(device_id) + @classmethod + def get_device_uuid(cls, device_id: int = 0) -> str: + device_props = torch.npu.get_device_properties(device_id) + if not hasattr(device_props, "uuid") or device_props.uuid is None: + raise RuntimeError(f"Device {device_id} does not have a valid UUID.") + return device_props.uuid + @classmethod def inference_mode(cls): return torch.inference_mode()