File size: 6,429 Bytes
9287a32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d520cdce-6234-40b8-9a6d-c0d073249e62",
   "metadata": {},
   "source": [
    "**此代码适用于新镜像:192.168.204.22:5000/default-workspace/99280a9940ae44ca8f5892134386fddb/image:sd_final**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a48381fe",
   "metadata": {},
   "source": [
    "# 首次使用先复制镜像(左侧目录有sd就不用按这个):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "145e099f",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "#复制镜像\n",
    "!cp -r /sd /code\n",
    "!cp /t/lora/sd-models/131-half.safetensors /code/sd/models/Stable-diffusion\n",
    "!echo \"finish-copy\"\n",
    "#查看显卡\n",
    "!echo 你的GPU是:& nvidia-smi -L"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca9e8951-2c27-4241-b2dd-27ed20aa748f",
   "metadata": {},
   "source": [
    "# 30min定时关机脚本:(无限白嫖GPU):\n",
    "### **详细见**:https://github.com/2575044704/auto_shutdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2a91be9-3337-443f-b8e0-1617a2486ef3",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import subprocess\n",
    "try:\n",
    "    process = subprocess.Popen([\"bash\", \"shutdown.sh\"])\n",
    "    print(\"自动关机脚本已启动\")\n",
    "except Exception as e:\n",
    "    print(f\"启动自动关机脚本失败,错误:{e}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9459c185",
   "metadata": {},
   "source": [
    "# SD启动:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84f9609a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%cd /code/sd\n",
    "import os\n",
    "package_envs = [\n",
    "    {\"env\": \"STABLE_DIFFUSION_REPO\", \"url\": os.environ.get('STABLE_DIFFUSION_REPO', \"https://gitcode.net/overbill1683/stablediffusion\")},\n",
    "    {\"env\": \"STABLE_DIFFUSION_XL_REPO\", \"url\": os.environ.get('STABLE_DIFFUSION_XL_REPO', \"https://gitcode.net/overbill1683/generative-models\")},\n",
    "    {\"env\": \"K_DIFFUSION_REPO\", \"url\": os.environ.get('K_DIFFUSION_REPO', \"https://gitcode.net/overbill1683/k-diffusion\")},\n",
    "    {\"env\": \"CODEFORMER_REPO\", \"url\": os.environ.get('CODEFORMER_REPO', \"https://gitcode.net/overbill1683/CodeFormer\")},\n",
    "    {\"env\": \"BLIP_REPO\", \"url\": os.environ.get('BLIP_REPO', \"https://gitcode.net/overbill1683/BLIP\")},\n",
    "]\n",
    "os.environ[\"PIP_INDEX_URL\"] = \"https://mirrors.aliyun.com/pypi/simple/\"\n",
    "for i in package_envs:\n",
    "    os.environ[i[\"env\"]] = i[\"url\"]\n",
    "    \n",
    "# 请记得填写ngrok token\n",
    "!python launch.py --ngrok=你的token --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9eeb5985",
   "metadata": {},
   "source": [
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e26887f",
   "metadata": {},
   "source": [
    "# 下载模型,直接把模型下载地址粘贴进去\n",
    "# 支持的模型下载站:liblib.ai, tusiart.com, Huggingface镜像站\n",
    "# 不支持的:Civitai,\n",
    "## HUggingface镜像站:huggingface.sukaka.top\n",
    "## 必须先把SD停下来再执行代码!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c3e8600",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 下载 模型\n",
    "urls = ['https://huggingface.sukaka.top/datasets/ACCC1380/private-model/resolve/main/ba.safetensors']\n",
    "\n",
    "下载目录 = '/code/sd/models/Lora'\n",
    "\n",
    "文件名 = \"wodemoxing.safetensors\"\n",
    "# SD大模型目录 :/code/sd/models/Lora\n",
    "# Lora目录:/code/sd/models/Lora\n",
    "# VAE目录:/code/sd/models/VAE\n",
    "\n",
    "%cd {下载目录}\n",
    "for url in urls:\n",
    "    !aria2c -x 16 -s 16 -c -k 1M --console-log-level=error \"{url}\" -o \"{文件名}\"\n",
    "%cd /code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6098be12",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 安装常用插件,github如果连不上就多执行几次\n",
    "extensions = [\n",
    "\"https://gitcode.net/ranting8323/sd-webui-controlnet\",\n",
    "]\n",
    "%cd /code/sd\n",
    "\n",
    "for e in extensions:\n",
    "    proxied_url =  e\n",
    "    !git -C \"extensions\" clone {proxied_url}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17062dc1-2083-41fb-9a67-5a9f623b1276",
   "metadata": {},
   "source": [
    "------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a69b680b-c87d-4219-9eec-d69baec9f2c9",
   "metadata": {},
   "source": [
    "# 下面代码是启动秋叶的Lora训练器:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d89e635-77a2-4c18-b126-e914e30d8841",
   "metadata": {},
   "source": [
    "# 1.拉取lora训练文件(首次启动)(左侧有lora文件夹就不用拉取)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "451c1e08-7eb0-4dab-92e2-6f7879f68c08",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "!cp -r /t/lora/ /code"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f2ae3fa-1729-4a58-8e6f-92cfd1c12597",
   "metadata": {},
   "source": [
    "# 2. 启动Lora训练器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f53478e-1788-45d1-9a12-a757f81edde5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 先配置ngrok再启动!!,启动后找到ngrok链接即可!\n",
    "import os\n",
    "%cd /code/lora\n",
    "!/code/lora/venv/bin/python gui.py --disable-dataset-tag-editor & ngrok http 28000 --authtoken=你的ngroktoken"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}