Skip to content

Commit

Permalink
#16 low RAM patch can be applied
Browse files Browse the repository at this point in the history
  • Loading branch information
ddPn08 committed Jan 5, 2023
1 parent 2748452 commit 81431d6
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions automatic1111.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"drive_path = \"/content/drive\"\n",
"if mount_google_drive and not os.path.exists(drive_path):\n",
" from google.colab import drive\n",
"\n",
" try:\n",
" drive.mount(drive_path, force_remount=force_remount)\n",
" data_dir_gdrive = \"/content/drive/MyDrive/AI/automatic1111\" # @param {type:\"string\"}\n",
Expand Down Expand Up @@ -169,7 +170,7 @@
" filepath = f\"{config_path}/{filename}\"\n",
" if not os.path.exists(filepath):\n",
" if filename.endswith(\".json\"):\n",
" with open(filepath, mode='w') as f:\n",
" with open(filepath, mode=\"w\") as f:\n",
" f.write(\"{}\")\n",
" else:\n",
" ! touch {config_path}/{filename}\n",
Expand Down Expand Up @@ -207,17 +208,17 @@
"import os\n",
"\n",
"no_half = False # @param {type:\"boolean\"}\n",
"no_half_vae = False # @param {type:\"boolean\"}\n",
"allow_code = False # @param {type:\"boolean\"}\n",
"no_half_vae = False # @param {type:\"boolean\"}\n",
"allow_code = False # @param {type:\"boolean\"}\n",
"no_progressbar_hiding = False # @param {type:\"boolean\"}\n",
"medvram = False # @param {type:\"boolean\"}\n",
"lowvram = False # @param {type:\"boolean\"}\n",
"deepdanbooru = False # @param {type:\"boolean\"}\n",
"deepdanbooru = False # @param {type:\"boolean\"}\n",
"xformers = True # @param {type:\"boolean\"}\n",
"disable_opt_split_attention = False # @param {type:\"boolean\"}\n",
"\n",
"# @markdown  \n",
"custom_arguments = \"\" # @param {type:\"string\"}\n",
"custom_arguments = \"\" # @param {type:\"string\"}\n",
"\n",
"run_string_with_variables = {\n",
" \"--no-half\": f\"{no_half}\",\n",
Expand All @@ -237,9 +238,9 @@
"# @markdown ## Enable password authentication (Prevent other users from using the WebUI)\n",
"\n",
"# @markdown  \n",
"use_gradio_auth = False # @param {type:\"boolean\"}\n",
"gradio_auth_username = \"username\" # @param {type:\"string\"}\n",
"gradio_auth_password = \"password\" # @param {type:\"string\"}\n",
"use_gradio_auth = False # @param {type:\"boolean\"}\n",
"gradio_auth_username = \"username\" # @param {type:\"string\"}\n",
"gradio_auth_password = \"password\" # @param {type:\"string\"}\n",
"\n",
"# @markdown  \n",
"# @markdown # Advanced | Network preferences\n",
Expand Down Expand Up @@ -272,10 +273,11 @@
"use_tailscale = False # @param {type: \"boolean\"}\n",
"tailscale_auth_key = \"\" # @param {type: \"string\"}\n",
"\n",
"# @markdown  \n",
"# @markdown ## Extensions\n",
"load_extensions_from_gdrive = True # @param {type:\"boolean\"}\n",
"extensions = \"https://github.com/yfszzx/stable-diffusion-webui-images-browser, https://github.com/DominikDoom/a1111-sd-webui-tagcomplete\" # @param {type:\"string\"}\n",
"extensions = list(map(str.strip, extensions.split(',')))\n",
"extensions = list(map(str.strip, extensions.split(\",\")))\n",
"\n",
"if load_extensions_from_gdrive and extensions_file_path:\n",
" if os.path.exists(extensions_file_path):\n",
Expand All @@ -296,7 +298,7 @@
"if use_gradio_auth:\n",
" vars += f\" --gradio-auth {gradio_auth_username}:{gradio_auth_password}\"\n",
"\n",
"os.environ['COMMANDLINE_ARGS'] = f\"{vars} {custom_arguments}\""
"os.environ[\"COMMANDLINE_ARGS\"] = f\"{vars} {custom_arguments}\""
]
},
{
Expand All @@ -321,8 +323,8 @@
"# @markdown ## Setup environment\n",
"# @markdown This may take up to 10 minutes\n",
"\n",
"store_env_gdrive = False # @param{type:\"boolean\"}\n",
"force_reinstall_environmemt = False # @param{type:\"boolean\"}\n",
"store_env_gdrive = False # @param{type:\"boolean\"}\n",
"force_reinstall_environmemt = False # @param{type:\"boolean\"}\n",
"gdrive_env_directory = f\"{data_dir}/conda-env\"\n",
"gdrive_env_file = f\"{gdrive_env_directory}/env.tar.zst\"\n",
"\n",
Expand Down Expand Up @@ -361,7 +363,11 @@
" ! rm Miniconda3-latest-Linux-x86_64.sh\n",
"\n",
"\n",
"if os.path.exists(gdrive_env_file) and not os.path.exists(\"/usr/local/envs/automatic\") and not force_reinstall_environmemt:\n",
"if (\n",
" os.path.exists(gdrive_env_file)\n",
" and not os.path.exists(\"/usr/local/envs/automatic\")\n",
" and not force_reinstall_environmemt\n",
"):\n",
" os.makedirs(\"/usr/local/envs/automatic\", exist_ok=True)\n",
" ! zstd -dc {gdrive_env_file} | tar -xf - -C /usr/local/envs/automatic\n",
" ! cd stable-diffusion-webui && conda env update -n automatic -f ./environment-wsl2.yaml\n",
Expand All @@ -377,21 +383,38 @@
"python -c 'from launch import prepare_environment; prepare_environment()'\"\"\"\n",
"! {install_script}\n",
"\n",
"os.environ[\"LD_LIBRARY_PATH\"] = f\"{os.environ['LD_LIBRARY_PATH']}:/usr/local/envs/automatic/lib\"\n",
"# @markdown  \n",
"# @markdown ## Optional | Apply low RAM patch\n",
"apply_lowram_patch = True # @param {type: \"boolean\"}\n",
"\n",
"if apply_lowram_patch:\n",
" patches_dir = \"/content/patches\"\n",
" os.makedirs(patches_dir, exist_ok=True)\n",
" ! cd {patches_dir} && curl -LO https://raw.githubusercontent.com/ddPn08/automatic1111-colab/main/patches/stablediffusion-lowram.patch\n",
" ! cd /content/stable-diffusion-webui/repositories/stable-diffusion-stability-ai && git apply {patches_dir}/stablediffusion-lowram.patch\n",
"\n",
"\n",
"os.environ[\n",
" \"LD_LIBRARY_PATH\"\n",
"] = f\"{os.environ['LD_LIBRARY_PATH']}:/usr/local/envs/automatic/lib\"\n",
"\n",
"if os.path.exists(f\"{data_dir}/script.post.sh\"):\n",
" ! chmod +x {data_dir}/script.post.sh\n",
" ! {data_dir}/script.post.sh\n",
"\n",
"if store_env_gdrive and mount_google_drive and mount_success:\n",
" import threading\n",
"\n",
" def pack():\n",
" os.makedirs(gdrive_env_directory, exist_ok=True)\n",
" ! tar -C /usr/local/envs/automatic -cf - . | zstd > /content/tmp.tar.zst\n",
" ! mv /content/tmp.tar.zst {gdrive_env_file}\n",
" print(\"Finish storing environment.\")\n",
"\n",
" threading.Thread(target=pack).start()\n",
" print(\"Started storing the conda environment in a separate thread. This will take approximately 2 minutes.\")"
" print(\n",
" \"Started storing the conda environment in a separate thread. This will take approximately 2 minutes.\"\n",
" )"
]
},
{
Expand Down

0 comments on commit 81431d6

Please sign in to comment.