stable-diffusion-webui icon indicating copy to clipboard operation
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)

Open DrThodt2021 opened this issue 5 months ago • 10 comments

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

  1. System Setup: Configure a Linux system with an Intel Arc A770 GPU.
  2. Driver Installation: Ensure the latest Intel GPU drivers for Linux are installed and correctly loaded (e.g., i915 kernel module, level-zero, firmware, etc.).
  3. 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.
  1. Stable Diffusion WebUI Setup: Clone and set up the Automatic1111 Stable Diffusion WebUI.
  2. 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 ".
  3. Launch WebUI: Start Stable Diffusion WebUI using ./webui.sh.
  4. 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

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_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.

DrThodt2021 avatar Jun 28 '25 05:06 DrThodt2021