Skip to content

feat: Add Intel Arc GPU (XPU) support / 添加 Intel Arc GPU (XPU) 支持 - #9423

Open
wesd6r wants to merge 5 commits into
invoke-ai:mainfrom
wesd6r:intel-gpu-support
Open

feat: Add Intel Arc GPU (XPU) support / 添加 Intel Arc GPU (XPU) 支持#9423
wesd6r wants to merge 5 commits into
invoke-ai:mainfrom
wesd6r:intel-gpu-support

Conversation

@wesd6r

@wesd6r wesd6r commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary / 概述

This PR adds Intel Arc GPU (XPU/iGPU) support to InvokeAI, enabling image generation on Intel discrete and integrated GPUs via Intel Extension for PyTorch (IPEX).

本 PR 为 InvokeAI 添加 Intel Arc GPU(XPU/集显)支持,通过 Intel Extension for PyTorch (IPEX) 实现在 Intel 独立和集成显卡上生成图像。

Based on the community effort by ilmarille-prog/InvokeAI_intelGPU, ported and updated to the latest InvokeAI codebase.

基于 ilmarille-prog/InvokeAI_intelGPU 的社区工作,移植并更新到最新 InvokeAI 代码库。

Motivation / 动机

InvokeAI currently supports CUDA (NVIDIA) and MPS (Apple Silicon) GPUs but has no path for Intel GPU users. Intel Arc GPUs (A-series, Pro B-series, and newer integrated Arc graphics) expose a PyTorch backend via torch.xpu through IPEX. This PR integrates XPU support with minimal, non-invasive changes so that Intel GPU users can run InvokeAI without maintaining a separate fork.

InvokeAI 目前支持 CUDA(NVIDIA)和 MPS(Apple Silicon)GPU,但没有 Intel GPU 用户的使用路径。Intel Arc GPU(A 系列、Pro B 系列及更新的集成 Arc 显卡)通过 IPEX 提供 torch.xpu 后端。本 PR 以最小化、非侵入的方式集成 XPU 支持,使 Intel GPU 用户无需维护单独的分支即可运行 InvokeAI。

Changes / 改动

Core device abstraction / 核心设备抽象 (devices.py)

  • Added _is_xpu_available() helper (guarded with hasattr for safety on non-IPEX systems)
    • 添加 _is_xpu_available() 辅助函数(通过 hasattr 保护,确保无 IPEX 时安全运行)
  • choose_torch_device() auto-selects xpu when available and CUDA is not
    • choose_torch_device() 在 XPU 可用且 CUDA 不可用时自动选择 xpu
  • choose_torch_dtype() defaults XPU to float16
    • choose_torch_dtype() XPU 默认使用 float16
  • empty_cache() includes torch.xpu.empty_cache()
    • empty_cache() 包含 torch.xpu.empty_cache()

Configuration / 配置 (config_default.py)

  • Added xpu to the valid device pattern: ^(auto|cpu|mps|cuda|xpu)(:\d+)?$
    • xpu 添加到有效设备模式:^(auto|cpu|mps|cuda|xpu)(:\d+)?$

Attention & pipeline / 注意力与推理管线 (diffusers_pipeline.py, attention.py)

  • Explicitly disables xformers for XPU (incompatible) and falls back to torch-sdp or sliced attention
    • 为 XPU 显式禁用 xformers(不兼容),回退到 torch-sdpsliced 注意力
  • XPU uses system RAM for slice size estimation (same as CPU/MPS path)
    • XPU 使用系统内存进行切片大小估算(同 CPU/MPS 路径)

Model cache / 模型缓存 (model_cache.py)

  • Uses torch.xpu.mem_get_info() and torch.xpu.memory_allocated() for XPU VRAM tracking
    • 使用 torch.xpu.mem_get_info()torch.xpu.memory_allocated() 进行 XPU 显存追踪

xformers compatibility / xformers 兼容性 (hotfixes.py)

  • Patches diffusers to return False for is_xformers_available on XPU devices
    • 修补 diffusers 使其在 XPU 设备上返回 False,防止加载不兼容的 xformers

Image utilities / 图像工具

  • depth_anything, grounding_dino, segment_anything, segment_anything_2, pbr_maps: Allow xpu as valid device
    • 以上工具管线:允许 xpu 作为有效设备
  • dw_openpose: Added comment noting ONNX Runtime XPU limitation (falls back to CPU)
    • dw_openpose:添加注释说明 ONNX Runtime XPU 限制(回退到 CPU)

