Windows11安装kohya_ss详细步骤(报错、踩坑)

笔者环境

  • OS:windows11
  • Python:3.10.6
  • CUDA11.6

所需环境

安装kohya_ss

方式一:带有GUI的kohya_ss仓库

1、克隆该项目仓库
地址
该项目为 kohya-ss的sd-scripts提供了一个以 Windows 为中心的 Gradio GUI,可以方便的进行参数的预设。

2、双击项目根目录下的 setup.bat

Warning: Python version 3.10.9 is recommended.
=============================================================
Modules installed outside the virtual environment were found.
This can cause issues. Please review the installed modules.

You can uninstall all local modules with:

deactivate
pip freeze > uninstall.txt
pip uninstall -y -r uninstall.txt
=============================================================
Do you want to continue?

[1] - Yes
[2] - No
# 选择1
Enter your choice (1 or 2): 1

Please choose the version of torch you want to install:
[1] - v1 (torch 1.12.1) (Recommended for best compatibility)
[2] - v2 (torch 2.0.0) (Experimental, faster but more prone to issues)

# 这一步选择1,也就是非torch2.0版本,因为Windows目前(2023-06-04)不支持torch2.0中的一些方法的使用,比如torch.compile。如果选择安装torch2.0,那么在训练过程中可能出现错误:RuntimeError:windows not yet supportted torch.compile
Enter your choice (1 or 2):1

# 等该torch下载完成
Looking in indexes: https://mirrors.cloud.tencent.com/pypi/simple, https://download.pytorch.org/whl/cu116
Collecting torch==1.12.1+cu116
  Downloading https://download.pytorch.org/whl/cu116/torch-1.12.1%2Bcu116-cp310-cp310-win_amd64.whl (2388.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺ 2.4/2.4 GB 6.6 MB/s eta 0:00:05
......
#如果 从github下载xformers时太慢了,此时可以直接关掉这个cmd了
 Downloading https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl (184.3 MB)
     ━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.7/184.3 MB 28.0 kB/s eta 1:23:47
# 然后,重新进入项目根目录下,通过pip命令手动下载xformers,并且加一个代理,这样我这里十几秒就可以下载完成了
PS D:\AI\sd\kohya_ss> .\venv\Scripts\activate
(venv) PS D:\AI\sd\kohya_ss> pip install -U -I --no-deps https://ghproxy.com/https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl
Looking in indexes: https://mirrors.cloud.tencent.com/pypi/simple
Collecting xformers==0.0.14.dev0
  Downloading https://ghproxy.com/https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl (184.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━╸━━━━━━━━━━━━━━━━ 110.4/184.3 MB 6.7 MB/s eta 0:00:11
# 等xformers下载完成后关掉当前cmd,再次双击项目根目录下的 setup.bat,之后的两个步骤还和上面一样,都选择 1


In which compute environment are you running?
Please select a choice using the arrow or number keys, and selecting with enter
# 选择第一项(直接回车)
 * This machine
    AWS (Amazon SageMaker)
 Which type of machine are you using?
 
# 选择第一项(直接回车)
Please select a choice using the arrow or number keys, and selecting with enter
 * No distributed training
    multi-CPU
    multi-GPU
    TPU
    MPS

# 选择NO,然后回车
Do you want to run your training on CPU only (even if a GPU is available)? [yes/NO]:NO

# 选择NO,然后回车
Do you wish to optimize your script with torch dynamo?[yes/NO]:NO

# 选择NO,然后回车
Do you want to use DeepSpeed? [yes/NO]: NO

# 输入0,然后回车,也就是使用第一张显卡,如果输入all,可能会在训练过程中报错:ValueError: fp16 mixed precision requires a GPU
What GPU(s) (by id) should be used for training on this machine as a comma-seperated list? [all]:0
------------------------------------------------------------------------------------------------------------------------

# 选择fp16,如果键盘上下键不起作用,则敲数字键盘上的 1,然后回车
Do you wish to use FP16 or BF16 (mixed precision)?
Please select a choice using the arrow or number keys, and selecting with enter
 * no
    fp16
    bf16

3、 NVIDIA 30X0/40X0系列显卡
NVIDIA 30X0/40X0系列显卡可以额外安装 CUDNN 8.6 ,它允许更大的训练批量和更快的训练速度(该作者说:在 4090 GPU 上几乎提高 50%的样本生成速度)。
首先在项目根目录下新建文件夹 cudnn_windows(只用于临时存放下载的依赖库),然后执行以下命令

PS D:\AI\sd\kohya_ss> .\venv\Scripts\activate
(venv) PS D:\AI\sd\kohya_ss> python .\tools\cudann_1.8_install.py
[ ] xformers version 0.0.14.dev0 installed.
[+] bitsandbytes version 0.35.0 installed.
[ ] diffusers version 0.10.2 installed.
[+] transformers version 4.26.0 installed.
[+] torch version 1.12.1+cu116 installed.
[+] torchvision version 0.13.1+cu116 installed.
Checking for CUDNN files in D:\AI\sd\kohya_ss\venv\Lib\site-packages\torch\lib
Copied CUDNN 8.6 files to destination

至此安装完成!

4、运行项目
进入项目根目录下双击gui.bat,等待控制台出现地址http://127.0.0.1:7860/,即可在浏览器中访问该地址进行训练
在这里插入图片描述

方式二:kohya_ss核心仓库

