File size: 9,005 Bytes
9743213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c290d1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ceedd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9743213
 
 
 
 
 
 
 
 
 
b482793
9743213
 
 
 
 
 
 
 
 
3ceedd5
9743213
 
 
b482793
 
 
 
 
9743213
 
 
b482793
9743213
b482793
3ceedd5
b482793
 
 
3ceedd5
9743213
 
b482793
9743213
 
 
b482793
 
 
 
 
9743213
 
 
 
 
3ceedd5
9743213
 
 
3ceedd5
 
b482793
 
9743213
 
cb343fc
 
 
 
 
 
 
 
 
 
 
9743213
 
 
3ceedd5
9743213
 
cb6230f
3ceedd5
 
 
 
b482793
3ceedd5
c290d1b
3ceedd5
 
 
cb6230f
cb343fc
 
 
 
 
 
 
 
 
 
9743213
 
 
 
cb6230f
9743213
 
 
 
 
 
 
 
 
 
 
 
 
cb6230f
 
 
 
 
 
9743213
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cd9b419-e368-4416-9ec8-370de5db7e22",
   "metadata": {},
   "outputs": [],
   "source": [
    "# web-uiのインストール ※初回のみ実行\n",
    "%cd /notebooks\n",
    "!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n",
    "%cd /notebooks/stable-diffusion-webui"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7754e8bf-d149-4e3e-9115-e954639c1a12",
   "metadata": {},
   "outputs": [],
   "source": [
    "# googleドライブからファイルダウンロードするのに必要なツールのインストール ※初回のみ実行\n",
    "!pip install gdown\n",
    "!pip install --upgrade gdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fe03bfa",
   "metadata": {},
   "outputs": [],
   "source": [
    "# install xformers\n",
    "# https://rentry.co/paperspace_de_xformers\n",
    "from pathlib import Path\n",
    "%cd /notebooks/\n",
    "! mkdir lora\n",
    "\n",
    "%cd lora\n",
    "! git clone https://github.com/kohya-ss/sd-scripts.git\n",
    "! git clone https://github.com/derrian-distro/LoRA_Easy_Training_Scripts.git\n",
    "\n",
    "%cd /notebooks/lora/sd-scripts\n",
    "! cp ~/LoRA_Easy_Training_Scripts/lora_train_command_line.py ./\n",
    "! apt install python3.10 python3.10-dev -y\n",
    "! pip3.10 install setuptools\n",
    "! apt autoremove python3-yaml python3-lxml --purge -y\n",
    "! curl https://bootstrap.pypa.io/get-pip.py | python3.10\n",
    "! pip3.10 install lxml\n",
    "! pip3.10 install -U torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116\n",
    "! pip3.10 install `grep 'fairscale==' requirements.txt` --no-build-isolation\n",
    "! pip3.10 install gradio==3.16.2 altair==4.2.2 easygui requests timm==0.4.12 \"tensorflow<2.11\" huggingface-hub\n",
    "! pip3.10 install -r requirements.txt\n",
    "! pip3.10 install -U --pre triton\n",
    "! pip3.10 uninstall accelerate -y;pip3.10 install accelerate\n",
    "! pip3.10 install -U https://github.com/ninele7/xfromers_builds/releases/download/3393900949/xformers-0.0.14.dev0-cp310-cp310-linux_x86_64.whl\n",
    "! sed -i 's/^accelerate.*//g' /notebooks/stable-diffusion-webui/requirements_versions.txt\n",
    "d = Path(\"/root/.cache/huggingface/accelerate\")\n",
    "if not d.exists():\n",
    "    d.mkdir(parents=True)\n",
    "p = d / Path(\"default_config.yaml\")\n",
    "p.write_text(\"\"\"command_file: null\n",
    "commands: null\n",
    "compute_environment: LOCAL_MACHINE\n",
    "deepspeed_config: {}\n",
    "distributed_type: 'NO'\n",
    "downcast_bf16: 'no'\n",
    "dynamo_backend: 'NO'\n",
    "fsdp_config: {}\n",
    "gpu_ids: all\n",
    "machine_rank: 0\n",
    "main_process_ip: null\n",
    "main_process_port: null\n",
    "main_training_function: main\n",
    "megatron_lm_config: {}\n",
    "mixed_precision: fp16\n",
    "num_machines: 1\n",
    "num_processes: 1\n",
    "rdzv_backend: static\n",
    "same_network: true\n",
    "tpu_name: null\n",
    "tpu_zone: null\n",
    "use_cpu: false\"\"\")\n",
    "\n",
    "! echo FINISHED!\n",
    "! date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22601392",
   "metadata": {},
   "outputs": [],
   "source": [
    "# install extensions\n",
    "%cd /notebooks/stable-diffusion-webui/extensions\n",
    "!git clone https://github.com/kohya-ss/sd-webui-additional-networks\n",
    "!git clone https://github.com/Mikubill/sd-webui-controlnet.git\n",
    "!git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser\t\n",
    "!git clone https://github.com/toriato/stable-diffusion-webui-wd14-tagger.git\n",
    "!git clone https://github.com/toriato/stable-diffusion-webui-daam.git"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f34e111a-28d7-456e-bb38-c142c781a680",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 各モデルのダウンロード ※初回のみ実行\n",
    "# ※なにかしらのモデルが入っていないとweb-uiは起動しません\n",
    "%cd /notebooks/stable-diffusion-webui/models/Stable-diffusion\n",
    "!curl -OL https://huggingface.co/Defpoint/Defmix-v2.0/resolve/main/Defmix-v2.0.safetensors # 2.1GB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0eb13e70",
   "metadata": {},
   "outputs": [],
   "source": [
    "## download models\n",
    "\n",
    "### CKPT\n",
    "%cd /notebooks/stable-diffusion-webui/models/Stable-diffusion/\n",
    "#!curl -OL https://huggingface.co/syaimu/7th_Layer/resolve/main/7th_anime_v3/7th_anime_v3_B.safetensors # \n",
    "#!curl -OL https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/Models/AbyssOrangeMix3/AOM3A1.safetensors # 2.13 GB\n",
    "#!curl -OL https://huggingface.co/gsdf/Counterfeit-V2.5/resolve/main/Counterfeit-V2.5.safetensors # 7.7 GB\n",
    "#!curl -OL https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/Models/ElyOrangeMix/ElyNightOrangeMix.ckpt # 4.27 GB\n",
    "#!curl -OL https://huggingface.co/Defpoint/Defmix-v2.0/resolve/main/Defmix-v2.0.safetensors # 2.1GB\n",
    "\n",
    "### VAE\n",
    "%cd /notebooks/stable-diffusion-webui/models/VAE/\n",
    "!curl -OL https://huggingface.co/andite/anything-v4.0/resolve/main/anything-v4.0.vae.pt\n",
    "\n",
    "### EMBEDDING\n",
    "%cd /notebooks/stable-diffusion-webui/embeddings/\n",
    "#!curl -OL https://huggingface.co/datasets/Nerfgun3/bad_prompt/resolve/main/bad_prompt_version2.pt\n",
    "!curl -OL https://huggingface.co/datasets/gsdf/EasyNegative/resolve/main/EasyNegative.safetensors\n",
    "#!curl -OL https://huggingface.co/nick-x-hacker/bad-artist/resolve/main/bad-artist.pt\n",
    "\n",
    "### LoRA\n",
    "%cd /notebooks/stable-diffusion-webui/extensions/sd-webui-additional-networks/models/lora/\n",
    "#!curl -OL https://huggingface.co/yui-futao/LoRA-fto/resolve/main/fto-v43.safetensors\n",
    "\n",
    "### ControlNet\n",
    "%cd /notebooks/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
    "#!curl -OL https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_canny-fp16.safetensors\n",
    "#!curl -OL https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_depth-fp16.safetensors\n",
    "#!curl -OL https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_normal-fp16.safetensors\n",
    "#!curl -OL https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_openpose-fp16.safetensors\n",
    "#!curl -OL https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_seg-fp16.safetensors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d7a0b98-720c-4d6f-bf51-966114128c63",
   "metadata": {},
   "outputs": [],
   "source": [
    "# config.json の復元\n",
    "%cd /notebooks/stable-diffusion-webui/\n",
    "!curl -OL https://huggingface.co/datasets/yui-futao/notebooks/raw/main/config.json\n",
    "!curl -OL https://huggingface.co/datasets/yui-futao/notebooks/raw/main/ui-config.json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "837b2843",
   "metadata": {},
   "outputs": [],
   "source": [
    "!cd; git clone https://github.com/doHub1/dotfiles.git; cd dotfiles; bash install.sh; cd /notebooks/ #DOT\n",
    "!cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime #TZ=JST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca0e037f-4f6d-4122-9b4e-0ce8853e2bf3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# web-uiの起動\n",
    "# ログイン用のユーザーネームとパスワードは --gradio-auth ユーザーネーム:パスワード となる。書き換え推奨。\n",
    "%cd /notebooks/stable-diffusion-webui\n",
    "!python launch.py\\\n",
    "--gradio-auth <gradio_username>:<gradio_password>\\\n",
    "--share\\\n",
    "--xformers\\\n",
    "--no-half-vae\\\n",
    "--skip-version-check\\\n",
    "--enable-insecure-extension-access"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a9b447c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "!watch -d -n 10 \"ls -lh /notebooks/stable-diffusion-webui/outputs/ |grep 2023 & du -h /notebooks/stable-diffusion-webui/outputs/ |grep 2023\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  },
  "vscode": {
   "interpreter": {
    "hash": "3834a203b0427e23345e2285a24ec315196163d8a2ce1fe7c01f4ca5296d844c"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}