Documentation / 文档

  • INSTALL_INTEL.md: Step-by-step Windows installation guide for Intel GPU users
    • INSTALL_INTEL.md:Intel GPU 用户的 Windows 分步安装指南

Design principles / 设计原则

  1. Minimal invasiveness / 最小侵入: All changes are additive — no existing CUDA/MPS/CPU paths are modified.
    所有改动都是新增的——不修改现有的 CUDA/MPS/CPU 路径。
  2. Safety guards / 安全保护: Every torch.xpu call is wrapped in hasattr(torch, "xpu") checks so the code runs safely on systems without IPEX.
    每个 torch.xpu 调用都用 hasattr(torch, "xpu") 检查包裹,确保在没有 IPEX 的系统上安全运行。
  3. No new dependencies / 无新依赖: IPEX is an optional install-time dependency; the codebase itself only references torch.xpu APIs which gracefully no-op when absent.
    IPEX 是可选的安装时依赖;代码本身只引用 torch.xpu API,缺失时自动跳过。

Testing / 测试

  • Tested on Windows 11 with Intel Arc Pro B50 GPU / 在 Windows 11 + Intel Arc Pro B50 GPU 上测试
  • Verified: auto device detection, model loading, image generation, memory management, cache eviction
    • 已验证:自动设备检测、模型加载、图像生成、显存管理、缓存回收
  • All torch.xpu API calls are guarded for non-IPEX environments
    • 所有 torch.xpu API 调用均已针对非 IPEX 环境做了保护

Related / 相关项目

@github-actions github-actions Bot added python PRs that change python files Root backend PRs that change backend files services PRs that change app services invocations PRs that change invocations labels Jul 31, 2026
@wesd6r
wesd6r force-pushed the intel-gpu-support branch from d921a46 to 820f7b7 Compare August 2, 2026 01:12
@github-actions github-actions Bot added the frontend PRs that change frontend files label Aug 2, 2026
- devices.py: XPU device detection, choose_torch_device, bfloat16 default
- config_default.py: device field accepts xpu/xpu:N patterns
- run_app.py: guard CUDA memory allocator for non-CUDA devices
- attention.py + diffusers_pipeline.py: XPU VRAM detection
- hotfixes.py: disable xformers on XPU devices
- model_cache.py: XPU memory tracking + OOM handling
- invocation_stats + memory_snapshot: XPU VRAM reporting
- pid/*: device-agnostic inference (autocast, .to(device))
- bnb_llm_int8.py + bnb_nf4.py: XPU quantization guards
- ggml_tensor.py: XPU dispatch table
- pidi/model.py: device-agnostic FloatTensor
- anima_latents_to_image.py: XPU OOM detection + tiled decode
- textual_inversion.py: .to() short-circuit fix
- zh-CN.json: Simplified Chinese translations
- scripts/patch_xpu.py: upstream-aware XPU patching tool
- scripts/sync_and_patch.py: automated upstream sync + patching

Tested on Intel Arc A730M with torch 2.13.0+xpu, IPEX 2.10.0
@wesd6r
wesd6r force-pushed the intel-gpu-support branch from 486ae5b to 94fb26b Compare August 3, 2026 13:14
@github-actions github-actions Bot added the api label Aug 3, 2026
wesd6r added 4 commits August 3, 2026 21:58
- 8d (_get_vram_in_use): match from elif mps onwards (upstream has long
  comment block between 'if cuda:' and 'return' that broke the old pattern)
- 8f (_log_cache_state): match the upstream ternary pattern
  'allocated = (... if cuda else 0)' instead of the removed direct call
- Both fixes verified against origin/main upstream code
- Add fork-specific title, description, and badges
- Add Quick Start guide for Intel Arc GPU installation
- Add complete list of 31 patched files
- Add sync_and_patch.py workflow documentation
- Add known limitations section
- Keep original InvokeAI content at bottom
- Update badge URLs to point to wesd6r/InvokeAI
- README.md: restore English version + add language switch link
- README-zh_CN.md: complete Chinese translation with accurate patch data
  - 54 patches / 28 files documented with detailed categories
  - Test status table with actual A730M benchmark results
  - Full upstream InvokeAI content preserved
- Updated from origin/main (Weblate PR invoke-ai#9445, 2026-08-02)
- New section: systemPrompts (17 keys)
- Expanded: parameters (+18), popovers (+14), toast (+14), gallery (+9), modelManager (+8)
- Total: 2914 translation keys across 35 sections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api backend PRs that change backend files frontend PRs that change frontend files invocations PRs that change invocations python PRs that change python files Root services PRs that change app services

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant