搭建stable diffusion的kohya_ss_GUI环境

前言

上个教程跟大家说了如何在stable diffusion webui中部署lora,并且使用别人训练好的模型根据提示词生成图片。那么如何自己生成自己喜欢的二次元图片呢?比如我小时候比较喜欢看七龙珠,在模型网站上又找不到自己预期的那种模型,那我想生成帅气的悟空图片要怎么做呢?
下面告诉大家如何使用kohya_ss-GUI生成LoRA模型。

什么是kohya_ss_GUI

kohya_ss_GUI可以让你在网页界面上可视化调参数去训练你自己的模型,操作会很方便。

安装kohya_ss_GUI环境

首先你得保证你已经有的对应的python环境,版本跟 stable diffusion webui 要求的版本一样。

修改setup.bat脚本安装

这里使用腾讯云的pip源,会让往后的pip install快很多

pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
pip config set global.trusted-host mirrors.cloud.tencent.com
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss

Test

可以看到他正在下载torch,文件很大,你也可以一直等,但是我实在忍不了,那这里提供一个奇技淫巧。
思路是用迅雷手动根据链接下载文件,然后根据下载的文件安装
下载地址是 torch-1.12.1+cu116-cp310-cp310-win_amd64.whl
Test
这速度根本不是一个档次的好吧。
下载完之后把文件放在kohya_ss根目录。

还有两个文件也是一样的道理,是从外网下载的,很慢,所以我们也是用迅雷下载好放到根目录
torchvision-0.13.1+cu116-cp310-cp310-win_amd64.whl
xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl

如果你不想使用迅雷下载,这里提供 百度网盘

我们修改setup.bat,把这3个文件都用本地的方式去安装

这是原来的setup.bat

@echo off

set PYTHON_VER=3.10.9

REM Check if Python version meets the recommended version
python --version 2>nul | findstr /b /c:"Python %PYTHON_VER%" >nul
if errorlevel 1 (
    echo Warning: Python version %PYTHON_VER% is recommended.
)

IF NOT EXIST venv (
    python -m venv venv
) ELSE (
    echo venv folder already exists, skipping creation...
)
call .\venv\Scripts\activate.bat

pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install --use-pep517 --upgrade -r requirements.txt
pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl

copy /y .\bitsandbytes_windows\*.dll .\venv\Lib\site-packages\bitsandbytes\
copy /y .\bitsandbytes_windows\cextension.py .\venv\Lib\site-packages\bitsandbytes\cextension.py
copy /y .\bitsandbytes_windows\main.py .\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.py

accelerate config

这是修改之后的

@echo off

set PYTHON_VER=3.10.9

REM Check if Python version meets the recommended version
python --version 2>nul | findstr /b /c:"Python %PYTHON_VER%" >nul
if errorlevel 1 (
    echo Warning: Python version %PYTHON_VER% is recommended.
)

IF NOT EXIST venv (
    python -m venv venv
) ELSE (
    echo venv folder already exists, skipping creation...
)
call .\venv\Scripts\activate.bat

pip install .\torch-1.12.1+cu116-cp310-cp310-win_amd64.whl
pip install .\torchvision-0.13.1+cu116-cp310-cp310-win_amd64.whl
pip install .\xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl
pip install --use-pep517 --upgrade -r requirements.txt

copy /y .\bitsandbytes_windows\*.dll .\venv\Lib\site-packages\bitsandbytes\
copy /y .\bitsandbytes_windows\cextension.py .\venv\Lib\site-packages\bitsandbytes\cextension.py
copy /y .\bitsandbytes_windows\main.py .\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.py

accelerate config

再重新执行setup.bat
稍等一会就会提示我们安装成功
这次执行就没什么压力了,非常快~
上面说这么多步骤也是为了同学们以后在安装其他环境的时候也能够随机应变。

选择配置

In which compute environment are you running?
回车,默认就行
Which type of machine are you using?
依然回车
Do you want to run your training on CPU only (even if a GPU is available)?
这里它是问你是否只只用cpu,因为我的显卡是NVIDIA GeForce RTX 3060,所以我多少肯定要体现显卡的优势(够用了),这里我选择NO
Do you wish to optimize your script with torch dynamo?
回车
Do you want to use DeepSpeed
回车
What GPU(s) (by id) should be used for training on this machine as a comma-seperated list?
回车
Do you wish to use FP16 or BF16 (mixed precision)?
输入数字1,选择fp166

安装完成!

启动kohya_ss_GUI

gui-user.bat

Test
稍等一会会弹出来一个网页,如果没有弹出来也可以根据提示手动输入控制台上的链接。
Test

结束语

那么安装kohya_ss_GUI的教程到此也就结束了,环境是装好了,那么如何训练呢?下个教程会教大家如何进行简单的二次元lora训练

评论区
头像