Merge cf1b959d985a160d639dc54311654a5dfe0257c1 into 553741557a57df44a46fb3ab72b6aafeaf945337

This commit is contained in:
Tony Lin 2026-10-26 13:08:00 +00:00 committed by GitHub
commit 949218eb29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 116 additions and 1 deletions

View File

@ -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

View File

@ -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}"

View File

@ -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()

View File

@ -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

View File

@ -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