在Intel Arc平台上运行Stable Diffusion Web UI的两种方案(文字版)
Aloereed
编辑于 2023年02月28日 13:49
收录于文集
共4篇

感谢 @kusoplayer 整理的文字版本!可以在红迪网IntelArc社区看到,原文名为Stable Diffusion Web UI for Intel Arc。(https://www.reddit.com/r/IntelArc/comments/11an12q/stable_diffusion_web_ui_for_intel_arc/)

以下为翻译版本

大家好各位网友! 经过几个月的社区努力,英特尔Arc终于拥有了自己的Stable Diffusion Web UI!目前有两个可用版本-一个依赖于DirectML,一个依赖于oneAPI,后者相对较快但仍处于初期阶段。

话不多说,让我们开始学习如何安装它们。


DirectML 实现(可在 Windows 环境下运行)

  1. 下载并安装 Python 3.10.6(https://www.python.org/downloads/release/python-3106/)

  2. 下载整个提交(https://github.com/Aloereed/stable-diffusion-webui-arc-directml)

  3. 在 ..\stable-diffusion-webui-arc-directml-master\repositories 下安装 k-diffusion-directml(https://github.com/lshqqytiger/k-diffusion-directml/tree/master) 和 stablediffusion-directml(https://github.com/lshqqytiger/stablediffusion-directml/tree/main),并将文件夹分别重命名为 k-diffusion 和 stable-diffusion-stability-ai(教程https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs)

  4. 在 ..\stable-diffusion-webui-arc-directml-master\models\Stable-diffusion 下安装您选择的 ckpt/safetensors(可选:vae/lora/embeddings),例如 counterfeit 或 chilloutmix

  5. 运行 webui-user.bat

  6. 享受吧!


oneAPI实现(只能在WSL2/Linux环境下运行,有些实验性质)

对于这个特定的安装指南,我将仅关注当前使用Windows 11的用户,但对于Windows 10用户来说应该并没有太大差别。环境设置有些麻烦。这个安装过程大约需要1~2个小时,所以请做好准备。虽然这个指南应该适用于任何不了解Linux的人,但试图让它正常工作可能会非常令人沮丧。

在进行之前,请确保BIOS中启用了CPU虚拟化(默认情况下应该已经启用)。如有疑问,请打开任务管理器进行检查。

同时,请确保您的Windows GPU驱动程序已经更新到最新版本。我目前使用的是4125 beta,但旧版本也应该可以正常工作。

对于那些从未使用过Linux CLI的人,这里是一个简要介绍。我保证你不需要知道更多。

代码块
JavaScript
自动换行
复制代码
命令 作用
cd .. 退出当前文件夹
cd ~ 进入 /home/{用户名}
cd - 返回上次访问的文件夹
cd {文件夹名称} 进入 {文件夹名称}
ls 列出当前目录中的所有项
pwd 显示当前路径
复制成功

1. 设置虚拟机

在 Windows 搜索栏中输入“Windows 功能”,选择“打开或关闭 Windows 功能”。

启用“虚拟机平台”和“适用于 Linux 的 Windows 子系统”,然后单击“确定”。

更新完成后,重新启动计算机

打开 PowerShell 并执行

代码块
Shell
自动换行
复制代码
 wsl --update
复制成功

从 Windows Store 下载 Ubuntu 22.04

启动 Ubuntu 22.04 并完成用户设置

2. 设置 systemd = true

按照此处(https://www.xda-developers.com/how-enable-systemd-in-wsl/)的指南。不需要安装 nextcloud。这个设置是为了执行 sudo reboot,这是一种杀死进程的可靠方法。

3. 为 WSL 启用 GUI 输出

只需按照这里(https://medium.com/@japheth.yates/the-complete-wsl2-gui-setup-2582828f4577)的指南即可。不需要安装 firefox。

4. 安装 Miniconda

按照此处(https://varhowto.com/install-miniconda-ubuntu-20-04/)的指南。或者您可以只按照下面的步骤执行。执行

代码块
Shell
自动换行
复制代码
cd ~
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh
复制成功

理想情况下,您应该将 Miniconda 安装在 /home/{用户名}/miniconda3 下

完成后,执行 sudo reboot。然后再次打开 Ubuntu。执行 conda。如果有提示,表示您已正确安装 miniconda。

5. 安装运行时软件包

只需按照此处(https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-jammy-arc.html)安装指南的步骤 1 ~ 4 即可。

您可能会看到安装失败并出现“未满足的依赖关系”警告,这表示缺少其他必要的软件包。要安装缺少的软件包,请执行 sudo apt-get install {软件包名称}。话虽如此,您总是可以回来安装它们,或者如果您已经可以Stable Diffusion,则可以将它们留下来。

6. 在Ubuntu中安装Intel oneAPI基础工具包

按照Intel的指南(https://intel.github.io/intel-extension-for-pytorch/xpu/latest/tutorials/installation.html)进行安装,或者如果过于繁琐,只需参考下面的步骤。

执行以下命令:

代码块
Shell
自动换行
复制代码
cd ~
wget https://registrationcenter-download.intel.com/akdlm/irc_nas/19079/l_BaseKit_p_2023.0.0.25537.sh
sudo sh ./l_BaseKit_p_2023.0.0.25537.sh
复制成功

会弹出一个图形化界面,您只需要按照指示安装“oneAPI DPC++编译器”和“Intel® oneAPI数学核心库”。如果您不想麻烦,完全安装也没问题。

为了在每次启动Ubuntu时自动初始化oneAPI环境,执行nano ~/.bashrc并将以下命令粘贴到文档底部。它们应该在不同的行中。

代码块
Shell
自动换行
复制代码
source /opt/intel/oneapi/setvars.sh
复制成功

执行sudo reboot,然后重新启动Ubuntu,您应该会看到oneAPI环境被自动初始化。使用命令sycl-ls验证GPU的可见性,它应该显示类似以下的内容。

代码块
Shell
自动换行
复制代码
[opencl:acc:0] Intel(R) FPGA Emulation Platform for OpenCL(TM), Intel(R) FPGA Emulation Device 1.2 [2022.15.12.0.01_081451]

[opencl:cpu:1] Intel(R) OpenCL, AMD Ryzen 7 5700X 8-Core Processor 3.0 [2022.15.12.0.01_081451]

[opencl:gpu:2] Intel(R) OpenCL HD Graphics, Intel(R) Graphics [0x56a0] 3.0 [22.49.25018.23]

[ext_oneapi_level_zero:gpu:0] Intel(R) Level-Zero, Intel(R) Graphics [0x56a0] 1.3 [1.3.25018] <<<  *** 如果您看到这个,则已成功执行上述步骤。否则,请尝试再次安装包(在第5步中) ***
复制成功

7. 安装并配置oneAPI Stable Diffusion Web UI

  • 执行以下命令:

代码块
Shell
自动换行
复制代码
cd ~
wget https://raw.githubusercontent.com/Aloereed/stable-diffusion-webui-ipex-arc/main/webui.sh
git clone https://github.com/Aloereed/stable-diffusion-webui-ipex-arc.git
source webui.sh
复制成功

一旦开始下载pytorch,请退出Ubuntu。

转到~/stable-diffusion-webui-ipex-arc/launch.py,用

代码块
Shell
自动换行
复制代码
pip install pillow mkl torch==1.13.0a0 torchvision==0.14.1a0 intel_extension_for_pytorch==1.13.10+xpu -f https://developer.intel.com/ipex-whl-stable-xpu
复制成功

替换

代码块
Shell
自动换行
复制代码
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
复制成功
  • 您可以从Windows文件资源管理器的左侧导航到VM文件。

  • 在Windows中下载所需的checkpoint / safetensors,然后将它们拖到/home/{user}/stable-diffusion-webui/models/Stable-diffusion。

  • 复制~/stable-diffusion-webui-ipex-arc/下的所有文件,覆盖~/stable-diffusion-webui/中的所有文件。

  • 执行source ~/stable-diffusion-webui/webui.sh --skip-torch-cuda-test --disable-nan-check。很可能会告诉您无法找到Intel Extension for Pytorch并自动退出。如果遇到此问题,请按照下一部分的说明操作。

8. (可能需要)回滚运行时包

执行以下命令:

代码块
Shell
自动换行
复制代码
mkdir neo
cd neo
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.12504.5/intel-igc-core_1.0.12504.5_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.12504.5/intel-igc-opencl_1.0.12504.5_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/22.43.24595.30/intel-level-zero-gpu-dbgsym_1.3.24595.30_amd64.ddeb
wget https://github.com/intel/compute-runtime/releases/download/22.43.24595.30/intel-level-zero-gpu_1.3.24595.30_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/22.43.24595.30/intel-opencl-icd-dbgsym_22.43.24595.30_amd64.ddeb
wget https://github.com/intel/compute-runtime/releases/download/22.43.24595.30/intel-opencl-icd_22.43.24595.30_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/22.43.24595.30/libigdgmm12_22.3.0_amd64.deb
sudo dpkg -i *
cd ..
复制成功

然后执行命令:source ~/stable-diffusion-webui/webui.sh --skip-torch-cuda-test --disable-nan-check。有可能会提示“中间件”出现问题并退出。如果出现这种情况,请继续进行下一步操作。

9. (可能需要)修复中间件

进入 ~/stable-diffusion-webui/webui.py 文件,并在 "app.add_middleware(GZipMiddleware, minimum_size=1000)" 之前添加一个井号(#​)注释掉该行代码。

需要注意的是,这不是一个实际的修复,而是一个解决方法。这个问题已知是由 fastapi 版本引起的,但将其更改为正确的版本将导致其他问题。如果您有更好的解决方法,请随时告诉我。

要获得正确的fastapi版本,只需在其他地方下载旧版本并覆盖到虚拟环境中。执行

代码块
Shell
自动换行
复制代码
pip install --upgrade fastapi==0.90.1
yes | cp -rf ~/miniconda3/lib/python3.10/site-packages/{fastapi,starlette} ~/stable-diffusion-webui/venv/lib/python3.10/site-packages
复制成功

执行 source ~/stable-diffusion-webui/webui.sh --skip-torch-cuda-test --disable-nan-check。最后,您应该能够启动 Web UI。

10. 现在是时候创造一些 AI 艺术了!


特别感谢:

Aloereed,本次提交的创建者;

neggles,AUTOMATIC1111以及其他许多人,本次提交所基于的工作;

(你),为使显卡市场更加多元化所作出的贡献。

以下是我在A770 LE上生成并放大的Intel主题动漫女孩图片,大约需要3分钟的时间:(见头图。https://imgur.com/a/d8m90DI)