[Feature Request] Add Intel XPU Device Support
Describe the feature Add Intel XPU support to ModelScope device utilities. Users should be able to specify xpu and xpu: devices for PyTorch models, device creation, and device placement.
Motivation Intel XPU is available and supported by PyTorch, but the current ModelScope implementation only recognizes CPU and CUDA/GPU devices. As a result, ModelScope rejects xpu device strings or falls back to CPU even when an Intel XPU is available.
For example, in an Intel XPU environment:
torch: 2.12.0+xpu
torch.xpu.is_available(): True
torch.xpu.device_count(): 1PyTorch can successfully execute:
import torch
torch.ones(2, device="xpu")However, the original ModelScope implementation fails for:
from modelscope.utils.device import verify_device, create_device
verify_device("xpu")
create_device("xpu")
verify_device("xpu:0")
create_device("xpu:0")with:
AssertionError: device should be either cpu, cuda, gpu, gpu:X or cuda:X where X is the ordinal for gpu device.
Using create_device("gpu") also falls back to CPU because it checks torch.cuda.is_available() instead of Intel XPU availability.
Related resources
- PyTorch Intel GPU/XPU documentation: https://pytorch.org/docs/stable/notes/get_start_xpu.html
- PyTorch XPU package documentation: https://pytorch.org/docs/stable/xpu.html
- Proposed implementation: PR #1764
Additional context The existing ModelScope device tests pass because they currently cover CPU and CUDA/GPU behavior but do not cover XPU:
This feature should include tests for:
- verify_device("xpu")
- verify_device("xpu:0")
- create_device("xpu")
- create_device("xpu:0")
- XPU device placement
- CPU fallback when XPU is unavailable
I would like to implement this feature, and the proposed changes are available in PR #1764.
Source: modelscope/modelscope