stable-diffusion-webui
stable-diffusion-webui copied to clipboard
[Bug]: Intel Arc GPU (XPU) not detected with PyTorch builds integrating XPU support (e.g., 2.7.1+XPU)
Checklist
- [x] The issue exists after disabling all extensions
- [x] The issue exists on a clean installation of webui
- [ ] The issue is caused by an extension, but I believe it is caused by a bug in the webui
- [x] The issue exists in the current version of the webui
- [x] The issue has not been reported before recently
- [ ] The issue has been reported before but has not been fixed yet
What happened?
When attempting to run Stable Diffusion WebUI (Automatic1111) on a Linux system equipped with an Intel Arc A770 GPU and a PyTorch version that natively integrates XPU (Intel GPU) support (such as PyTorch 2.7.1+XPU), the WebUI consistently fails to detect and utilize the Intel Arc GPU. Instead, it defaults to performing image generation on the CPU, even when the --use-ipex command-line argument is explicitly provided in webui-user.sh.
Steps to reproduce the problem
- System Setup: Configure a Linux system with an Intel Arc A770 GPU.
- Driver Installation: Ensure the latest Intel GPU drivers for Linux are installed and correctly loaded (e.g., i915 kernel module, level-zero, firmware, etc.).
- PyTorch Installation: Install a PyTorch build with integrated XPU support (e.g., PyTorch 2.7.1+XPU). A relevant community guide for this setup can be found here.
- Verification: Confirm that PyTorch correctly recognizes the XPU by executing
python -c "import torch; print(torch.xpu.is_available());"within your PyTorch environment. This command should returnTrue.
- Stable Diffusion WebUI Setup: Clone and set up the Automatic1111 Stable Diffusion WebUI.
- Configure WebUI Launch: In your
webui-user.shfile, ensureCOMMANDLINE_ARGSincludes--use-ipex. Example:export COMMANDLINE_ARGS="--use-ipex --precision full --no-half ". - Launch WebUI: Start Stable Diffusion WebUI using
./webui.sh. - Observe Behavior: Initiate an image generation task. The WebUI will incorrectly utilize the CPU instead of the Intel Arc GPU (XPU).
What should have happened?
When the --use-ipex command-line argument is provided and a PyTorch build with native XPU support (like PyTorch 2.7.1+XPU) is correctly installed and torch.xpu.is_available() returns True, Stable Diffusion WebUI should correctly detect and automatically utilize the Intel Arc GPU (XPU) for accelerated image generation.
What browsers do you use to access the UI ?
Other
Sysinfo
not applicable but anyway
Console logs
not applicable
Additional information
- GPU Model: Intel Arc A770
- Operating System: Linux (tested on PikaOS; issue likely affects other Linux distributions as well)
- PyTorch Version: 2.7.1+XPU (XPU support is integrated into the core PyTorch package, making a separate
intel_extension_for_pytorchmodule unnecessary for functionality).
Root Cause Analysis:
- The problem lies in the XPU device detection logic within the Stable Diffusion WebUI, specifically in files like
modules/xpu_specific.py. - The relevant code snippet for XPU detection (
has_ipex variable, which translates toxpu_specific.has_xpuinmodules/devices.py) relies on atry...exceptblock attempting to importintel_extension_for_pytorch. - Since
PyTorch 2.7.1+XPUintegrates the functionality ofintel_extension_for_pytorchdirectly, the standaloneintel_extension_for_pytorchmodule is often not installed separately (and is not needed fortorch.xpu.is_available()to be true). - Consequently, the
import intel_extension_for_pytorchcall fails withinxpu_specific.py, causing the detection flag (has_ipex/xpu_specific.has_xpu) to remainFalse. - This leads
modules/devices.py'sget_optimal_device_name()function to incorrectly fall back to the CPU, despite the GPU being fully functional and available viatorch.xpu.
Temporary Workaround (User's Solution):
A temporary workaround that resolves the issue is to directly force the XPU backend by manually changing the last line within the def get_optimal_device_name(): function in modules/devices.py from return "cpu" to return "xpu". This bypasses the flawed detection logic, and the WebUI then successfully uses the Intel Arc GPU.
Proposed Clean Solution (for xpu_specific.py):
To provide a more robust and future-proof detection mechanism, the XPU availability check in xpu_specific.py should be modified to directly query torch.xpu.is_available(). This would eliminate the dependency on the presence of the separate intel_extension_for_pytorch module for detection.
Example modification within xpu_specific.py:
import torch
# ... other necessary imports ...
has_xpu_device_natively_available = False
try:
if hasattr(torch, 'xpu') and torch.xpu.is_available():
has_xpu_device_natively_available = True
except Exception:
# Log error if needed, but ensure has_xpu_device_natively_available remains False
pass
# This variable should be the one accessed by modules/devices.py
# If it was originally named 'has_ipex', retain that name for compatibility.
has_ipex = has_xpu_device_natively_available
# Ensure get_xpu_device_string() also uses torch.xpu methods directly if present.