Aloereed / stable-diffusion-webui-ipex-arc

A guide to Intel Arc-enabled (maybe) version of @AUTOMATIC1111/stable-diffusion-webui
GNU Affero General Public License v3.0
54 stars 8 forks source link

[Bug]: 按照 教程 中的方法无法顺利安装环境 #1

Closed Well2333 closed 1 year ago

Well2333 commented 1 year ago

Is there an existing issue for this?

What happened?

按照 教程 中的方法无法顺利安装环境

Steps to reproduce the problem

按照 教程 中的方法,进行到 设置 的第一步时,出现如下输出:

well@DESKTOP-Q9148KD:~/stable-diffusion-webui-ipex-arc$ bash webui.sh

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on well user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
ERROR: Cannot activate python venv, aborting...
################################################################

我查询 源码 后初步判断为环境初始化问题,也无法在对应目录下找到 activate 文件。(请不要在意多出来的文件,后面会有解释)

well@DESKTOP-Q9148KD:~/stable-diffusion-webui-ipex-arc/venv/bin$ ls
convert-caffe2-to-onnx  f2py   f2py3.10  normalizer  pip3     python   python3.10  wheel
convert-onnx-to-caffe2  f2py3  ipexrun   pip         pip3.10  python3  torchrun

然后,我为此虚拟环境的 python 安装了 pip 工具,但并未解决问题,依旧抛出上面的错误。

然后,我尝试按照 webui.sh 中的指令手动安装pytorch,但安装中发现这是cuda的版本,便手动中断安装了。

well@DESKTOP-Q9148KD:~/stable-diffusion-webui-ipex-arc$ ./venv/bin/python3.10 -m pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/rocm5.2
Collecting torch
  Using cached torch-2.0.0-cp310-cp310-manylinux1_x86_64.whl (619.9 MB)
