Upload lora-scripts/train.ipynb with huggingface_hub
Browse files- lora-scripts/train.ipynb +99 -0
lora-scripts/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 |
+
}
|