地址
该仓库包含稳定扩散模型的训练、生成和实用脚本。该仓库没有供用户直接使用的GUI界面,而是通过python编码来进行使用。
1、创建python虚拟环境
进入项目根目录下

PS D:\AI\sd\sd-scripts> python -m venv venv
PS D:\AI\sd\sd-scripts> .\venv\Scripts\activate
# 需要更改执行策略
.\venv\Scripts\activate : 无法加载文件 D:\AI\sd\sd-scripts\venv\Scripts\Activate.ps1,因为在此系统上禁止运行脚本。有关
详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ .\venv\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

更改执行策略
以管理员身份运行windows的power shell

PS C:\Windows\system32> set-ExecutionPolicy RemoteSigned

执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y] 是(Y)  [A] 全是(A)  [N] 否(N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“N”): Y
PS C:\Windows\system32>

2、安装依赖库

PS D:\AI\sd\sd-scripts> .\venv\Scripts\activate
# 官方建议安装cuda11.6对应的torch,否则训练过程中会有意想不到的错误产生
(venv) PS D:\AI\sd\sd-scripts> pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116

# 安装必要依赖包
(venv) PS D:\AI\sd\sd-scripts> pip install --upgrade -r requirements.txt

# 安装xformers
(venv) PS D:\AI\sd\sd-scripts> pip install -U -I --no-deps https://ghproxy.com/https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl

# 拷贝一些必要依赖到当前python虚拟环境中
(venv) PS D:\AI\sd\sd-scripts> cp .\bitsandbytes_windows\*.dll .\venv\Lib\site-packages\bitsandbytes\
(venv) PS D:\AI\sd\sd-scripts> cp .\bitsandbytes_windows\cextension.py .\venv\Lib\site-packages\bitsandbytes\cextension.py
(venv) PS D:\AI\sd\sd-scripts> cp .\bitsandbytes_windows\main.py .\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.py

# 选择一些加速训练的配置
(venv) PS D:\AI\sd\sd-scripts> accelerate config
------------------------------------------------------------------------------------------------------------------------In which compute environment are you running?
This machine
------------------------------------------------------------------------------------------------------------------------Which type of machine are you using?
No distributed training
Do you want to run your training on CPU only (even if a GPU is available)? [yes/NO]:NO
Do you wish to optimize your script with torch dynamo?[yes/NO]:NO
Do you want to use DeepSpeed? [yes/NO]: NO
# 这里输入0,也就是使用第一张显卡
What GPU(s) (by id) should be used for training on this machine as a comma-seperated list? [all]:0
-----------------------------------------------------------------------------------------------------------------------
Do you wish to use FP16 or BF16 (mixed precision)?
# 选择fp16,如果键盘上下键不起作用,则敲数字键盘上的 1,然后回车
Please select a choice using the arrow or number keys, and selecting with enter
 * no
    fp16
    bf16
accelerate configuration saved at C:\Users\/.cache\huggingface\accelerate\default_config.yaml

至此安装完成!

题外话

此外,想创建一个微信群大家交流学习。入群需要遵守规定:
禁止有关包括但不限于政治、色情、宗教类等违法中华人民共和国法律的消息;
禁止广告;
禁止私自加群友;
群友一切的损失由自己承担,应当提高警惕,不要轻信他人!!!
个人微信:INYOURWORLDWITHME(加群备注:AI绘画)

  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Kohya_ss 安装指的是在计算机系统中安装 Kohya_ss 软件。Kohya_ss 是一种基于单片机的智能控制系统,广泛应用于工业自动化和智能家居等领域。 要进行 Kohya_ss安装,首先需要准备好所有必要的软件和硬件设备,包括操作系统、Kohya_ss 软件程序和相应的设备驱动程序。 接下来,可以按照以下步骤进行 Kohya_ss安装: 1. 确保计算机系统符合 Kohya_ss 的硬件和软件要求。例如,检查操作系统的版本、处理器类型和内存容量等。 2. 下载并安装 Kohya_ss 的软件程序。可以从官方网站或其他可信的软件下载平台获取 Kohya_ss安装程序文件。 3. 执行 Kohya_ss 安装程序。双击安装程序文件,按照安装向导的指示进行安装。通常需要选择安装目录、确认许可协议并完成一些其他设置。 4. 安装所需的设备驱动程序。根据 Kohya_ss 所需要的外围设备类型和规格,安装相应的驱动程序。驱动程序通常由设备制造商提供,并可以在官方网站或光盘中找到。 5. 配置 Kohya_ss 系统设置。启动 Kohya_ss 软件后,按照用户手册或操作指南的说明进行系统设置。这些设置包括连接外部设备、设置通讯参数和调优程序配置等。 6. 进行系统测试和调试。安装完成后,需要对 Kohya_ss 系统进行测试和调试,以确保其正常运行。可以使用提供的示例程序或自己编写测试程序,验证软件和硬件的功能和兼容性。 7. 完成安装并调试后,Kohya_ss 就可以投入使用了。根据具体的应用需求,可以进一步配置和优化系统,以满足特定的控制要求。 总的来说,Kohya_ss安装是一个较为复杂的过程,需要仔细阅读安装手册和操作指南,并按照相关要求和步骤进行操作。正确安装和配置 Kohya_ss 软件和系统将确保其正常运行,并能够满足控制系统的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

那个小白猿

讨杯可乐

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值