Collecting torchvision
  Downloading torchvision-0.15.1-cp310-cp310-manylinux1_x86_64.whl (6.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.0/6.0 MB 1.3 MB/s eta 0:00:00
Collecting nvidia-cuda-cupti-cu11==11.7.101
  Downloading nvidia_cuda_cupti_cu11-11.7.101-py3-none-manylinux1_x86_64.whl (11.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.8/11.8 MB 1.8 MB/s eta 0:00:00
Collecting networkx
  Downloading https://download.pytorch.org/whl/networkx-3.0-py3-none-any.whl (2.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 1.7 MB/s eta 0:00:00
Collecting typing-extensions
  Downloading typing_extensions-4.5.0-py3-none-any.whl (27 kB)
Collecting nvidia-cuda-nvrtc-cu11==11.7.99
  Downloading nvidia_cuda_nvrtc_cu11-11.7.99-2-py3-none-manylinux1_x86_64.whl (21.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 21.0/21.0 MB 2.0 MB/s eta 0:00:00
Collecting nvidia-nvtx-cu11==11.7.91
  Using cached nvidia_nvtx_cu11-11.7.91-py3-none-manylinux1_x86_64.whl (98 kB)
Collecting nvidia-curand-cu11==10.2.10.91
  Using cached nvidia_curand_cu11-10.2.10.91-py3-none-manylinux1_x86_64.whl (54.6 MB)
Collecting nvidia-cublas-cu11==11.10.3.66
  Downloading nvidia_cublas_cu11-11.10.3.66-py3-none-manylinux1_x86_64.whl (317.1 MB)
     ━━━━━━━━━━━━━━━━━━━╸━━━━━━━━━━━━━━━━━━━━ 155.8/317.1 MB 3.9 MB/s eta 0:00:42
ERROR: Operation cancelled by user

然后,我尝试按照 arcnote 中排查是否是环境问题导致的错误,在 这里 发现这个仓库可能出现了问题。

well@DESKTOP-Q9148KD:~$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Hit:2 https://repositories.intel.com/graphics/ubuntu jammy InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Hit:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:6 https://apt.repos.intel.com/oneapi all InRelease
Fetched 229 kB in 5s (43.4 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
44 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: https://repositories.intel.com/graphics/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
W: Skipping acquire of configured file 'main/binary-amd64/Packages' as repository 'https://repositories.intel.com/graphics/ubuntu jammy InRelease' doesn't have the component 'main' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'main/i18n/Translation-en' as repository 'https://repositories.intel.com/graphics/ubuntu jammy InRelease' doesn't have the component 'main' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'main/cnf/Commands-amd64' as repository 'https://repositories.intel.com/graphics/ubuntu jammy InRelease' doesn't have the component 'main' (component misspelt in sources.list?)

并且,无法获取 level-zero 包

well@DESKTOP-Q9148KD:~$ sudo apt-get install intel-opencl-icd intel-level-zero-gpu level-zero intel-media-va-driver-non-free libmfx1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package level-zero

然后,在后续根据 此处 尝试手动安装python依赖的时候,发现以下包并不存在

ERROR: Could not find a version that satisfies the requirement torch==1.13.0a0 (from versions: 1.11.0, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 2.0.0)
ERROR: No matching distribution found for torch==1.13.0a0

ERROR: Could not find a version that satisfies the requirement intel_extension_for_pytorch==1.13.10+xpu (from versions: 1.11.0, 1.11.100, 1.11.200, 1.12.0, 1.12.100, 1.12.200, 1.12.300, 1.13.0, 1.13.100, 2.0.0)
ERROR: No matching distribution found for intel_extension_for_pytorch==1.13.10+xpu

我手动修改了torch==1.13.0intel_extension_for_pytorch==1.13.100,但出现了版本冲突问题

ERROR: Cannot install torch==1.13.0 and torchvision==0.14.1 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested torch==1.13.0
    torchvision 0.14.1 depends on torch==1.13.1

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

最终使用此命令成功安装 ./venv/bin/python3.10 -m pip install pillow mkl torch==1.13.1 torchvision==0.14.1 intel_extension_for_pytorch==1.13.100 -f https://developer.intel.com/ipex-whl- stable-xpu-idp

但最后,在尝试验证gpu是否可用的时候,出现以下结果

well@DESKTOP-Q9148KD:~/stable-diffusion-webui-ipex-arc$ ./venv/bin/python3.10
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import intel_extension_for_pytorch
>>> torch.xpu.is_available()
False
>>> exit()

截止到现在,我已经不知道改如何继续尝试debug了。

在上文中未作说明的部分,例如 教程 中设置往前的部分均未出现任何问题,与文中展示的完全一致,因此并未额外展示,如果有需要的信息我可以进行提供。

What should have happened?

None

Commit where the problem happens

main

What platforms do you use to access the UI ?

Windows

What browsers do you use to access the UI ?

Microsoft Edge

Command Line Arguments

None

List of extensions

None

Console logs

None

Additional information

宿主操作系统: Windows 10 22H2 WSL系统: Ubuntu-22.04 (wsl 2) python: 3.10.6(python-venv)

GPU: Arc A770 16G CPU: 5800x RAM: 16G DDR4 主板: MSI B550M MAG

OnXtheWays commented 1 year ago

ERROR: Cannot activate python venv, aborting...无法激活虚拟环境,只需要安装对应版本的venv就行,例如sudo apt-get install -y python3.10-venv

安装Intel的环境(oneApi)可以参考Intel官方。Download the Intel® oneAPI Base Toolkit,只需要安装oneAPI DPC++和 oneMKL。以下是我当时使用的代码。

sudo apt-get update
sudo apt-get install -y xdg-utils libatspi2.0-0 libgbm1 libgtk-3-0 libnotify4 libxcb-dri3-0 libnss3

sudo apt-get install -y gpg-agent wget
wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | \
  sudo gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg
echo 'deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc' | \
  sudo tee  /etc/apt/sources.list.d/intel.gpu.jammy.list

sudo apt-get install -y intel-opencl-icd intel-level-zero-gpu level-zero intel-media-va-driver-non-free libmfx1

wget https://registrationcenter-download.intel.com/akdlm/irc_nas/19079/l_BaseKit_p_2023.0.0.25537_offline.sh
sudo sh ./l_BaseKit_p_2023.0.0.25537_offline.sh

另外,每一次都要使用source /opt/intel/oneapi/setvars.sh激活oneAPI,有一些错误可能是因为没有激活环境。

如果出现ERROR: Cannot add middleware after an application has started,是因为fastapi的版本问题,进入虚拟环境安装对应版本就行。

source ./venv/bin/activate
pip install fastapi==0.90.1
deactivate

希望对你的ARC之旅有所帮助。

Well2333 commented 1 year ago

ERROR: Cannot activate python venv, aborting...无法激活虚拟环境,只需要安装对应版本的venv就行,例如sudo apt-get install -y python3.10-venv

安装Intel的环境(oneApi)可以参考Intel官方。Download the Intel® oneAPI Base Toolkit,只需要安装oneAPI DPC++和 oneMKL。以下是我当时使用的代码。

sudo apt-get update
sudo apt-get install -y xdg-utils libatspi2.0-0 libgbm1 libgtk-3-0 libnotify4 libxcb-dri3-0 libnss3

sudo apt-get install -y gpg-agent wget
wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | \
  sudo gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg
echo 'deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc' | \
  sudo tee  /etc/apt/sources.list.d/intel.gpu.jammy.list

sudo apt-get install -y intel-opencl-icd intel-level-zero-gpu level-zero intel-media-va-driver-non-free libmfx1

wget https://registrationcenter-download.intel.com/akdlm/irc_nas/19079/l_BaseKit_p_2023.0.0.25537_offline.sh
sudo sh ./l_BaseKit_p_2023.0.0.25537_offline.sh

另外,每一次都要使用source /opt/intel/oneapi/setvars.sh激活oneAPI,有一些错误可能是因为没有激活环境。

如果出现ERROR: Cannot add middleware after an application has started,是因为fastapi的版本问题,进入虚拟环境安装对应版本就行。

source ./venv/bin/activate
pip install fastapi==0.90.1
deactivate

希望对你的ARC之旅有所帮助。

上述的步骤我已经在提交issue之前就执行过了,但仍然出现了此结果。

sudo apt-get install -y python3.10-venv 命令安装之后,生成的虚拟环境并没有自带 activate 脚本。

另外,我确信 oneAPI 是激活状态,当时操作的终端我并没有关闭,查询记录能够发现是激活状态。

我把仍然留存的控制台记录全部放到了 pastebin 中,有效期是一个月,希望能够对发现问题有所帮助

Well2333 commented 1 year ago

今天我在尝试删除venv文件夹,并且把 python_cmd 由 python3 更换为 python3.10 之后,虚拟环境的问题便解决了,其中有两个值得注意的点:

  1. wsl 的 Ubuntu22.04 中默认 python3 的版本貌似为 python3.9,直接运行代码会导致venv的python为3.9版本,需要手动指定为python3.10
  2. 之前缺失的 activate 文件在此次正常生成了,这点我仍未能找到合理的解释

然后,其中 level-zero 包在更换了 @OnTheWayes 大佬提供的镜像之后便顺利安装上了,也可能是我之前使用的是apt安装但实际上应该使用apt-get安装导致的。

最后一点是,在issue后半部分尝试手动安装依赖部分的尝试可以被忽略掉了,因为这些版本确实是存在于对应的特殊镜像上的,使用 webui.sh 脚本可以顺利获取到这些资源。

现在我已经成功搭建起来了环境,但是因为内存不足还没办法进行图像生成的测试(RuntimeError: An OpenCL error occurred: -6),准备加钱买内存条去了(悲)

ytx222 commented 1 year ago

请问你是否切换了wsl内核到5.17,我尝试切换内核,但是一直失败,目前查到可以通过.wslconfig修改位置,但是我无法编译出内核文件...

Well2333 commented 1 year ago

请问你是否切换了wsl内核到5.17,我尝试切换内核,但是一直失败,目前查到可以通过.wslconfig修改位置,但是我无法编译出内核文件...

这个我不太清楚了,我在安装完毕环境之后因为 RuntimeError: An OpenCL error occurred: -6 导致依旧无法使用,加钱把内存拓展到32G之后还是会这样,现在我在使用 drictml 版本,先对来说比ipex版本简单很多。

我现在 wsl 的内核版本为 GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64

ytx222 commented 1 year ago

我也是5.15 我是同时参考了b站的一篇文章 https://www.bilibili.com/read/cv22030278 比起readme中的做法多了一些步骤,... 我同时也使用novelai中文频道的包(drictml),速度大概在1.4it/s(300600),512512的话大概是1.1it/s,同时还不能生成一些大的图片和使用除了euler以外的采样方式..., 或者是cpu计算,功能基本都能用,性能差了亿点点... 还是希望可以使用oneApi吧,听说性能可以达到6it/s,同时限制没有那么多,我再研究研究,有好消息了告诉你

ytx222 commented 1 year ago

https://www.reddit.com/r/IntelArc/comments/11an12q/stable_diffusion_web_ui_for_intel_arc/?sort=new 按照这个教程,可以很方便的安装成功,执行之前记得重置你的linux系统, @Well2333

Well2333 commented 1 year ago

https://www.reddit.com/r/IntelArc/comments/11an12q/stable_diffusion_web_ui_for_intel_arc/?sort=new 按照这个教程,可以很方便的安装成功,执行之前记得重置你的linux系统, @Well2333

感谢,我现在也可以在wsl中成功使用oneapi进行绘图了,相比directml效率确实高很多,而且显存占用更低,但相对内存占用更高了,可能总计16G的内存会OOM吧(没测试过

ytx222 commented 1 year ago

我在绘图过程中内存占用最高能达到16G左右(32G系统内存),而且据说会存在内存泄漏的问题,不过总的来说还是好用的,更多的细节可以看文章下面的问答

Well2333 commented 1 year ago

我在绘图过程中内存占用最高能达到16G左右(32G系统内存),而且据说会存在内存泄漏的问题,不过总的来说还是好用的,更多的细节可以看文章下面的问答

是的,我也遇到了一些匪夷所思的问题,例如生成这样的图片

00002-117624082

不过目前不清楚成因,再继续使用一段时间看看有无其他问题吧,如果实在有无法接受的问题,还是可以回到较为稳妥的directml方案。