├── README.md ├── automatic1111.ipynb └── patches └── stablediffusion-lowram.patch /README.md: -------------------------------------------------------------------------------- 1 | # CoLab-compatible version of StableDiffusionWebui by Automatic1111 2 | 3 | [![](https://img.shields.io/static/v1?message=Open%20in%20Colab&logo=googlecolab&labelColor=5c5c5c&color=0f80c1&label=%20&style=for-the-badge)](https://colab.research.google.com/github/ddPn08/automatic1111-colab/blob/main/automatic1111.ipynb) 4 | 5 | # Wiki 6 | https://github.com/ddPn08/automatic1111-colab/wiki 7 | 8 | # Features 9 | - Xformers support 10 | - Using Miniconda to make Xformers available. 11 | - Fast setup 12 | - If you have space in Google Drive, you can save your environment for faster setup. 13 | - Model download support 14 | - Any model on the internet can be downloaded by entering the URL 15 | - Google Drive support 16 | - You can also save output images, models, embeddings, configuration files, etc... 17 | - Low RAM patch 18 | - You can run models that require a lot of RAM, such as StableDiffusion 2.1, even with the free Colab. 19 | - Advanced options 20 | - You can easily change advanced options by simply clicking a checkbox. 21 | 22 | # Respect 23 | [automatic1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 24 | -------------------------------------------------------------------------------- /automatic1111.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github", 7 | "colab_type": "text" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "id": "A6OFCYOzNjDX" 17 | }, 18 | "source": [ 19 | "# [Stable Diffusion WebUI Colab](https://github.com/ddPn08/stable-diffusion-webui-colab) by [ddPn08](https://github.com/ddpn08/)\n", 20 | "\n", 21 | "## Wiki\n", 22 | "https://github.com/ddPn08/automatic1111-colab/wiki\n", 23 | "\n", 24 | "
\n", 25 | "\n", 26 | "# Troubleshooting (不具合が発生したら)\n", 27 | "1. First, check the wiki and changelog. (まずは、Wikiと変更ログを確認してください。)\n", 28 | " - [Wiki](https://github.com/ddPn08/automatic1111-colab/wiki)\n", 29 | " - [CHANGELOG | 変更ログ](#scrollTo=moDR3lrJVsE8)\n", 30 | "\n", 31 | "2. If you still can't figure it out, open a Github issue. (それでもわからない場合はGithubのIssueを立ててください。)\n", 32 | " - [Github Issue](https://github.com/ddPn08/automatic1111-colab/issues/new)." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": { 39 | "id": "Y4xxtQfuJiWM" 40 | }, 41 | "outputs": [], 42 | "source": [ 43 | "! nvidia-smi\n", 44 | "! nvcc -V\n", 45 | "! free -h" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": { 51 | "id": "TE45Pqn_N81E" 52 | }, 53 | "source": [ 54 | "## 1 - Setup" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": { 60 | "id": "4cXkcQu6OEAu" 61 | }, 62 | "source": [ 63 | "### 1.1 Clone repository\n", 64 | "[Wiki / English](https://github.com/ddPn08/automatic1111-colab/wiki/1.-Setup-%7C-EN#11-clone-repository) - [Wiki / 日本語](https://github.com/ddPn08/automatic1111-colab/wiki/1.-Setup-%7C-JP#11-リポジトリのクローン)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": { 71 | "cellView": "form", 72 | "id": "yzdbQDudNZ6j" 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "%cd /content/\n", 77 | "repository_url = \"https://github.com/AUTOMATIC1111/stable-diffusion-webui\" # @param {type: \"string\"}\n", 78 | "webui_branch = \"master\" # @param {type: \"string\"}\n", 79 | "\n", 80 | "! git clone {repository_url}\n", 81 | "%cd /content/stable-diffusion-webui\n", 82 | "! git checkout {webui_branch}" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": { 88 | "id": "tOHgDng2c0FX" 89 | }, 90 | "source": [ 91 | "### 1.2 Setup models\n", 92 | "[Wiki / English](https://github.com/ddPn08/automatic1111-colab/wiki/1.-Setup-%7C-EN#12-setup-models) - [Wiki / 日本語](https://github.com/ddPn08/automatic1111-colab/wiki/1.-Setup-%7C-JP#12-モデルのセットアップ)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": { 99 | "cellView": "form", 100 | "id": "Mls4_48XOrTd" 101 | }, 102 | "outputs": [], 103 | "source": [ 104 | "# @markdown # Set up the StableDiffusion model.\n", 105 | "\n", 106 | "# @markdown ---\n", 107 | "\n", 108 | "%cd /content/\n", 109 | "\n", 110 | "data_dir = \"/content/data\" # @param {type:\"string\"}\n", 111 | "\n", 112 | "# @markdown **Optional | Download the model if it isn't already in the `{data_dir}/models` folder**\n", 113 | "\n", 114 | "# @markdown Get huggingface access token from [here](https://huggingface.co/settings/tokens)\n", 115 | "auth_token = \"\" # @param {type:\"string\"}\n", 116 | "\n", 117 | "download_if_missing = False # @param {type:\"boolean\"}\n", 118 | "# @markdown If you use the SD 2.1 model, select its config from the dropdown\n", 119 | "\n", 120 | "# @markdown model_url2, 3, config_url2, 3, vae_url2, 3 are option.
\n", 121 | "# @markdown If you have models, config or vae that you want to load at the same time, please enter them.\n", 122 | "model_url = \"https://huggingface.co/dreamlike-art/dreamlike-anime-1.0/resolve/main/dreamlike-anime-1.0.safetensors\" #@param [\"https://huggingface.co/dreamlike-art/dreamlike-anime-1.0/resolve/main/dreamlike-anime-1.0.safetensors\", \"https://huggingface.co/AdamOswald1/anything-v5.0/resolve/main/Anything-V3.0.ckpt\", \"https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt\", \"https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-ema-pruned.ckpt\"] {allow-input: true}\n", 123 | "model_url2 = \"\" #@param [\"https://huggingface.co/dreamlike-art/dreamlike-anime-1.0/resolve/main/dreamlike-anime-1.0.safetensors\", \"https://huggingface.co/AdamOswald1/anything-v5.0/resolve/main/Anything-V3.0.ckpt\", \"https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt\", \"https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-ema-pruned.ckpt\"] {allow-input: true}\n", 124 | "model_url3 = \"\" #@param [\"https://huggingface.co/dreamlike-art/dreamlike-anime-1.0/resolve/main/dreamlike-anime-1.0.safetensors\", \"https://huggingface.co/AdamOswald1/anything-v5.0/resolve/main/Anything-V3.0.ckpt\", \"https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt\", \"https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-ema-pruned.ckpt\"] {allow-input: true}\n", 125 | "\n", 126 | "config_url = \"\" #@param [\"\", \"https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference.yaml\"] {allow-input: true}\n", 127 | "config_url2 = \"\" #@param [\"\", \"https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference.yaml\"] {allow-input: true}\n", 128 | "config_url3 = \"\" #@param [\"\", \"https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference.yaml\"] {allow-input: true}\n", 129 | "\n", 130 | "use_vae = False # @param {type:\"boolean\"}\n", 131 | "vae_url = \"https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt\" #@param [\"https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt\"] {allow-input: true}\n", 132 | "vae_url2 = \"\" #@param [\"https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt\"] {allow-input: true}\n", 133 | "vae_url3 = \"\" #@param [\"https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt\"] {allow-input: true}\n", 134 | "\n", 135 | "urls = [model_url, model_url2, model_url3, config_url, config_url2, config_url3]\n", 136 | "vae_urls = [vae_url, vae_url2, vae_url3]\n", 137 | "\n", 138 | "# @markdown **Optional | Use Google Drive**\n", 139 | "mount_google_drive = True # @param {type:\"boolean\"}\n", 140 | "data_dir_gdrive = \"/content/drive/MyDrive/AI/automatic1111\" # @param {type:\"string\"}\n", 141 | "# @markdown If you load multiple models/config/vae, it is recommended to check force_model_download_locally\n", 142 | "force_model_download_locally = False # @param {type:\"boolean\"}\n", 143 | "force_remount = False # @param {type:\"boolean\"}\n", 144 | "\n", 145 | "import os\n", 146 | "\n", 147 | "mount_success = False\n", 148 | "drive_path = \"/content/drive\"\n", 149 | "if mount_google_drive and not os.path.exists(drive_path):\n", 150 | " from google.colab import drive\n", 151 | "\n", 152 | " try:\n", 153 | " drive.mount(drive_path, force_remount=force_remount)\n", 154 | " os.makedirs(data_dir_gdrive, exist_ok=True)\n", 155 | " ! rm -Rf {data_dir} && ln -s {data_dir_gdrive} {data_dir}\n", 156 | " mount_success = True\n", 157 | " except:\n", 158 | " print(\"...error mounting drive or with drive path variables\")\n", 159 | " print(\"...reverting to default path variables\")\n", 160 | "\n", 161 | "if os.path.exists(f\"{data_dir}/script.pre.sh\"):\n", 162 | " ! chmod +x {data_dir}/script.pre.sh\n", 163 | " ! {data_dir}/script.pre.sh\n", 164 | "\n", 165 | "models_path = f\"{data_dir}/models\"\n", 166 | "output_path = f\"{data_dir}/outputs\"\n", 167 | "config_path = f\"{data_dir}/config\"\n", 168 | "scripts_path = f\"{data_dir}/scripts\"\n", 169 | "extensions_file_path = f\"{data_dir}/extensions.txt\"\n", 170 | "\n", 171 | "if force_model_download_locally:\n", 172 | " models_path = \"/content/models\"\n", 173 | "\n", 174 | "os.makedirs(models_path, exist_ok=True)\n", 175 | "os.makedirs(output_path, exist_ok=True)\n", 176 | "os.makedirs(config_path, exist_ok=True)\n", 177 | "os.makedirs(scripts_path, exist_ok=True)\n", 178 | "os.makedirs(f\"{models_path}/embeddings\", exist_ok=True)\n", 179 | "os.makedirs(f\"{models_path}/Stable-diffusion\", exist_ok=True)\n", 180 | "os.makedirs(f\"{models_path}/VAE\", exist_ok=True)\n", 181 | "os.makedirs(f\"{models_path}/hypernetworks\", exist_ok=True)\n", 182 | "os.makedirs(f\"{models_path}/dreambooth\", exist_ok=True)\n", 183 | "os.makedirs(f\"{models_path}/Lora\", exist_ok=True)\n", 184 | "\n", 185 | "for script in os.listdir(scripts_path):\n", 186 | " ! rm -Rf stable-diffusion-webui/scripts/{script} && ln -s {scripts_path}/{script} stable-diffusion-webui/scripts/{script}\n", 187 | "\n", 188 | "for dir in os.listdir(models_path):\n", 189 | " if dir == \"embeddings\":\n", 190 | " ! rm -Rf stable-diffusion-webui/embeddings && ln -s {models_path}/embeddings stable-diffusion-webui/embeddings\n", 191 | " else:\n", 192 | " ! rm -Rf stable-diffusion-webui/models/{dir} && ln -s {models_path}/{dir} stable-diffusion-webui/models/{dir}\n", 193 | "\n", 194 | "! rm -Rf stable-diffusion-webui/outputs && ln -s {data_dir}/outputs stable-diffusion-webui/outputs\n", 195 | "\n", 196 | "for filename in [\"config.json\", \"ui-config.json\"]:\n", 197 | " ! rm -f stable-diffusion-webui/{filename}\n", 198 | " filepath = f\"{config_path}/{filename}\"\n", 199 | " if not os.path.exists(filepath):\n", 200 | " if filename.endswith(\".json\"):\n", 201 | " with open(filepath, mode=\"w\") as f:\n", 202 | " f.write(\"{}\")\n", 203 | " else:\n", 204 | " ! touch {config_path}/{filename}\n", 205 | " ! ln -s {config_path}/{filename} stable-diffusion-webui/{filename}\n", 206 | "\n", 207 | "if download_if_missing:\n", 208 | " for url in urls:\n", 209 | " filename = url.split(\"/\")[-1]\n", 210 | " if not os.path.exists(f\"{models_path}/Stable-diffusion/{filename}\"):\n", 211 | " ! curl -LJ {url} -o {models_path}/Stable-diffusion/{filename} {'-H \"Authorization: Bearer ' + auth_token + '\"' if auth_token else \"\"}\n", 212 | " if use_vae:\n", 213 | " for vae_url in vae_urls:\n", 214 | " vae_filename = vae_url.split(\"/\")[-1]\n", 215 | " if not os.path.exists(f\"{models_path}/VAE/{vae_filename}\"):\n", 216 | " ! curl -LJ {vae_url} -o {models_path}/VAE/{vae_filename} {'-H \"Authorization: Bearer ' + auth_token + '\"' if auth_token else \"\"}" 217 | ] 218 | }, 219 | { 220 | "cell_type": "markdown", 221 | "metadata": { 222 | "id": "3JkrcrPBza-M" 223 | }, 224 | "source": [ 225 | "## 2 - Advanced - Launch preferences\n", 226 | "[Wiki / English](https://github.com/ddPn08/automatic1111-colab/wiki/2.-Launch-preferences-%7C-EN#2-launch-preferences) - [Wiki / 日本語](https://github.com/ddPn08/automatic1111-colab/wiki/2.-Launch-preferences-%7C-JP#2-起動設定)" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": null, 232 | "metadata": { 233 | "id": "goUvyTZ4zd4l", 234 | "cellView": "form" 235 | }, 236 | "outputs": [], 237 | "source": [ 238 | "# @markdown ## Command line arguments\n", 239 | "\n", 240 | "import os\n", 241 | "\n", 242 | "no_half = False # @param {type:\"boolean\"}\n", 243 | "no_half_vae = True # @param {type:\"boolean\"}\n", 244 | "allow_code = False # @param {type:\"boolean\"}\n", 245 | "no_progressbar_hiding = False # @param {type:\"boolean\"}\n", 246 | "medvram = False # @param {type:\"boolean\"}\n", 247 | "lowvram = False # @param {type:\"boolean\"}\n", 248 | "deepdanbooru = False # @param {type:\"boolean\"}\n", 249 | "xformers = False # @param {type:\"boolean\"}\n", 250 | "disable_opt_split_attention = False # @param {type:\"boolean\"}\n", 251 | "gradio_queue = True # @param {type:\"boolean\"}\n", 252 | "\n", 253 | "# @markdown
\n", 254 | "custom_arguments = \"\" # @param {type:\"string\"}\n", 255 | "\n", 256 | "run_string_with_variables = {\n", 257 | " \"--no-half\": f\"{no_half}\",\n", 258 | " \"--no-half-vae\": f\"{no_half_vae}\",\n", 259 | " \"--allow-code\": f\"{allow_code}\",\n", 260 | " \"--no-progressbar-hiding\": f\"{no_progressbar_hiding}\",\n", 261 | " \"--medvram\": f\"{medvram}\",\n", 262 | " \"--lowvram\": f\"{lowvram}\",\n", 263 | " \"--deepdanbooru\": f\"{deepdanbooru}\",\n", 264 | " \"--xformers\": f\"{xformers}\",\n", 265 | " \"--disable-opt-split-attention\": f\"{disable_opt_split_attention}\",\n", 266 | "}\n", 267 | "\n", 268 | "if use_vae:\n", 269 | " for vae_url in vae_urls:\n", 270 | " vae_filename = vae_url.split(\"/\")[-1]\n", 271 | " if os.path.exists(f\"{models_path}/VAE/{vae_filename}\") and vae_filename:\n", 272 | " key = \"--vae-path /content/stable-diffusion-webui/models/VAE/\" + vae_filename\n", 273 | " run_string_with_variables[key] = f\"{use_vae}\"\n", 274 | "\n", 275 | "advanced_options = {k for (k, v) in run_string_with_variables.items() if v == \"True\"}\n", 276 | "\n", 277 | "# @markdown
\n", 278 | "\n", 279 | "# @markdown ## Enable password authentication (Prevent other users from using the WebUI)\n", 280 | "\n", 281 | "# @markdown
\n", 282 | "\n", 283 | "use_gradio_auth = False # @param {type:\"boolean\"}\n", 284 | "gradio_auth_username = \"username\" # @param {type:\"string\"}\n", 285 | "gradio_auth_password = \"password\" # @param {type:\"string\"}\n", 286 | "\n", 287 | "# @markdown
\n", 288 | "\n", 289 | "# @markdown # Advanced | Network preferences\n", 290 | "\n", 291 | "# @markdown
\n", 292 | "\n", 293 | "# @markdown ## Optional | Ngrok Tunnel\n", 294 | "# @markdown Get token from [here](https://dashboard.ngrok.com/get-started/your-authtoken)\n", 295 | "use_ngrok = False # @param {type: \"boolean\"}\n", 296 | "load_token_from_gdrive = True # @param {type:\"boolean\"}\n", 297 | "ngrok_auth_token = \"\" # @param {type: \"string\"}\n", 298 | "ngrok_region = \"default\" # @param [\"default\", \"us\", \"eu\", \"au\", \"ap\", \"sa\", \"jp\", \"in\"]\n", 299 | "\n", 300 | "if os.path.exists(f\"{data_dir}/ngrok.txt\") and use_ngrok:\n", 301 | " with open(f\"{data_dir}/ngrok.txt\", mode=\"r\") as f:\n", 302 | " lines = f.readlines()\n", 303 | " if not ngrok_auth_token and len(lines) > 0:\n", 304 | " ngrok_auth_token = lines[0].strip()\n", 305 | " if ngrok_region == \"default\" and len(lines) > 1:\n", 306 | " ngrok_region = lines[1].strip()\n", 307 | "\n", 308 | "with open(f\"{data_dir}/ngrok.txt\", mode=\"w\") as f:\n", 309 | " f.write(f\"{ngrok_auth_token}\\n{ngrok_region}\")\n", 310 | "\n", 311 | "if not ngrok_region or ngrok_region == \"default\":\n", 312 | " ngrok_region = \"us\"\n", 313 | "\n", 314 | "# @markdown
\n", 315 | "\n", 316 | "# @markdown ## Extensions\n", 317 | "load_extensions_from_gdrive = True # @param {type:\"boolean\"}\n", 318 | "extensions = \"https://github.com/yfszzx/stable-diffusion-webui-images-browser, https://github.com/DominikDoom/a1111-sd-webui-tagcomplete\" # @param {type:\"string\"}\n", 319 | "extensions = list(map(str.strip, extensions.split(\",\")))\n", 320 | "\n", 321 | "# @markdown
\n", 322 | "\n", 323 | "# @markdown ## Save extensions to Google Drive\n", 324 | "# @markdown **Deprecated** (Unexpected errors may occur)\n", 325 | "save_extensions_to_gdrive = False # @param {type:\"boolean\"}\n", 326 | "\n", 327 | "if save_extensions_to_gdrive:\n", 328 | " os.makedirs(f\"{data_dir}/extensions\", exist_ok=True)\n", 329 | " ! rm -Rf stable-diffusion-webui/extensions && ln -s {data_dir}/extensions stable-diffusion-webui/extensions\n", 330 | "\n", 331 | "if load_extensions_from_gdrive and extensions_file_path:\n", 332 | " if os.path.exists(extensions_file_path):\n", 333 | " with open(extensions_file_path, mode=\"r\") as f:\n", 334 | " for s in f:\n", 335 | " url = s.strip()\n", 336 | " if url not in extensions:\n", 337 | " extensions.append(url)\n", 338 | " with open(extensions_file_path, mode=\"w+\") as f:\n", 339 | " f.write(\"\\n\".join(extensions))\n", 340 | "\n", 341 | "share_args = f\" --share {'--gradio-queue' if gradio_queue else ''}\"\n", 342 | "\n", 343 | "vars = \" \".join(advanced_options)\n", 344 | "if not use_ngrok:\n", 345 | " vars += share_args\n", 346 | "elif ngrok_auth_token and ngrok_region:\n", 347 | " vars += f\" --ngrok {ngrok_auth_token} --ngrok-region {ngrok_region}\"\n", 348 | "elif not ngrok_auth_token or not ngrok_region:\n", 349 | " vars += share_args\n", 350 | "\n", 351 | "if use_gradio_auth:\n", 352 | " vars += f\" --gradio-auth {gradio_auth_username}:{gradio_auth_password}\"\n", 353 | "\n", 354 | "vars += f\" --styles-file {data_dir}/config/styles.csv\"\n", 355 | "\n", 356 | "os.environ[\"COMMANDLINE_ARGS\"] = f\"{vars} {custom_arguments}\"" 357 | ] 358 | }, 359 | { 360 | "cell_type": "markdown", 361 | "metadata": { 362 | "id": "htQtwGXHTaob" 363 | }, 364 | "source": [ 365 | "## 3 - Launch WebUI\n", 366 | "[Wiki / English](https://github.com/ddPn08/automatic1111-colab/wiki/3.-Run-%7C-EN#set-up-the-environment) - [Wiki / 日本語](https://github.com/ddPn08/automatic1111-colab/wiki/3.-Run-%7C-JP)" 367 | ] 368 | }, 369 | { 370 | "cell_type": "code", 371 | "execution_count": null, 372 | "metadata": { 373 | "id": "Ao2t5h5qG9HD", 374 | "cellView": "form" 375 | }, 376 | "outputs": [], 377 | "source": [ 378 | "# @markdown ## Setup environment\n", 379 | "# @markdown This may take up to 5 minutes\n", 380 | "\n", 381 | "\n", 382 | "%cd /content/stable-diffusion-webui/extensions\n", 383 | "\n", 384 | "import os\n", 385 | "import sys\n", 386 | "\n", 387 | "for extension in extensions:\n", 388 | " if extension.startswith(\"#\"):\n", 389 | " continue\n", 390 | " ! git clone {extension}\n", 391 | " extension_name, _ = os.path.splitext(extension.split(\"/\")[-1])\n", 392 | " if not os.path.isdir(extension_name):\n", 393 | " ! git clone {extension}\n", 394 | " else:\n", 395 | " ! cd {extension_name} && git fetch\n", 396 | "\n", 397 | "%cd /content\n", 398 | "\n", 399 | "conda_dir = \"/opt/conda\" # @param{type:\"string\"}\n", 400 | "conda_bin = os.path.join(conda_dir, \"bin\", \"conda\")\n", 401 | "\n", 402 | "if not os.path.exists(conda_bin):\n", 403 | " ! curl -O https://repo.anaconda.com/miniconda/Miniconda3-py310_24.9.2-0-Linux-x86_64.sh\n", 404 | " ! chmod +x Miniconda3-py310_24.9.2-0-Linux-x86_64.sh\n", 405 | " ! bash ./Miniconda3-py310_24.9.2-0-Linux-x86_64.sh -b -f -p {conda_dir}\n", 406 | " ! rm Miniconda3-py310_24.9.2-0-Linux-x86_64.sh\n", 407 | "\n", 408 | "\n", 409 | "install_script = f\"\"\"\n", 410 | "eval \"$({conda_bin} shell.bash hook)\"\n", 411 | "cd stable-diffusion-webui\n", 412 | "python3 -m pip install --upgrade tensorrt triton\n", 413 | "python -c 'from launch import prepare_environment; prepare_environment()'\n", 414 | "\"\"\"\n", 415 | "\n", 416 | "! {install_script}\n", 417 | "\n", 418 | "# @markdown \n", 419 | "# @markdown ## Optional | Apply low RAM patch\n", 420 | "apply_lowram_patch = True # @param {type: \"boolean\"}\n", 421 | "\n", 422 | "if apply_lowram_patch:\n", 423 | " patches_dir = \"/content/patches\"\n", 424 | " os.makedirs(patches_dir, exist_ok=True)\n", 425 | " ! cd {patches_dir} && curl -LO https://raw.githubusercontent.com/ddPn08/automatic1111-colab/main/patches/stablediffusion-lowram.patch\n", 426 | " ! cd /content/stable-diffusion-webui/repositories/stable-diffusion-stability-ai && git apply {patches_dir}/stablediffusion-lowram.patch\n", 427 | "\n", 428 | "\n", 429 | "os.environ[\n", 430 | " \"LD_LIBRARY_PATH\"\n", 431 | "] = f\"{os.environ['LD_LIBRARY_PATH']}:/usr/local/envs/automatic/lib\"\n", 432 | "\n", 433 | "if os.path.exists(f\"{data_dir}/script.post.sh\"):\n", 434 | " ! chmod +x {data_dir}/script.post.sh\n", 435 | " ! {data_dir}/script.post.sh" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": null, 441 | "metadata": { 442 | "cellView": "form", 443 | "id": "Y4ebYsPqTrGb" 444 | }, 445 | "outputs": [], 446 | "source": [ 447 | "# @markdown # Run script\n", 448 | "# @markdown keep in mind that this script is set to run for ever.\n", 449 | "# @markdown > ※注意 このスクリプトは永久に実行されます。\n", 450 | "\n", 451 | "# @markdown \n", 452 | "\n", 453 | "# @markdown ### Important - click the public URL to launch WebUI in another tab\n", 454 | "# @markdown > ### 重要 - 公開URLをクリックしてWebUIを起動してください\n", 455 | "\n", 456 | "# @markdown ![](https://user-images.githubusercontent.com/71378929/189563599-6df78bcf-133b-41e8-a55d-8ca3783cd933.png)\n", 457 | "\n", 458 | "%cd /content/stable-diffusion-webui/\n", 459 | "! git pull\n", 460 | "\n", 461 | "run_script = f\"\"\"\n", 462 | "eval \"$({conda_bin} shell.bash hook)\"\n", 463 | "accelerate launch --num_cpu_threads_per_process 1 launch.py --disable-model-loading-ram-optimization\n", 464 | "\"\"\"\n", 465 | "! {run_script}" 466 | ] 467 | }, 468 | { 469 | "cell_type": "markdown", 470 | "metadata": { 471 | "id": "moDR3lrJVsE8" 472 | }, 473 | "source": [ 474 | "# CHANGELOG (変更ログ)\n", 475 | "\n", 476 | "## 2022/12/18 BREAKING CHANGE\n", 477 | "モデル等のディレクトリの構造を変更しました。くわしくは[こちら](https://github.com/ddPn08/automatic1111-colab/wiki/Data-directory-%7C-JP) \n", 478 | "Changed the directory structure of models etc. For details [here](https://github.com/ddPn08/automatic1111-colab/wiki/Data-directory-%7C-EN) \n", 479 | "\n", 480 | "## 2023/01/28\n", 481 | "- Simplified Python environment setup. / Python環境のセットアップをより簡潔にしました。\n", 482 | "- Removed Tailscale option. / Tailscaleオプションを削除しました。\n" 483 | ] 484 | } 485 | ], 486 | "metadata": { 487 | "accelerator": "GPU", 488 | "colab": { 489 | "provenance": [], 490 | "toc_visible": true, 491 | "include_colab_link": true 492 | }, 493 | "gpuClass": "standard", 494 | "kernelspec": { 495 | "display_name": "automatic", 496 | "language": "python", 497 | "name": "python3" 498 | }, 499 | "language_info": { 500 | "name": "python", 501 | "version": "3.10.0 | packaged by conda-forge | (default, Nov 10 2021, 13:20:59) [MSC v.1916 64 bit (AMD64)]" 502 | }, 503 | "vscode": { 504 | "interpreter": { 505 | "hash": "27f3fb6862b547830c34fbd0390b87507e21782526fd5ca25cfe7dc4f2b0fdae" 506 | } 507 | } 508 | }, 509 | "nbformat": 4, 510 | "nbformat_minor": 0 511 | } 512 | -------------------------------------------------------------------------------- /patches/stablediffusion-lowram.patch: -------------------------------------------------------------------------------- 1 | diff --git a/ldm/util.py b/ldm/util.py 2 | index 8c09ca1..681ffcf 100644 3 | --- a/ldm/util.py 4 | +++ b/ldm/util.py 5 | @@ -76,7 +76,7 @@ def instantiate_from_config(config): 6 | elif config == "__is_unconditional__": 7 | return None 8 | raise KeyError("Expected key `target` to instantiate.") 9 | - return get_obj_from_str(config["target"])(**config.get("params", dict())) 10 | + return get_obj_from_str(config["target"])(**config.get("params", dict())).cuda() 11 | 12 | 13 | def get_obj_from_str(string, reload=False): 14 | --------------------------------------------------------------------------------