From cf1b959d985a160d639dc54311654a5dfe0257c1 Mon Sep 17 00:00:00 2001 From: Tony Lin Date: Wed, 21 Oct 2026 03:05:11 +0000 Subject: [PATCH] [Platform] Add intel xpu platform skeleton Signed-off-by: Tony Lin --- README.md | 9 +++++ deepinfer/__init__.py | 2 +- deepinfer/platform.py | 21 ++++++++++ setup.py | 3 ++ tests/test_xpu_platform.py | 82 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/test_xpu_platform.py diff --git a/README.md b/README.md index 7143caa..d962be7 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,15 @@ export DEEPINFER_ACCELERATOR=nvidia ./build.sh ``` +### Intel XPU skeleton + +`DEEPINFER_ACCELERATOR=intel` reserves an Intel backend targeting native +`torch.xpu`, without patching `torch.cuda`. This is a platform placeholder only: +runtime integration, native extensions, and model kernels are not implemented. +Accessing `deepinfer.PLATFORM` or building the native extension with this target +raises `NotImplementedError`; model inference is not supported. Intel hardware +is not automatically discovered. NVIDIA and Ascend behavior is unchanged. + ### Offline inference The default checkpoint, [`deepseek-ai/DeepSeek-V4.1-Flash-1017`](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash-1017), is diff --git a/deepinfer/__init__.py b/deepinfer/__init__.py index 9ac3a71..7efabef 100644 --- a/deepinfer/__init__.py +++ b/deepinfer/__init__.py @@ -20,7 +20,7 @@ def _so_platform_tag() -> str: accelerator = accelerator_kind() except Exception: accelerator = "" - if accelerator not in ("nvidia", "ascend"): + if accelerator not in ("nvidia", "ascend", "intel"): accelerator = "nvidia" # 无加速卡 / 探测失败:缺省按 nvidia return f"{accelerator}-{os.uname().machine}" diff --git a/deepinfer/platform.py b/deepinfer/platform.py index 020390c..17d873f 100644 --- a/deepinfer/platform.py +++ b/deepinfer/platform.py @@ -14,6 +14,7 @@ if TYPE_CHECKING: class PlatformEnum(enum.Enum): GPU = enum.auto() NPU = enum.auto() + XPU = enum.auto() class Platform: @@ -34,6 +35,10 @@ class Platform: def is_npu(self) -> bool: return self.enum is PlatformEnum.NPU + @property + def is_xpu(self) -> bool: + return self.enum is PlatformEnum.XPU + def pin_host_memory(self, tensor: torch.Tensor) -> None: """Pin host memory so async H2D/D2H copies can use the DMA fast path. @@ -219,9 +224,25 @@ class PlatformNPU(Platform): ) +class PlatformIntel(Platform): + """Placeholder for a native torch.xpu backend, without CUDA patching.""" + + enum = PlatformEnum.XPU + device_type = "xpu" + tilelang_ops_backend = "xpu" + distributed_backend = "xccl" + + def __init__(self) -> None: + raise NotImplementedError( + "Intel XPU support is a skeleton only; runtime integration, native extensions, and model kernels are not implemented." + ) + + @functools.cache def get_platform() -> Platform: from deep_cluster.hardware import accelerator_kind + if os.environ.get("DEEPINFER_ACCELERATOR") == "intel": + return PlatformIntel() platform_class = PlatformNPU if accelerator_kind() == "ascend" else PlatformGPU return platform_class() diff --git a/setup.py b/setup.py index b8223de..2cc019f 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,9 @@ import os +if os.environ.get("DEEPINFER_ACCELERATOR") == "intel": + raise NotImplementedError("Intel XPU native extension build is not implemented (skeleton only).") + import setuptools import torch from torch.utils.cpp_extension import CUDA_HOME, BuildExtension, CUDAExtension diff --git a/tests/test_xpu_platform.py b/tests/test_xpu_platform.py new file mode 100644 index 0000000..9236f8e --- /dev/null +++ b/tests/test_xpu_platform.py @@ -0,0 +1,82 @@ +"""Checks for the Intel platform placeholder without accelerator dependencies.""" + +from __future__ import annotations + +import os +import subprocess +import sys +from collections.abc import Generator +from pathlib import Path + +import pytest + +import deep_cluster.hardware +from deepinfer import platform + +ROOT = Path(__file__).resolve().parents[1] + + +@pytest.fixture(autouse=True) +def _clear_platform_cache() -> Generator[None]: + platform.get_platform.cache_clear() + yield + platform.get_platform.cache_clear() + + +def test_intel_selection_is_explicit(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("DEEPINFER_ACCELERATOR", "intel") + + def unexpected_probe() -> None: + pytest.fail("Intel selection must not probe another accelerator") + + monkeypatch.setattr(deep_cluster.hardware, "accelerator_kind", unexpected_probe) + assert platform.PlatformIntel.enum is platform.PlatformEnum.XPU + assert platform.PlatformIntel.device_type == "xpu" + with pytest.raises(NotImplementedError, match="Intel XPU support is a skeleton only"): + platform.get_platform() + + +@pytest.mark.parametrize( + "detected,cls", [("nvidia", platform.PlatformGPU), ("ascend", platform.PlatformNPU), ("cpu", platform.PlatformGPU)] +) +def test_existing_selection_is_unchanged(detected: str, cls: type[platform.Platform], monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("DEEPINFER_ACCELERATOR", raising=False) + monkeypatch.setattr(deep_cluster.hardware, "accelerator_kind", lambda: detected) + monkeypatch.setattr(cls, "__init__", lambda self: None) + assert isinstance(platform.get_platform(), cls) + + +def test_intel_placeholder_does_not_load_torch_or_cuda_artifacts() -> None: + result = subprocess.run( + [ + sys.executable, + "-c", + "import sys; import deepinfer\n" + "assert deepinfer._so_platform_tag().startswith('intel-')\n" + "try:\n" + " from deepinfer import PLATFORM\n" + "except NotImplementedError as error:\n" + " assert 'skeleton only' in str(error)\n" + "else:\n" + " raise AssertionError('Intel runtime is not implemented')\n" + "assert 'torch' not in sys.modules\n" + "assert 'deepinfer._C' not in sys.modules\n", + ], + cwd=ROOT, + env={**os.environ, "DEEPINFER_ACCELERATOR": "intel"}, + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stderr + + +def test_intel_extension_build_is_rejected() -> None: + result = subprocess.run( + [sys.executable, "setup.py", "--name"], + cwd=ROOT, + env={**os.environ, "DEEPINFER_ACCELERATOR": "intel"}, + capture_output=True, + text=True, + ) + assert result.returncode != 0 + assert "Intel XPU native extension build is not implemented" in result.stderr