amd显卡在wsl环境下配置stable-diffusion-webui

环境为 wsl2 + openEule-22.09,显卡为农企的rx5700
只能说能用~
安装git、python软件包
sudo dnf install -y git python
下载stable-diffusion-webui到本地
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && cd ./stable-diffusion-webui
安装Miniconda
下载Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
使用Miniconda
bash Miniconda3-latest-Linux-x86_64.sh
初始化完毕后输入conda -V 查看是否成功安装,若提示命令不存在,可执行 source ~/.bashrc 刷新当前环境变量
配置stable-diffusion-webui环境
创建stable-diffusion-webui环境
conda create -n stable-diffusion-webui python=3.10
进入stable-diffusion-webui环境
conda activate stable-diffusion-webui
配置pip包管理器的源地址
vi ~/.config/pip/pip.conf
添加以下内容
[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host = mirrors.aliyun.com
安装环境依赖
conda install numpy==1.23.5 conda install pytorch=1.13.1 cpuonly -c pytorch pip install torch-directml==0.1.13.1dev230301 gfpgan clip pip install -r requirements.txt
可能会遇到提示pip版本过低,可执行pip install --upgrade pip升级
修改部分代码,使其支持directml
找到 ./modules/devices.py 里的
def has_maps() -> bool:
,在上面添加如下代码def has_dml() -> bool:
return True
同样是 ./modules/devices.py 里的
def get_optimal_device_name()
,在代码内部的if has_maps():
上面添加if has_dml(): return "dml"
同样是 ./modules/devices.py 里的
def get_optimal_device_name()
,在代码内部添加if get_optimal_device_name() == "dml": import torch_directml return torch_directml.device()
找到 ./modules/sd_models.py 里的
device = map_location or shared.weight_load_location or devices.get_optimal_device_name()
,修改为device = map_location or shared.weight_load_location or devices.get_optimal_device()
开启stable-diffusion-webui应用服务
python .\launch.py --skip-torch-cuda-test --lowvram --precision full --no-half
首次运行可能还需要安装部分依赖,请静候
在部署中遇到的一些错误
代码缩进不要用空格
安装环境依赖要在
conda activate stable-diffusion-webui
之后报libGL.so.1缺失,执行
pip install opencv-python-headless
部分内容参考自
