Checklist
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 return True.
- Stable Diffusion WebUI Setup: Clone and set up the Automatic1111 Stable Diffusion WebUI.
- Configure WebUI Launch: In your
webui-user.sh file, ensure COMMANDLINE_ARGS includes --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
sysinfo-2025-06-28-05-33.json
Console logs
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_pytorch module 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 to xpu_specific.has_xpu in modules/devices.py) relies on a try...except block attempting to import intel_extension_for_pytorch.
- Since
PyTorch 2.7.1+XPU integrates the functionality of intel_extension_for_pytorch directly, the standalone intel_extension_for_pytorch module is often not installed separately (and is not needed for torch.xpu.is_available() to be true).
- Consequently, the
import intel_extension_for_pytorch call fails within xpu_specific.py, causing the detection flag (has_ipex / xpu_specific.has_xpu) to remain False.
- This leads
modules/devices.py's get_optimal_device_name() function to incorrectly fall back to the CPU, despite the GPU being fully functional and available via torch.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.
Checklist
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-ipexcommand-line argument is explicitly provided inwebui-user.sh.Steps to reproduce the problem
python -c "import torch; print(torch.xpu.is_available());"within your PyTorch environment. This command should returnTrue.webui-user.shfile, ensureCOMMANDLINE_ARGSincludes--use-ipex. Example:export COMMANDLINE_ARGS="--use-ipex --precision full --no-half "../webui.sh.What should have happened?
When the
--use-ipexcommand-line argument is provided and a PyTorch build with native XPU support (likePyTorch 2.7.1+XPU) is correctly installed andtorch.xpu.is_available()returnsTrue, 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
sysinfo-2025-06-28-05-33.json
Console logs
Additional information
intel_extension_for_pytorchmodule unnecessary for functionality).Root Cause Analysis:
modules/xpu_specific.py.has_ipex variable, which translates toxpu_specific.has_xpuinmodules/devices.py) relies on atry...exceptblock attempting to importintel_extension_for_pytorch.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).import intel_extension_for_pytorchcall fails withinxpu_specific.py, causing the detection flag (has_ipex/xpu_specific.has_xpu) to remainFalse.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 inmodules/devices.pyfromreturn "cpu"toreturn "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.pyshould be modified to directly querytorch.xpu.is_available(). This would eliminate the dependency on the presence of the separateintel_extension_for_pytorchmodule for detection.Example modification within
xpu_specific.py: