mirror of
https://github.com/deepseek-ai/DeepInfer.git
synced 2026-10-31 00:36:20 +08:00
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
"""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
|