andzhang01 commited on
Commit
368e3de
·
1 Parent(s): 3e824df

Upload 17 files

Browse files
Files changed (17) hide show
  1. .gitattributes +1 -34
  2. .gitignore +20 -0
  3. .gitmodules +6 -0
  4. README.md +47 -0
  5. gui.py +94 -0
  6. install-cn.ps1 +55 -0
  7. install.bash +34 -0
  8. install.ps1 +23 -0
  9. interrogate.ps1 +29 -0
  10. resize.ps1 +41 -0
  11. run_gui.ps1 +6 -0
  12. tensorboard.ps1 +3 -0
  13. train.ipynb +99 -0
  14. train.ps1 +183 -0
  15. train.sh +138 -0
  16. train_by_toml.ps1 +33 -0
  17. train_by_toml.sh +24 -0
.gitattributes CHANGED
@@ -1,34 +1 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tflite filter=lfs diff=lfs merge=lfs -text
29
- *.tgz filter=lfs diff=lfs merge=lfs -text
30
- *.wasm filter=lfs diff=lfs merge=lfs -text
31
- *.xz filter=lfs diff=lfs merge=lfs -text
32
- *.zip filter=lfs diff=lfs merge=lfs -text
33
- *.zst filter=lfs diff=lfs merge=lfs -text
34
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.ps1 text eol=crlf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.gitignore ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .vscode
2
+ .idea
3
+
4
+ venv
5
+
6
+ output/*
7
+ !output/.keep
8
+
9
+ py310
10
+ git
11
+
12
+ train/*
13
+ logs/*
14
+ sd-models/*
15
+ !sd-models/put stable diffusion model here.txt
16
+ !logs/.keep
17
+
18
+ tests/
19
+
20
+ huggingface/hub/models--openai--clip-vit-large-patch14
.gitmodules ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [submodule "sd-scripts"]
2
+ path = sd-scripts
3
+ url = https://github.com/kohya-ss/sd-scripts.git
4
+ [submodule "frontend"]
5
+ path = frontend
6
+ url = https://github.com/hanamizuki-ai/lora-gui-dist
README.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LoRA-scripts
2
+
3
+ LoRA training scripts for [kohya-ss/sd-scripts](https://github.com/kohya-ss/sd-scripts.git)
4
+
5
+ ## Usage
6
+
7
+ ### Clone repo with submodules
8
+
9
+ ```sh
10
+ git clone --recurse-submodules https://github.com/Akegarasu/lora-scripts
11
+ ```
12
+
13
+ ### Required Dependencies
14
+
15
+ Python 3.10.8 and Git
16
+
17
+ ### Windows
18
+
19
+ #### Installation
20
+
21
+ Run `install.ps1` will automaticilly create a venv for you and install necessary deps.
22
+
23
+ #### Train
24
+
25
+ Edit `train.ps1`, and run it.
26
+
27
+ ### Linux
28
+
29
+ #### Installation
30
+
31
+ Run `install.bash` will create a venv and install necessary deps.
32
+
33
+ #### Train
34
+
35
+ Training script `train.sh` **will not** activate venv for you. You should activate venv first.
36
+
37
+ ```sh
38
+ source venv/bin/activate
39
+ ```
40
+
41
+ Edit `train.sh`, and run it.
42
+
43
+ #### TensorBoard
44
+
45
+ Run `tensorboard.ps1` will start TensorBoard at http://localhost:6006/
46
+
47
+ ![](./assets/tensorboard-example.png)
gui.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import json
3
+ import os
4
+ import subprocess
5
+ import sys
6
+ import webbrowser
7
+ from datetime import datetime
8
+ from threading import Lock
9
+
10
+ import uvicorn
11
+ from fastapi import BackgroundTasks, FastAPI, Request
12
+ from fastapi.responses import FileResponse
13
+ from fastapi.staticfiles import StaticFiles
14
+
15
+ import toml
16
+
17
+ app = FastAPI()
18
+
19
+ lock = Lock()
20
+
21
+ # fix mimetype error in some fucking systems
22
+ sf = StaticFiles(directory="frontend/dist")
23
+ _o_fr = sf.file_response
24
+ def _hooked_file_response(*args, **kwargs):
25
+ full_path = args[0]
26
+ r = _o_fr(*args, **kwargs)
27
+ if full_path.endswith(".js"):
28
+ r.media_type = "application/javascript"
29
+ elif full_path.endswith(".css"):
30
+ r.media_type = "text/css"
31
+ return r
32
+ sf.file_response = _hooked_file_response
33
+
34
+ parser = argparse.ArgumentParser(description="GUI for training network")
35
+ parser.add_argument("--port", type=int, default=28000, help="Port to run the server on")
36
+
37
+ def run_train(toml_path: str):
38
+ print(f"Training started with config file / 训练开始,使用配置文件: {toml_path}")
39
+ args = [
40
+ "accelerate", "launch", "--num_cpu_threads_per_process", "8",
41
+ "./sd-scripts/train_network.py",
42
+ "--config_file", toml_path,
43
+ ]
44
+ try:
45
+ result = subprocess.run(args, shell=True, env=os.environ)
46
+ if result.returncode != 0:
47
+ print(f"Training failed / 训练失败")
48
+ else:
49
+ print(f"Training finished / 训练完成")
50
+ except Exception as e:
51
+ print(f"An error occurred when training / 创建训练进程时出现致命错误: {e}")
52
+ finally:
53
+ lock.release()
54
+
55
+
56
+ @app.post("/api/run")
57
+ async def create_toml_file(request: Request, background_tasks: BackgroundTasks):
58
+ acquired = lock.acquire(blocking=False)
59
+
60
+ if not acquired:
61
+ print("Training is already running / 已有正在进行的训练")
62
+ return {"status": "fail", "detail": "Training is already running"}
63
+
64
+ timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
65
+ toml_file = f"toml/{timestamp}.toml"
66
+ toml_data = await request.body()
67
+ j = json.loads(toml_data.decode("utf-8"))
68
+ with open(toml_file, "w") as f:
69
+ f.write(toml.dumps(j))
70
+ background_tasks.add_task(run_train, toml_file)
71
+ return {"status": "success"}
72
+
73
+ @app.middleware("http")
74
+ async def add_cache_control_header(request, call_next):
75
+ response = await call_next(request)
76
+ response.headers["Cache-Control"] = "max-age=0"
77
+ return response
78
+
79
+ @app.get("/")
80
+ async def index():
81
+ return FileResponse("./frontend/dist/index.html")
82
+
83
+
84
+ app.mount("/", sf, name="static")
85
+
86
+ if __name__ == "__main__":
87
+ args, _ = parser.parse_known_args()
88
+ print(f"Server started at http://127.0.0.1:{args.port}")
89
+ if sys.platform == "win32":
90
+ # disable triton on windows
91
+ os.environ["XFORMERS_FORCE_DISABLE_TRITON"] = "1"
92
+
93
+ webbrowser.open(f"http://127.0.0.1:{args.port}")
94
+ uvicorn.run(app, host="127.0.0.1", port=28000, log_level="error")
install-cn.ps1 ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $Env:HF_HOME = "huggingface"
2
+ $Env:PIP_DISABLE_PIP_VERSION_CHECK = 1
3
+ $Env:PIP_NO_CACHE_DIR = 1
4
+ function InstallFail {
5
+ Write-Output "��װʧ�ܡ�"
6
+ Read-Host | Out-Null ;
7
+ Exit
8
+ }
9
+
10
+ function Check {
11
+ param (
12
+ $ErrorInfo
13
+ )
14
+ if (!($?)) {
15
+ Write-Output $ErrorInfo
16
+ InstallFail
17
+ }
18
+ }
19
+
20
+ if (!(Test-Path -Path "venv")) {
21
+ Write-Output "���ڴ������⻷��..."
22
+ python -m venv venv
23
+ Check "�������⻷��ʧ�ܣ����� python �Ƿ�װ����Լ� python �汾�Ƿ�Ϊ64λ�汾��python 3.10����python��Ŀ¼�Ƿ��ڻ�������PATH�ڡ�"
24
+ }
25
+
26
+ .\venv\Scripts\activate
27
+ Check "�������⻷��ʧ�ܡ�"
28
+
29
+ Set-Location .\sd-scripts
30
+ Write-Output "��װ������������ (�ѽ��й��ڼ��٣����ڹ�����޷�ʹ�ü���Դ�뻻�� install.ps1 �ű�)"
31
+ $install_torch = Read-Host "�Ƿ���Ҫ��װ Torch+xformers? ��������Ϊ�״ΰ�װ��ѡ�� y ��������Ϊ����������װ��ѡ�� n��[y/n] (Ĭ��Ϊ y)"
32
+ if ($install_torch -eq "y" -or $install_torch -eq "Y" -or $install_torch -eq ""){
33
+ pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html -i https://mirrors.bfsu.edu.cn/pypi/web/simple
34
+ Check "torch ��װʧ�ܣ���ɾ�� venv �ļ��к��������С�"
35
+ pip install -U -I --no-deps xformers==0.0.17 -i https://mirrors.aliyun.com/pypi/simple/
36
+ Check "xformers ��װʧ�ܡ�"
37
+ }
38
+
39
+ pip install --upgrade -r requirements.txt -i https://mirrors.bfsu.edu.cn/pypi/web/simple
40
+ Check "����������װʧ�ܡ�"
41
+ pip install --upgrade lion-pytorch dadaptation -i https://mirrors.bfsu.edu.cn/pypi/web/simple
42
+ Check "Lion��dadaptation �Ż�����װʧ�ܡ�"
43
+ pip install --upgrade lycoris-lora -i https://mirrors.bfsu.edu.cn/pypi/web/simple
44
+ Check "lycoris ��װʧ�ܡ�"
45
+ pip install --upgrade fastapi uvicorn -i https://mirrors.bfsu.edu.cn/pypi/web/simple
46
+ Check "UI ����������װʧ�ܡ�"
47
+
48
+
49
+ Write-Output "��װ bitsandbytes..."
50
+ cp .\bitsandbytes_windows\*.dll ..\venv\Lib\site-packages\bitsandbytes\
51
+ cp .\bitsandbytes_windows\cextension.py ..\venv\Lib\site-packages\bitsandbytes\cextension.py
52
+ cp .\bitsandbytes_windows\main.py ..\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.py
53
+
54
+ Write-Output "��װ���"
55
+ Read-Host | Out-Null ;
install.bash ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ echo "Creating python venv..."
2
+ python3 -m venv venv
3
+ source venv/bin/activate
4
+
5
+ echo "Installing torch & xformers..."
6
+ printf 'Which version of torch do you want to install?
7
+ (1) torch 2.0.0+cu118 with xformers 0.0.17 (suggested)
8
+ (2) torch 1.12.1+cu116, with xformers 0bad001ddd56c080524d37c84ff58d9cd030ebfd
9
+ '
10
+ while true; do
11
+ read -p "Choose: " version
12
+ case $version in
13
+ [1]*)
14
+ pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
15
+ pip install xformers==0.0.17
16
+ break
17
+ ;;
18
+ [2]*)
19
+ pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
20
+ pip install --upgrade git+https://github.com/facebookresearch/xformers.git@0bad001ddd56c080524d37c84ff58d9cd030ebfd
21
+ pip install triton==2.0.0.dev20221202
22
+ break
23
+ ;;
24
+ *) echo "Please enter 1 or 2." ;;
25
+ esac
26
+ done
27
+
28
+ echo "Installing deps..."
29
+ cd ./sd-scripts
30
+
31
+ pip install --upgrade -r requirements.txt
32
+ pip install --upgrade lion-pytorch lycoris-lora dadaptation
33
+
34
+ echo "Install completed"
install.ps1 ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $Env:HF_HOME = "huggingface"
2
+
3
+ if (!(Test-Path -Path "venv")) {
4
+ Write-Output "Creating venv for python..."
5
+ python -m venv venv
6
+ }
7
+ .\venv\Scripts\activate
8
+
9
+ Write-Output "Installing deps..."
10
+ Set-Location .\sd-scripts
11
+ pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
12
+ pip install --upgrade -r requirements.txt
13
+ pip install --upgrade xformers==0.0.17
14
+
15
+ Write-Output "Installing bitsandbytes for windows..."
16
+ cp .\bitsandbytes_windows\*.dll ..\venv\Lib\site-packages\bitsandbytes\
17
+ cp .\bitsandbytes_windows\cextension.py ..\venv\Lib\site-packages\bitsandbytes\cextension.py
18
+ cp .\bitsandbytes_windows\main.py ..\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.py
19
+
20
+ pip install --upgrade lion-pytorch dadaptation lycoris-lora
21
+
22
+ Write-Output "Install completed"
23
+ Read-Host | Out-Null ;
interrogate.ps1 ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LoRA interrogate script by @bdsqlsz
2
+
3
+ $v2 = 0 # load Stable Diffusion v2.x model / Stable Diffusion 2.x模型读取
4
+ $sd_model = "./sd-models/sd_model.safetensors" # Stable Diffusion model to load: ckpt or safetensors file | 读取的基础SD模型, 保存格式 cpkt 或 safetensors
5
+ $model = "./output/LoRA.safetensors" # LoRA model to interrogate: ckpt or safetensors file | 需要调查关键字的LORA模型, 保存格式 cpkt 或 safetensors
6
+ $batch_size = 64 # batch size for processing with Text Encoder | 使用 Text Encoder 处理时的批量大小,默认16,推荐64/128
7
+ $clip_skip = 1 # use output of nth layer from back of text encoder (n>=1) | 使用文本编码器倒数第 n 层的输出,n 可以是大于等于 1 的整数
8
+
9
+
10
+ # Activate python venv
11
+ .\venv\Scripts\activate
12
+
13
+ $Env:HF_HOME = "huggingface"
14
+ $ext_args = [System.Collections.ArrayList]::new()
15
+
16
+ if ($v2) {
17
+ [void]$ext_args.Add("--v2")
18
+ }
19
+
20
+ # run interrogate
21
+ accelerate launch --num_cpu_threads_per_process=8 "./sd-scripts/networks/lora_interrogator.py" `
22
+ --sd_model=$sd_model `
23
+ --model=$model `
24
+ --batch_size=$batch_size `
25
+ --clip_skip=$clip_skip `
26
+ $ext_args
27
+
28
+ Write-Output "Interrogate finished"
29
+ Read-Host | Out-Null ;
resize.ps1 ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LoRA resize script by @bdsqlsz
2
+
3
+ $save_precision = "fp16" # precision in saving, default float | 保存精度, 可选 float、fp16、bf16, 默认 float
4
+ $new_rank = 4 # dim rank of output LoRA | dim rank等级, 默认 4
5
+ $model = "./output/lora_name.safetensors" # original LoRA model path need to resize, save as cpkt or safetensors | 需要调整大小的模型路径, 保存格式 cpkt 或 safetensors
6
+ $save_to = "./output/lora_name_new.safetensors" # output LoRA model path, save as ckpt or safetensors | 输出路径, 保存格式 cpkt 或 safetensors
7
+ $device = "cuda" # device to use, cuda for GPU | 使用 GPU跑, 默认 CPU
8
+ $verbose = 1 # display verbose resizing information | rank变更时, 显示详细信息
9
+ $dynamic_method = "" # Specify dynamic resizing method, --new_rank is used as a hard limit for max rank | 动态调节大小,可选"sv_ratio", "sv_fro", "sv_cumulative",默认无
10
+ $dynamic_param = "" # Specify target for dynamic reduction | 动态参数,sv_ratio模式推荐1~2, sv_cumulative模式0~1, sv_fro模式0~1, 比sv_cumulative要高
11
+
12
+
13
+ # Activate python venv
14
+ .\venv\Scripts\activate
15
+
16
+ $Env:HF_HOME = "huggingface"
17
+ $ext_args = [System.Collections.ArrayList]::new()
18
+
19
+ if ($verbose) {
20
+ [void]$ext_args.Add("--verbose")
21
+ }
22
+
23
+ if ($dynamic_method) {
24
+ [void]$ext_args.Add("--dynamic_method=" + $dynamic_method)
25
+ }
26
+
27
+ if ($dynamic_param) {
28
+ [void]$ext_args.Add("--dynamic_param=" + $dynamic_param)
29
+ }
30
+
31
+ # run resize
32
+ accelerate launch --num_cpu_threads_per_process=8 "./sd-scripts/networks/resize_lora.py" `
33
+ --save_precision=$save_precision `
34
+ --new_rank=$new_rank `
35
+ --model=$model `
36
+ --save_to=$save_to `
37
+ --device=$device `
38
+ $ext_args
39
+
40
+ Write-Output "Resize finished"
41
+ Read-Host | Out-Null ;
run_gui.ps1 ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ .\venv\Scripts\activate
2
+
3
+ $Env:HF_HOME = "huggingface"
4
+ $Env:PYTHONUTF8 = "1"
5
+
6
+ python ./gui.py
tensorboard.ps1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .\venv\Scripts\activate
2
+
3
+ tensorboard --logdir=.\logs
train.ipynb ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {
7
+ "pycharm": {
8
+ "name": "#%%\n"
9
+ }
10
+ },
11
+ "outputs": [],
12
+ "source": [
13
+ "# Train data path | 设置训练用模型、图片\n",
14
+ "pretrained_model = \"./sd-models/model.ckpt\" # base model path | 底模路径\n",
15
+ "train_data_dir = \"./train/aki\" # train dataset path | 训练数据集路径\n",
16
+ "\n",
17
+ "# Train related params | 训练相关参数\n",
18
+ "resolution = \"512,512\" # image resolution w,h. 图片分辨率,宽,高。支持非正方形,但必须是 64 倍数。\n",
19
+ "batch_size = 1 # batch size\n",
20
+ "max_train_epoches = 10 # max train epoches | 最大训练 epoch\n",
21
+ "save_every_n_epochs = 2 # save every n epochs | 每 N 个 epoch 保存一次\n",
22
+ "network_dim = 32 # network dim | 常用 4~128,不是越大越好\n",
23
+ "network_alpha= 32 # network alpha | 常用与 network_dim 相同的值或者采用较小的值,如 network_dim的一半 防止下溢。默认值为 1,使用较小的 alpha 需要提升学习率。\n",
24
+ "clip_skip = 2 # clip skip | 玄学 一般用 2\n",
25
+ "train_unet_only = 0 # train U-Net only | 仅训练 U-Net,开启这个会牺牲效果大幅减少显存使用。6G显存可以开启\n",
26
+ "train_text_encoder_only = 0 # train Text Encoder only | 仅训练 文本编码器\n",
27
+ "\n",
28
+ "# Learning rate | 学习率\n",
29
+ "lr = \"1e-4\"\n",
30
+ "unet_lr = \"1e-4\"\n",
31
+ "text_encoder_lr = \"1e-5\"\n",
32
+ "lr_scheduler = \"cosine_with_restarts\" # \"linear\", \"cosine\", \"cosine_with_restarts\", \"polynomial\", \"constant\", \"constant_with_warmup\"\n",
33
+ "\n",
34
+ "# Output settings | 输出设置\n",
35
+ "output_name = \"aki\" # output model name | 模型保存名称\n",
36
+ "save_model_as = \"safetensors\" # model save ext | 模型保存格式 ckpt, pt, safetensors"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": null,
42
+ "metadata": {
43
+ "pycharm": {
44
+ "name": "#%%\n"
45
+ }
46
+ },
47
+ "outputs": [],
48
+ "source": [
49
+ "!accelerate launch --num_cpu_threads_per_process=8 \"./sd-scripts/train_network.py\" \\\n",
50
+ " --enable_bucket \\\n",
51
+ " --pretrained_model_name_or_path=$pretrained_model \\\n",
52
+ " --train_data_dir=$train_data_dir \\\n",
53
+ " --output_dir=\"./output\" \\\n",
54
+ " --logging_dir=\"./logs\" \\\n",
55
+ " --resolution=$resolution \\\n",
56
+ " --network_module=networks.lora \\\n",
57
+ " --max_train_epochs=$max_train_epoches \\\n",
58
+ " --learning_rate=$lr \\\n",
59
+ " --unet_lr=$unet_lr \\\n",
60
+ " --text_encoder_lr=$text_encoder_lr \\\n",
61
+ " --network_dim=$network_dim \\\n",
62
+ " --network_alpha=$network_alpha \\\n",
63
+ " --output_name=$output_name \\\n",
64
+ " --lr_scheduler=$lr_scheduler \\\n",
65
+ " --train_batch_size=$batch_size \\\n",
66
+ " --save_every_n_epochs=$save_every_n_epochs \\\n",
67
+ " --mixed_precision=\"fp16\" \\\n",
68
+ " --save_precision=\"fp16\" \\\n",
69
+ " --seed=\"1337\" \\\n",
70
+ " --cache_latents \\\n",
71
+ " --clip_skip=$clip_skip \\\n",
72
+ " --prior_loss_weight=1 \\\n",
73
+ " --max_token_length=225 \\\n",
74
+ " --caption_extension=\".txt\" \\\n",
75
+ " --save_model_as=$save_model_as \\\n",
76
+ " --xformers --shuffle_caption --use_8bit_adam"
77
+ ]
78
+ }
79
+ ],
80
+ "metadata": {
81
+ "kernelspec": {
82
+ "display_name": "Python 3",
83
+ "language": "python",
84
+ "name": "python3"
85
+ },
86
+ "language_info": {
87
+ "name": "python",
88
+ "version": "3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]"
89
+ },
90
+ "orig_nbformat": 4,
91
+ "vscode": {
92
+ "interpreter": {
93
+ "hash": "675b13e958f0d0236d13cdfe08a1df3882cae564fa23a2e7e5eb1f2c6c632b02"
94
+ }
95
+ }
96
+ },
97
+ "nbformat": 4,
98
+ "nbformat_minor": 2
99
+ }
train.ps1 ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LoRA train script by @Akegarasu
2
+
3
+ # Train data path | 设置训练用模型、图片
4
+ $pretrained_model = "./sd-models/model.ckpt" # base model path | 底模路径
5
+ $is_v2_model = 0 # SD2.0 model | SD2.0模型 2.0模型下 clip_skip 默认无效
6
+ $parameterization = 0 # parameterization | 参数化 本参数需要和 V2 参数同步使用 实验性功能
7
+ $train_data_dir = "./train/aki" # train dataset path | 训练数据集路径
8
+ $reg_data_dir = "" # directory for regularization images | 正则化数据集路径,默认不使用正则化图像。
9
+
10
+ # Network settings | 网络设置
11
+ $network_module = "networks.lora" # 在这里将会设置训练的网络种类,默认为 networks.lora 也就是 LoRA 训练。如果你想训练 LyCORIS(LoCon、LoHa) 等,则修改这个值为 lycoris.kohya
12
+ $network_weights = "" # pretrained weights for LoRA network | 若需要从已有的 LoRA 模型上继续训练,请填写 LoRA 模型路径。
13
+ $network_dim = 32 # network dim | 常用 4~128,不是越大越好
14
+ $network_alpha = 32 # network alpha | 常用与 network_dim 相同的值或者采用较小的值,如 network_dim的一半 防止下溢。默认值为 1,使用较小的 alpha 需要提升学习率。
15
+
16
+ # Train related params | 训练相关参数
17
+ $resolution = "512,512" # image resolution w,h. 图片分辨率,宽,高。支持非正方形,但必须是 64 倍数。
18
+ $batch_size = 1 # batch size
19
+ $max_train_epoches = 10 # max train epoches | 最大训练 epoch
20
+ $save_every_n_epochs = 2 # save every n epochs | 每 N 个 epoch 保存一次
21
+
22
+ $train_unet_only = 0 # train U-Net only | 仅训练 U-Net,开启这个会牺牲效果大幅减少显存使用。6G显存可以开启
23
+ $train_text_encoder_only = 0 # train Text Encoder only | 仅训练 文本编码器
24
+ $stop_text_encoder_training = 0 # stop text encoder training | 在第N步时停止训练文本编码器
25
+
26
+ $noise_offset = 0 # noise offset | 在训练中添加噪声偏移来改良生成非常暗或者非常亮的图像,如果启用,推荐参数为 0.1
27
+ $keep_tokens = 0 # keep heading N tokens when shuffling caption tokens | 在随机打乱 tokens 时,保留前 N 个不变。
28
+ $min_snr_gamma = 0 # minimum signal-to-noise ratio (SNR) value for gamma-ray | 伽马射线事件的最小信噪比(SNR)值 默认为 0
29
+
30
+ # Learning rate | 学习率
31
+ $lr = "1e-4"
32
+ $unet_lr = "1e-4"
33
+ $text_encoder_lr = "1e-5"
34
+ $lr_scheduler = "cosine_with_restarts" # "linear", "cosine", "cosine_with_restarts", "polynomial", "constant", "constant_with_warmup"
35
+ $lr_warmup_steps = 0 # warmup steps | 学习率预热步数,lr_scheduler 为 constant 或 adafactor 时该值需要设为0。
36
+ $lr_restart_cycles = 1 # cosine_with_restarts restart cycles | 余弦退火重启次数,仅在 lr_scheduler 为 cosine_with_restarts 时起效。
37
+
38
+ # Output settings | 输出设置
39
+ $output_name = "aki" # output model name | 模型保存名称
40
+ $save_model_as = "safetensors" # model save ext | 模型保存格式 ckpt, pt, safetensors
41
+
42
+ # Resume training state | 恢复训练设置
43
+ $save_state = 0 # save training state | 保存训练状态 名称类似于 <output_name>-??????-state ?????? 表示 epoch 数
44
+ $resume = "" # resume from state | 从某个状态文件夹中恢复训练 需配合上方参数同时使用 由于规范文件限制 epoch 数和全局步数不会保存 即使恢复时它们也从 1 开始 与 network_weights 的具体实现操作并不一致
45
+
46
+ # 其他设置
47
+ $min_bucket_reso = 256 # arb min resolution | arb 最小分辨率
48
+ $max_bucket_reso = 1024 # arb max resolution | arb 最大分辨率
49
+ $persistent_data_loader_workers = 0 # persistent dataloader workers | 容易爆内存,保留加载训练集的worker,减少每个 epoch 之间的停顿
50
+ $clip_skip = 2 # clip skip | 玄学 一般用 2
51
+ $multi_gpu = 0 # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用
52
+ $lowram = 0 # lowram mode | 低内存模式 该模式下会将 U-net 文本编码器 VAE 转移到 GPU 显存中 启用该模式可能会对显存有一定影响
53
+
54
+ # 优化器设置
55
+ $optimizer_type = "AdamW8bit" # Optimizer type | 优化器类型 默认为 AdamW8bit,可选:AdamW AdamW8bit Lion SGDNesterov SGDNesterov8bit DAdaptation AdaFactor
56
+
57
+ # LyCORIS 训练设置
58
+ $algo = "lora" # LyCORIS network algo | LyCORIS 网络算法 可选 lora、loha、lokr、ia3、dylora。lora即为locon
59
+ $conv_dim = 4 # conv dim | 类似于 network_dim,推荐为 4
60
+ $conv_alpha = 4 # conv alpha | 类似于 network_alpha,可以采用与 conv_dim 一致或者更小的值
61
+ $dropout = "0" # dropout | dropout 概率, 0 为不使用 dropout, 越大则 dropout 越多,推荐 0~0.5, LoHa/LoKr/(IA)^3暂时不支持
62
+
63
+ # ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================
64
+ # Activate python venv
65
+ .\venv\Scripts\activate
66
+
67
+ $Env:HF_HOME = "huggingface"
68
+ $Env:XFORMERS_FORCE_DISABLE_TRITON = "1"
69
+ $ext_args = [System.Collections.ArrayList]::new()
70
+ $launch_args = [System.Collections.ArrayList]::new()
71
+
72
+ if ($multi_gpu) {
73
+ [void]$launch_args.Add("--multi_gpu")
74
+ }
75
+
76
+ if ($lowram) {
77
+ [void]$ext_args.Add("--lowram")
78
+ }
79
+
80
+ if ($is_v2_model) {
81
+ [void]$ext_args.Add("--v2")
82
+ }
83
+ else {
84
+ [void]$ext_args.Add("--clip_skip=$clip_skip")
85
+ }
86
+
87
+ if ($parameterization) {
88
+ [void]$ext_args.Add("--v_parameterization")
89
+ }
90
+
91
+ if ($train_unet_only) {
92
+ [void]$ext_args.Add("--network_train_unet_only")
93
+ }
94
+
95
+ if ($train_text_encoder_only) {
96
+ [void]$ext_args.Add("--network_train_text_encoder_only")
97
+ }
98
+
99
+ if ($network_weights) {
100
+ [void]$ext_args.Add("--network_weights=" + $network_weights)
101
+ }
102
+
103
+ if ($reg_data_dir) {
104
+ [void]$ext_args.Add("--reg_data_dir=" + $reg_data_dir)
105
+ }
106
+
107
+ if ($optimizer_type) {
108
+ [void]$ext_args.Add("--optimizer_type=" + $optimizer_type)
109
+ }
110
+
111
+ if ($optimizer_type -eq "DAdaptation") {
112
+ [void]$ext_args.Add("--optimizer_args")
113
+ [void]$ext_args.Add("decouple=True")
114
+ }
115
+
116
+ if ($network_module -eq "lycoris.kohya") {
117
+ [void]$ext_args.Add("--network_args")
118
+ [void]$ext_args.Add("conv_dim=$conv_dim")
119
+ [void]$ext_args.Add("conv_alpha=$conv_alpha")
120
+ [void]$ext_args.Add("algo=$algo")
121
+ [void]$ext_args.Add("dropout=$dropout")
122
+ }
123
+
124
+ if ($noise_offset -ne 0) {
125
+ [void]$ext_args.Add("--noise_offset=$noise_offset")
126
+ }
127
+
128
+ if ($stop_text_encoder_training -ne 0) {
129
+ [void]$ext_args.Add("--stop_text_encoder_training=$stop_text_encoder_training")
130
+ }
131
+
132
+ if ($save_state -eq 1) {
133
+ [void]$ext_args.Add("--save_state")
134
+ }
135
+
136
+ if ($resume) {
137
+ [void]$ext_args.Add("--resume=" + $resume)
138
+ }
139
+
140
+ if ($min_snr_gamma -ne 0) {
141
+ [void]$ext_args.Add("--min_snr_gamma=$min_snr_gamma")
142
+ }
143
+
144
+ if($persistent_data_loader_workers) {
145
+ [void]$ext_args.Add("--persistent_data_loader_workers")
146
+ }
147
+
148
+ # run train
149
+ accelerate launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" `
150
+ --enable_bucket `
151
+ --pretrained_model_name_or_path=$pretrained_model `
152
+ --train_data_dir=$train_data_dir `
153
+ --output_dir="./output" `
154
+ --logging_dir="./logs" `
155
+ --log_prefix=$output_name `
156
+ --resolution=$resolution `
157
+ --network_module=$network_module `
158
+ --max_train_epochs=$max_train_epoches `
159
+ --learning_rate=$lr `
160
+ --unet_lr=$unet_lr `
161
+ --text_encoder_lr=$text_encoder_lr `
162
+ --lr_scheduler=$lr_scheduler `
163
+ --lr_warmup_steps=$lr_warmup_steps `
164
+ --lr_scheduler_num_cycles=$lr_restart_cycles `
165
+ --network_dim=$network_dim `
166
+ --network_alpha=$network_alpha `
167
+ --output_name=$output_name `
168
+ --train_batch_size=$batch_size `
169
+ --save_every_n_epochs=$save_every_n_epochs `
170
+ --mixed_precision="fp16" `
171
+ --save_precision="fp16" `
172
+ --seed="1337" `
173
+ --cache_latents `
174
+ --prior_loss_weight=1 `
175
+ --max_token_length=225 `
176
+ --caption_extension=".txt" `
177
+ --save_model_as=$save_model_as `
178
+ --min_bucket_reso=$min_bucket_reso `
179
+ --max_bucket_reso=$max_bucket_reso `
180
+ --keep_tokens=$keep_tokens `
181
+ --xformers --shuffle_caption $ext_args
182
+ Write-Output "Train finished"
183
+ Read-Host | Out-Null ;
train.sh ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # LoRA train script by @Akegarasu
3
+
4
+ # Train data path | 设置训练用模型、图片
5
+ pretrained_model="./sd-models/model.ckpt" # base model path | 底模路径
6
+ is_v2_model=0 # SD2.0 model | SD2.0模型 2.0模型下 clip_skip 默认无效
7
+ parameterization=0 # parameterization | 参数化 本参数需要和 V2 参数同步使用 实验性功能
8
+ train_data_dir="./train/aki" # train dataset path | 训练数据集路径
9
+ reg_data_dir="" # directory for regularization images | 正则化数据集路径,默认不使用正则化图像。
10
+
11
+ # Network settings | 网络设置
12
+ network_module="networks.lora" # 在这里将会设置训练的网络种类,默认为 networks.lora 也就是 LoRA 训练。如果你想训练 LyCORIS(LoCon、LoHa) 等,则修改这个值为 lycoris.kohya
13
+ network_weights="" # pretrained weights for LoRA network | 若需要从已有的 LoRA 模型上继续训练,请填写 LoRA 模型路径。
14
+ network_dim=32 # network dim | 常用 4~128,不是越大越好
15
+ network_alpha=32 # network alpha | 常用与 network_dim 相同的值或者采用较小的值,如 network_dim的一半 防止下溢。默认值为 1,使用较小的 alpha 需要提升学习率。
16
+
17
+ # Train related params | 训练相关参数
18
+ resolution="512,512" # image resolution w,h. 图片分辨率,宽,高。支持非正方形,但必须是 64 倍数。
19
+ batch_size=1 # batch size
20
+ max_train_epoches=10 # max train epoches | 最大训练 epoch
21
+ save_every_n_epochs=2 # save every n epochs | 每 N 个 epoch 保存一次
22
+
23
+ train_unet_only=0 # train U-Net only | 仅训练 U-Net,开启这个会牺牲效果大幅减少显存使用。6G显存可以开启
24
+ train_text_encoder_only=0 # train Text Encoder only | 仅训练 文本编码器
25
+ stop_text_encoder_training=0 # stop text encoder training | 在第N步时停止训练文本编码器
26
+
27
+ noise_offset="0" # noise offset | 在训练中添加噪声偏移来改良生成非常暗或者非常亮的图像,如果启用,推荐参数为0.1
28
+ keep_tokens=0 # keep heading N tokens when shuffling caption tokens | 在随机打乱 tokens 时,保留前 N 个不变。
29
+ min_snr_gamma=0 # minimum signal-to-noise ratio (SNR) value for gamma-ray | 伽马射线事件的最小信噪比(SNR)值 默认为 0
30
+
31
+ # Learning rate | 学习率
32
+ lr="1e-4"
33
+ unet_lr="1e-4"
34
+ text_encoder_lr="1e-5"
35
+ lr_scheduler="cosine_with_restarts" # "linear", "cosine", "cosine_with_restarts", "polynomial", "constant", "constant_with_warmup", "adafactor"
36
+ lr_warmup_steps=0 # warmup steps | 学习率预热步数,lr_scheduler 为 constant 或 adafactor 时该值需要设为0。
37
+ lr_restart_cycles=1 # cosine_with_restarts restart cycles | 余弦退火重启次数,仅在 lr_scheduler 为 cosine_with_restarts 时起效。
38
+
39
+ # Output settings | 输出设置
40
+ output_name="aki" # output model name | 模型保存名称
41
+ save_model_as="safetensors" # model save ext | 模型保存格式 ckpt, pt, safetensors
42
+
43
+ # Resume training state | 恢复训练设置
44
+ save_state=0 # save state | 保存训练状态 名称类似于 <output_name>-??????-state ?????? 表示 epoch 数
45
+ resume="" # resume from state | 从某个状态文件夹中恢复训练 需配合上方参数同时使用 由于规范文件限制 epoch 数和全局步数不会保存 即使恢复时它们也从 1 开始 与 network_weights 的具体实现操作并不一致
46
+
47
+ # 其他设置
48
+ min_bucket_reso=256 # arb min resolution | arb 最小分辨率
49
+ max_bucket_reso=1024 # arb max resolution | arb 最大分辨率
50
+ persistent_data_loader_workers=0 # persistent dataloader workers | 容易爆内存,保留加载训练集的worker,减少每个 epoch 之间的停顿
51
+ clip_skip=2 # clip skip | 玄学 一般用 2
52
+
53
+ # 优化器设置
54
+ optimizer_type="AdamW8bit" # Optimizer type | 优化器类型 默认为 AdamW8bit,可选:AdamW AdamW8bit Lion SGDNesterov SGDNesterov8bit DAdaptation AdaFactor
55
+
56
+ # LyCORIS 训练设置
57
+ algo="lora" # LyCORIS network algo | LyCORIS 网络算法 可选 lora、loha、lokr、ia3、dylora。lora即为locon
58
+ conv_dim=4 # conv dim | 类似于 network_dim,推荐为 4
59
+ conv_alpha=4 # conv alpha | 类似于 network_alpha,可以采用与 conv_dim 一致或者更小的值
60
+ dropout="0" # dropout | dropout 概率, 0 为不使用 dropout, 越大则 dropout 越多,推荐 0~0.5, LoHa/LoKr/(IA)^3暂时不支持
61
+
62
+ # ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================
63
+ export HF_HOME="huggingface"
64
+ export TF_CPP_MIN_LOG_LEVEL=3
65
+
66
+ extArgs=()
67
+ launchArgs=()
68
+ if [[ $multi_gpu == 1 ]]; then launchArgs+=("--multi_gpu"); fi
69
+
70
+ if [[ $is_v2_model == 1 ]]; then
71
+ extArgs+=("--v2");
72
+ else
73
+ extArgs+=("--clip_skip $clip_skip");
74
+ fi
75
+
76
+ if [[ $parameterization == 1 ]]; then extArgs+=("--v_parameterization"); fi
77
+
78
+ if [[ $train_unet_only == 1 ]]; then extArgs+=("--network_train_unet_only"); fi
79
+
80
+ if [[ $train_text_encoder_only == 1 ]]; then extArgs+=("--network_train_text_encoder_only"); fi
81
+
82
+ if [[ $network_weights ]]; then extArgs+=("--network_weights $network_weights"); fi
83
+
84
+ if [[ $reg_data_dir ]]; then extArgs+=("--reg_data_dir $reg_data_dir"); fi
85
+
86
+ if [[ $optimizer_type ]]; then extArgs+=("--optimizer_type $optimizer_type"); fi
87
+
88
+ if [[ $optimizer_type == "DAdaptation" ]]; then extArgs+=("--optimizer_args decouple=True"); fi
89
+
90
+ if [[ $save_state == 1 ]]; then extArgs+=("--save_state"); fi
91
+
92
+ if [[ $resume ]]; then extArgs+=("--resume $resume"); fi
93
+
94
+ if [[ $persistent_data_loader_workers == 1 ]]; then extArgs+=("--persistent_data_loader_workers"); fi
95
+
96
+ if [[ $network_module == "lycoris.kohya" ]]; then
97
+ extArgs+=("--network_args conv_dim=$conv_dim conv_alpha=$conv_alpha algo=$algo dropout=$dropout")
98
+ fi
99
+
100
+ if [[ $stop_text_encoder_training -ne 0 ]]; then extArgs+=("--stop_text_encoder_training $stop_text_encoder_training"); fi
101
+
102
+ if [[ $noise_offset != "0" ]]; then extArgs+=("--noise_offset $noise_offset"); fi
103
+
104
+ if [[ $min_snr_gamma -ne 0 ]]; then extArgs+=("--min_snr_gamma $min_snr_gamma"); fi
105
+
106
+ accelerate launch ${launchArgs[@]} --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" \
107
+ --enable_bucket \
108
+ --pretrained_model_name_or_path=$pretrained_model \
109
+ --train_data_dir=$train_data_dir \
110
+ --output_dir="./output" \
111
+ --logging_dir="./logs" \
112
+ --log_prefix=$output_name \
113
+ --resolution=$resolution \
114
+ --network_module=$network_module \
115
+ --max_train_epochs=$max_train_epoches \
116
+ --learning_rate=$lr \
117
+ --unet_lr=$unet_lr \
118
+ --text_encoder_lr=$text_encoder_lr \
119
+ --lr_scheduler=$lr_scheduler \
120
+ --lr_warmup_steps=$lr_warmup_steps \
121
+ --lr_scheduler_num_cycles=$lr_restart_cycles \
122
+ --network_dim=$network_dim \
123
+ --network_alpha=$network_alpha \
124
+ --output_name=$output_name \
125
+ --train_batch_size=$batch_size \
126
+ --save_every_n_epochs=$save_every_n_epochs \
127
+ --mixed_precision="fp16" \
128
+ --save_precision="fp16" \
129
+ --seed="1337" \
130
+ --cache_latents \
131
+ --prior_loss_weight=1 \
132
+ --max_token_length=225 \
133
+ --caption_extension=".txt" \
134
+ --save_model_as=$save_model_as \
135
+ --min_bucket_reso=$min_bucket_reso \
136
+ --max_bucket_reso=$max_bucket_reso \
137
+ --keep_tokens=$keep_tokens \
138
+ --xformers --shuffle_caption ${extArgs[@]}
train_by_toml.ps1 ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LoRA train script by @Akegarasu
2
+
3
+ $multi_gpu = 0 # multi gpu | ���Կ�ѵ�� �ò����������Կ��� >= 2 ʹ��
4
+ $config_file = "./toml/default.toml" # config_file | ʹ��toml�ļ�ָ��ѵ������
5
+ $sample_prompts = "./toml/sample_prompts.txt" # sample_prompts | ����prompts�ļ�,���������ò�������
6
+ $utf8 = 1 # utf8 | ʹ��utf-8�����ȡtoml����utf-8�����д�ġ������ĵ�toml���뿪��
7
+
8
+
9
+ # ============= DO NOT MODIFY CONTENTS BELOW | �����޸��·����� =====================
10
+
11
+ # Activate python venv
12
+ .\venv\Scripts\activate
13
+
14
+ $Env:HF_HOME = "huggingface"
15
+
16
+ $ext_args = [System.Collections.ArrayList]::new()
17
+ $launch_args = [System.Collections.ArrayList]::new()
18
+
19
+ if ($multi_gpu) {
20
+ [void]$launch_args.Add("--multi_gpu")
21
+ }
22
+ if ($utf8 -eq 1) {
23
+ $Env:PYTHONUTF8 = 1
24
+ }
25
+
26
+ # run train
27
+ accelerate launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" `
28
+ --config_file=$config_file `
29
+ --sample_prompts=$sample_prompts `
30
+ $ext_args
31
+
32
+ Write-Output "Train finished"
33
+ Read-Host | Out-Null ;
train_by_toml.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # LoRA train script by @Akegarasu
3
+
4
+ multi_gpu=0 # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用
5
+ config_file="./toml/default.toml" # config_file | 使用toml文件指定训练参数
6
+ sample_prompts="./toml/sample_prompts.txt" # sample_prompts | 采样prompts文件,留空则不启用采样功能
7
+ utf8=1 # utf8 | 使用utf-8编码读取toml;以utf-8编码编写的、含中文的toml必须开启
8
+
9
+ # ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================
10
+
11
+ export HF_HOME="huggingface"
12
+ export TF_CPP_MIN_LOG_LEVEL=3
13
+
14
+ extArgs=()
15
+ launchArgs=()
16
+
17
+ if [[ $multi_gpu == 1 ]]; then launchArgs+=("--multi_gpu"); fi
18
+ if [[ $utf8 == 1 ]]; then export PYTHONUTF8=1; fi
19
+
20
+ # run train
21
+ accelerate launch ${launchArgs[@]} --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" \
22
+ --config_file=$config_file \
23
+ --sample_prompts=$sample_prompts \
24
+ ${extArgs[@]}