Repository: pytorch
Issue: XPU - UserWarning: Failed to initialize XPU devices. when run on Machine without without Intel GPU Driver
Labels: triaged,module: xpu

### 🐛 Describe the bug

Based on following issue: https://github.com/pytorch/pytorch/issues/145290#issuecomment-2606374858

Test on Linux x86 without Intel Driver installed:

```
 pip install --pre torch --index-url https://download.pytorch.org/whl/test/xpu
Looking in indexes: https://download.pytorch.org/whl/test/xpu
Collecting torch
  Obtaining dependency information for torch from https://download.pytorch.org/whl/test/xpu/torch-2.6.0%2Bxpu-cp310-cp310-linux_x86_64.whl.metadata
  Downloading https://download.pytorch.org/whl/test/xpu/torch-2.6.0%2Bxpu-cp310-cp310-linux_x86_64.whl.metadata (27 kB)
Collecting jinja2
  Downloading https://download.pytorch.org/whl/test/Jinja2-3.1.4-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.3/133.3 kB 28.6 MB/s eta 0:00:00
Collecting typing-extensions>=4.10.0
  Downloading https://download.pytorch.org/whl/test/typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Collecting networkx
  Downloading https://download.pytorch.org/whl/test/networkx-3.3-py3-none-any.whl (1.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 114.9 MB/s eta 0:00:00
Collecting intel-cmplr-lib-rt==2025.0.2
  Downloading https://download.pytorch.org/whl/test/xpu/intel_cmplr_lib_rt-2025.0.2-py2.py3-none-manylinux_2_28_x86_64.whl (45.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 45.9/45.9 MB 57.1 MB/s eta 0:00:00
Collecting tcmlib==1.2.0
  Downloading https://download.pytorch.org/whl/test/xpu/tcmlib-1.2.0-py2.py3-none-manylinux_2_28_x86_64.whl (4.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.2/4.2 MB 117.4 MB/s eta 0:00:00
Collecting pytorch-triton-xpu==3.2.0
  Obtaining dependency information for pytorch-triton-xpu==3.2.0 from https://download.pytorch.org/whl/test/pytorch_triton_xpu-3.2.0-cp310-cp310-linux_x86_64.whl.metadata
  Downloading https://download.pytorch.org/whl/test/pytorch_triton_xpu-3.2.0-cp310-cp310-linux_x86_64.whl.metadata (1.3 kB)
Collecting sympy==1.13.1
  Downloading https://download.pytorch.org/whl/test/sympy-1.13.1-py3-none-any.whl (6.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.2/6.2 MB 134.6 MB/s eta 0:00:00
Collecting fsspec
  Downloading https://download.pytorch.org/whl/test/fsspec-2024.6.1-py3-none-any.whl (177 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 177.6/177.6 kB 47.3 MB/s eta 0:00:00
Collecting filelock
  Downloading https://download.pytorch.org/whl/test/filelock-3.13.1-py3-none-any.whl (11 kB)
Collecting intel-cmplr-lib-ur==2025.0.2
  Downloading https://download.pytorch.org/whl/test/xpu/intel_cmplr_lib_ur-2025.0.2-py2.py3-none-manylinux_2_28_x86_64.whl (25.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 25.1/25.1 MB 88.2 MB/s eta 0:00:00
Collecting umf==0.9.1
  Downloading https://download.pytorch.org/whl/test/xpu/umf-0.9.1-py2.py3-none-manylinux_2_28_x86_64.whl (161 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 161.6/161.6 kB 43.3 MB/s eta 0:00:00
Collecting intel-pti==0.10.0
  Downloading https://download.pytorch.org/whl/test/xpu/intel_pti-0.10.0-py2.py3-none-manylinux_2_28_x86_64.whl (651 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 651.8/651.8 kB 104.1 MB/s eta 0:00:00
Collecting intel-cmplr-lic-rt==2025.0.2
  Downloading https://download.pytorch.org/whl/test/xpu/intel_cmplr_lic_rt-2025.0.2-py2.py3-none-manylinux_2_28_x86_64.whl (18 kB)
Collecting intel-sycl-rt==2025.0.2
  Downloading https://download.pytorch.org/whl/test/xpu/intel_sycl_rt-2025.0.2-py2.py3-none-manylinux_2_28_x86_64.whl (12.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.4/12.4 MB 135.9 MB/s eta 0:00:00
Collecting packaging
  Downloading https://download.pytorch.org/whl/test/packaging-22.0-py3-none-any.whl (42 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.6/42.6 kB 14.9 MB/s eta 0:00:00
Collecting mpmath<1.4,>=1.1.0
  Downloading https://download.pytorch.org/whl/test/mpmath-1.3.0-py3-none-any.whl (536 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 536.2/536.2 kB 47.2 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
  Downloading https://download.pytorch.org/whl/test/MarkupSafe-2.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Downloading https://download.pytorch.org/whl/test/xpu/torch-2.6.0%2Bxpu-cp310-cp310-linux_x86_64.whl (1029.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 GB 694.9 kB/s eta 0:00:00
Downloading https://download.pytorch.org/whl/test/pytorch_triton_xpu-3.2.0-cp310-cp310-linux_x86_64.whl (348.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 348.4/348.4 MB 3.0 MB/s eta 0:00:00
Using cached https://download.pytorch.org/whl/test/xpu/torch-2.6.0%2Bxpu-cp310-cp310-linux_x86_64.whl (1029.5 MB)
Using cached https://download.pytorch.org/whl/test/pytorch_triton_xpu-3.2.0-cp310-cp310-linux_x86_64.whl (348.4 MB)
Installing collected packages: tcmlib, mpmath, intel-pti, intel-cmplr-lic-rt, intel-cmplr-lib-rt, umf, typing-extensions, sympy, packaging, networkx, MarkupSafe, fsspec, filelock, pytorch-triton-xpu, jinja2, intel-cmplr-lib-ur, intel-sycl-rt, torch
Successfully installed MarkupSafe-2.1.5 filelock-3.13.1 fsspec-2024.6.1 intel-cmplr-lib-rt-2025.0.2 intel-cmplr-lib-ur-2025.0.2 intel-cmplr-lic-rt-2025.0.2 intel-pti-0.10.0 intel-sycl-rt-2025.0.2 jinja2-3.1.4 mpmath-1.3.0 networkx-3.3 packaging-22.0 pytorch-triton-xpu-3.2.0 sympy-1.13.1 tcmlib-1.2.0 torch-2.6.0+xpu typing-extensions-4.12.2 umf-0.9.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
root@b90276700e5d:/# python
Python 3.10.16 (main, Jan 14 2025, 05:29:27) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
/usr/local/lib/python3.10/site-packages/torch/_subclasses/functional_tensor.py:275: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:81.)
  cpu = _conversion_method_template(device=torch.device("cpu"))
>>> torch.__version__
'2.6.0+xpu'
>>> exit()
root@b90276700e5d:/# git clone https://github.com/pytorch/pytorch.git
Cloning into 'pytorch'...
remote: Enumerating objects: 1047258, done.
remote: Counting objects: 100% (959/959), done.
remote: Compressing objects: 100% (445/445), done.
remote: Total 1047258 (delta 717), reused 565 (delta 514), pack-reused 1046299 (from 3)
Receiving objects: 100% (1047258/1047258), 955.33 MiB | 47.36 MiB/s, done.
Resolving deltas: 100% (838919/838919), done.
Updating files: 100% (17938/17938), done.
root@b90276700e5d:/# cd pytorch/.ci/pytorch/
root@b90276700e5d:/pytorch/.ci/pytorch# cd smoke_test/
root@b90276700e5d:/pytorch/.ci/pytorch/smoke_test# pip install numpy
Collecting numpy
  Downloading numpy-2.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.4/16.4 MB 103.5 MB/s eta 0:00:00
Installing collected packages: numpy
Successfully installed numpy-2.2.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 23.0.1 -> 24.3.1
[notice] To update, run: pip install --upgrade pip
root@b90276700e5d:/pytorch/.ci/pytorch/smoke_test# python smoke_test.py --package torchonly
torch: 2.6.0+xpu
ATen/Parallel:
	at::get_num_threads() : 4
	at::get_num_interop_threads() : 4
OpenMP 201511 (a.k.a. OpenMP 4.5)
	omp_get_max_threads() : 4
Intel(R) oneAPI Math Kernel Library Version 2025.0.1-Product Build 20241031 for Intel(R) 64 architecture applications
	mkl_get_max_threads() : 4
Intel(R) MKL-DNN v3.5.3 (Git Hash 66f0cb9eb66affd2da3bf5f8d897376f04aae6af)
std::thread::hardware_concurrency() : 8
Environment variables:
	OMP_NUM_THREADS : [not set]
	MKL_NUM_THREADS : [not set]
ATen parallel backend: OpenMP

Skip version check for channel None as stable version is None
Testing smoke_test_conv2d
Testing smoke_test_linalg on cpu
Testing smoke_test_compile for cpu and torch.float16
/usr/local/lib/python3.10/site-packages/torch/xpu/__init__.py:60: UserWarning: Failed to initialize XPU devices. The driver may not be installed, installed incorrectly, or incompatible with the current setup. Please refer to the guideline (https://github.com/pytorch/pytorch?tab=readme-ov-file#intel-gpu-support) for proper installation and configuration. (Triggered internally at /pytorch/c10/xpu/XPUFunctions.cpp:54.)
  return torch._C._xpu_getDeviceCount()
/usr/local/lib/python3.10/site-packages/torch/xpu/__init__.py:60: UserWarning: Failed to initialize XPU devices. The driver may not be installed, installed incorrectly, or incompatible with the current setup. Please refer to the guideline (https://github.com/pytorch/pytorch?tab=readme-ov-file#intel-gpu-support) for proper installation and configuration. (Triggered internally at /pytorch/c10/xpu/XPUFunctions.cpp:54.)
  return torch._C._xpu_getDeviceCount()
Testing smoke_test_compile for cpu and torch.float32
Testing smoke_test_compile for cpu and torch.float64
Picked CPU ISA VecAVX512 bit width 512
Testing smoke_test_compile with mode 'max-autotune' for torch.float32
```


Creates following warning when testing torch.compile:
```
Testing smoke_test_compile for cpu and torch.float16
/usr/local/lib/python3.10/site-packages/torch/xpu/__init__.py:60: UserWarning: Failed to initialize XPU devices. The driver may not be installed, installed incorrectly, or incompatible with the current setup. Please refer to the guideline (https://github.com/pytorch/pytorch?tab=readme-ov-file#intel-gpu-support) for proper installation and configuration. (Triggered internally at /pytorch/c10/xpu/XPUFunctions.cpp:54.)
```

Instead of Generating warning every time we could perhaps Display it once during torch import and during torch compile call fallback on cpu ?

### Versions

2.6.0 and 2.7.0

cc @gujinghui @EikanWang @fengyuan14 @guangyey