From 02a6391c82dc7cf8868c7b234a3c2435c0bdec22 Mon Sep 17 00:00:00 2001 From: Dillon Erb <585865+dte@users.noreply.github.com> Date: Tue, 13 Dec 2022 13:58:48 -0500 Subject: [PATCH 1/3] Feat: Support both Colab and Gradient notebook architectures --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 291 ++++++++++++---------- 1 file changed, 163 insertions(+), 128 deletions(-) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index bc01b5d6..70346bc6 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -6,7 +6,7 @@ "id": "47kV9o1Ni8GH" }, "source": [ - "# **Colab From https://github.com/TheLastBen/fast-stable-diffusion, if you face any issues, feel free to discuss them.** [Support](https://ko-fi.com/thelastben)\n", + "# **Colab + Gradient Notebook From https://github.com/TheLastBen/fast-stable-diffusion, if you face any issues, feel free to discuss them.** [Support](https://ko-fi.com/thelastben)\n", "\n", "\n", "\n", @@ -24,8 +24,36 @@ }, "outputs": [], "source": [ - "from google.colab import drive\n", - "drive.mount('/content/gdrive')" + "import os\n", + "import site\n", + "\n", + "IN_PAPERSPACE = False\n", + "persistent_storage_dir = \"/content/gdrive/MyDrive\"\n", + "working_notebook_dir = \"/content\"\n", + "packages_dir = \"/usr/local/lib/python3.7/dist-packages\" # Colab dir\n", + "\n", + "!which python\n", + "!python --version\n", + "\n", + "if 'PAPERSPACE_NOTEBOOK_ID' in os.environ:\n", + " IN_PAPERSPACE = False\n", + " # persistent_storage_dir = \"/notebooks\"\n", + " persistent_storage_dir = \"/storage\"\n", + " working_notebook_dir = \"/notebooks\"\n", + " packages_dir = site.getsitepackages()[0]\n", + " print(\"Using Paperspace Gradient\")\n", + "\n", + " %pip install ftfy regex tqdm triton\n", + " %pip install git+https://github.com/openai/CLIP.git\n", + " \n", + " # Install git-lef on ps\n", + " !apt-get update\n", + " !apt install -y git-lfs p7zip-full\n", + "else:\n", + " print(\"Using Google Colab\")\n", + " \n", + " from google.colab import drive\n", + " drive.mount('/content/gdrive')\n" ] }, { @@ -41,38 +69,38 @@ "from IPython.utils import capture\n", "from IPython.display import clear_output\n", "from subprocess import getoutput\n", - "from google.colab import runtime\n", "from IPython.display import display_markdown\n", "import time\n", "\n", "\n", "with capture.capture_output() as cap:\n", " fgitclone = \"git clone --depth 1\" \n", - " %cd /content/gdrive/MyDrive/\n", + " %cd {persistent_storage_dir}\n", " %mkdir sd\n", " %cd sd\n", " !$fgitclone https://github.com/Stability-AI/stablediffusion\n", " !$fgitclone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/\n", + " # %cd {persistent_storage_dir}/sd/stablediffusion/\n", + " %pip install -r {persistent_storage_dir}/sd/stablediffusion/requirements.txt\n", + " %pip install -r {persistent_storage_dir}/sd/stable-diffusion-webui/requirements.txt\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/\n", " !mkdir -p cache/{huggingface,torch}\n", - " %cd /content/\n", - " !ln -s /content/gdrive/MyDrive/sd/stable-diffusion-webui/cache/huggingface ../root/.cache/\n", - " !ln -s /content/gdrive/MyDrive/sd/stable-diffusion-webui/cache/torch ../root/.cache/\n", - " !wget -O /content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/shared.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/modules/shared.py\n", + " %cd {working_notebook_dir}\n", + " !ln -s {persistent_storage_dir}/sd/stable-diffusion-webui/cache/huggingface ../root/.cache/\n", + " !ln -s {persistent_storage_dir}/sd/stable-diffusion-webui/cache/torch ../root/.cache/\n", + " !wget -O {persistent_storage_dir}/sd/stable-diffusion-webui/modules/shared.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/modules/shared.py\n", "\n", - "Update_repo = True\n", + "Update_repo = False\n", "if Update_repo:\n", " with capture.capture_output() as cap:\n", - " !rm /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.sh \n", - " !rm /content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/paths.py\n", - " !rm /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py \n", - " !rm /content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/ui.py\n", - " !rm /content/gdrive/MyDrive/sd/stable-diffusion-webui/style.css\n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/\n", + " !rm {persistent_storage_dir}/sd/stable-diffusion-webui/webui.sh \n", + " !rm {persistent_storage_dir}/sd/stable-diffusion-webui/modules/paths.py\n", + " !rm {persistent_storage_dir}/sd/stable-diffusion-webui/webui.py \n", + " !rm {persistent_storage_dir}/sd/stable-diffusion-webui/modules/ui.py\n", + " !rm {persistent_storage_dir}/sd/stable-diffusion-webui/style.css\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/\n", " print('\u001b[1;32m')\n", - " !git pull\n", - " clear_output()\n", - " print('\u001b[1;32mDONE !')" + " !git pull" ] }, { @@ -94,51 +122,51 @@ "\n", "with capture.capture_output() as cap:\n", " \n", - " if not os.path.exists('/content/gdrive/MyDrive/sd/stablediffusion/src/k-diffusion/k_diffusion'):\n", - " !mkdir /content/gdrive/MyDrive/sd/stablediffusion/src\n", - " %cd /content/gdrive/MyDrive/sd/stablediffusion/src\n", + " if not os.path.exists(f'{persistent_storage_dir}/sd/stablediffusion/src/k-diffusion/k_diffusion'):\n", + " !mkdir {persistent_storage_dir}/sd/stablediffusion/src\n", + " %cd {persistent_storage_dir}/sd/stablediffusion/src\n", " !$fgitclone https://github.com/CompVis/taming-transformers\n", " !$fgitclone https://github.com/openai/CLIP\n", " !$fgitclone https://github.com/salesforce/BLIP\n", " !$fgitclone https://github.com/sczhou/CodeFormer\n", " !$fgitclone https://github.com/crowsonkb/k-diffusion\n", - " !mv /content/gdrive/MyDrive/sd/stablediffusion/src/CLIP /content/gdrive/MyDrive/sd/stablediffusion/src/clip\n", - " !mv /content/gdrive/MyDrive/sd/stablediffusion/src/BLIP /content/gdrive/MyDrive/sd/stablediffusion/src/blip \n", - " !mv /content/gdrive/MyDrive/sd/stablediffusion/src/CodeFormer /content/gdrive/MyDrive/sd/stablediffusion/src/codeformer \n", - " !cp -r /content/gdrive/MyDrive/sd/stablediffusion/src/k-diffusion/k_diffusion /content/gdrive/MyDrive/sd/stable-diffusion-webui/\n", + " !mv {persistent_storage_dir}/sd/stablediffusion/src/CLIP {persistent_storage_dir}/sd/stablediffusion/src/clip\n", + " !mv {persistent_storage_dir}/sd/stablediffusion/src/BLIP {persistent_storage_dir}/sd/stablediffusion/src/blip \n", + " !mv {persistent_storage_dir}/sd/stablediffusion/src/CodeFormer {persistent_storage_dir}/sd/stablediffusion/src/codeformer \n", + " !cp -r {persistent_storage_dir}/sd/stablediffusion/src/k-diffusion/k_diffusion {persistent_storage_dir}/sd/stable-diffusion-webui/\n", "\n", "\n", - " %cd /content/\n", + " %cd {working_notebook_dir}/\n", " for i in range(1,6):\n", " !wget -q \"https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dependencies/Dependencies.{i}\"\n", " !mv \"Dependencies.{i}\" \"Dependencies.7z.00{i}\"\n", " !7z x -y Dependencies.7z.001\n", " time.sleep(2)\n", - " !cp -r /content/usr/local/lib/python3.8/dist-packages /usr/local/lib/python3.8/\n", - " !rm -r /content/usr\n", + " !cp -r {working_notebook_dir}/usr/local/lib/python3.8/dist-packages /usr/local/lib/python3.8/\n", + " !rm -r {working_notebook_dir}/usr\n", " for i in range(1,6):\n", " !rm \"Dependencies.7z.00{i}\"\n", " !pip install -U -q pillow\n", " \n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/modules\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/modules\n", " !wget -O paths.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/paths.py\n", "\n", - " if os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui/scripts/deforum_helpers/src/infer.py'):\n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui/scripts/deforum_helpers\n", + " if os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui/scripts/deforum_helpers/src/infer.py'):\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui/scripts/deforum_helpers\n", " !wget -O animation.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/deforum/animation.py\n", " !wget -O depth.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/deforum/depth.py \n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui/scripts/deforum_helpers/src \n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui/scripts/deforum_helpers/src \n", " !wget -O infer.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/deforum/infer.py\n", "\n", - " if not os.path.exists('/content/gdrive/MyDrive/sd/stablediffusion/repositories/BoostingMonocularDepth'):\n", - " %cd /content/gdrive/MyDrive/sd/stablediffusion\n", + " if not os.path.exists(f'{persistent_storage_dir}/sd/stablediffusion/repositories/BoostingMonocularDepth'):\n", + " %cd {persistent_storage_dir}/sd/stablediffusion\n", " !mkdir repositories\n", " %cd repositories\n", " !git clone https://github.com/isl-org/MiDaS.git midas\n", " !git clone https://github.com/compphoto/BoostingMonocularDepth.git\n", - " %cd /content\n", + " %cd {working_notebook_dir}\n", "\n", - "base = '/content/gdrive/MyDrive/sd/stable-diffusion'\n", + "base = f'{persistent_storage_dir}/sd/stable-diffusion'\n", "dirs = [base, f'{base}/src/taming-transformers', f'{base}/src/clip',\n", " f'{base}/src/GFPGAN', f'{base}/src/blip', f'{base}/src/codeformer',\n", " f'{base}/src/realesrgan', f'{base}/src/k-diffusion', f'{base}/src/ldm']\n", @@ -171,19 +199,19 @@ "Redownload_the_original_model = False #@param {type:\"boolean\"}\n", "\n", "if Redownload_the_original_model:\n", - " if os.path.exists('/content/mainmodel.ckpt'):\n", - " !rm /content/mainmodel.ckpt\n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion \n", + " if os.path.exists(f'{working_notebook_dir}/mainmodel.ckpt'):\n", + " !rm {working_notebook_dir}/mainmodel.ckpt\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion \n", " !wget -q -O model.ckpt https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/precompiled/README.md\n", - " !mv /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f \n", + " !mv {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f \n", " time.sleep(2)\n", - " !rm /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f\n", + " !rm {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f\n", " time.sleep(2)\n", - " clear_output()\n", + " # clear_output()\n", "\n", "#@markdown Or\n", "Path_to_CKPT = \"\" #@param {type:\"string\"}\n", - "#@markdown - Insert the full path of your trained model (eg: /content/gdrive/MyDrive/zarathustra.ckpt) or to a folder containing multiple models.\n", + "#@markdown - Insert the full path of your trained model (eg: {persistent_storage_dir}/zarathustra.ckpt) or to a folder containing multiple models.\n", "\n", "#@markdown Or\n", "Link_CKPT = \"\" #@param {type:\"string\"}\n", @@ -191,25 +219,25 @@ "\n", "def newmdl(token):\n", "\n", - " if not os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", + " if not os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", " if token==\"\":\n", " token=input(\"Insert your huggingface token :\")\n", - " %cd /content/\n", + " %cd {working_notebook_dir}/\n", " clear_output()\n", " !git init\n", " !git lfs install --system --skip-repo\n", " !$fgitclone --branch fp16 \"https://USER:{token}@huggingface.co/runwayml/stable-diffusion-v1-5\"\n", - " if os.path.exists('/content/stable-diffusion-v1-5'):\n", + " if os.path.exists(f'{working_notebook_dir}/stable-diffusion-v1-5'):\n", " !$fgitclone \"https://USER:{token}@huggingface.co/stabilityai/sd-vae-ft-mse\"\n", - " !rm -r /content/stable-diffusion-v1-5/vae\n", - " !mv /content/sd-vae-ft-mse /content/stable-diffusion-v1-5/vae \n", + " !rm -r {working_notebook_dir}/stable-diffusion-v1-5/vae\n", + " !mv {working_notebook_dir}/sd-vae-ft-mse {working_notebook_dir}/stable-diffusion-v1-5/vae \n", " !wget -O convertosd.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertosd.py\n", - " !sed -i '201s@.*@ model_path = \"/content/stable-diffusion-v1-5\"@' /content/convertosd.py\n", - " !sed -i '202s@.*@ checkpoint_path= \"/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt\"@' /content/convertosd.py\n", + " !sed -i '201s@.*@ model_path = \"{working_notebook_dir}/stable-diffusion-v1-5\"@' {working_notebook_dir}/convertosd.py\n", + " !sed -i '202s@.*@ checkpoint_path= \"{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt\"@' {working_notebook_dir}/convertosd.py\n", " clear_output() \n", - " !python /content/convertosd.py \n", - " if os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", - " model='/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", + " !python {working_notebook_dir}/convertosd.py \n", + " if os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", + " model=f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", " clear_output()\n", " print('\u001b[1;32mDONE !')\n", " else:\n", @@ -218,24 +246,24 @@ " print('\u001b[1;31mMake sure you accept the terms at https://huggingface.co/runwayml/stable-diffusion-v1-5')\n", "\n", " else:\n", - " model='/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", + " model=f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", " clear_output()\n", " print('\u001b[1;32mModel already exists, check the box \"Redownload_the_original_model\" to redownload/download the V1.5')\n", "\n", - " if os.path.exists('/content/.git'):\n", - " !rm -r /content/.git\n", + " if os.path.exists(f'{working_notebook_dir}/.git'):\n", + " !rm -r {working_notebook_dir}/.git\n", "\n", - " if os.path.exists('/content/stable-diffusion-v1-5'):\n", - " !rm -r /content/stable-diffusion-v1-5 \n", + " if os.path.exists(f'{working_notebook_dir}/stable-diffusion-v1-5'):\n", + " !rm -r {working_notebook_dir}/stable-diffusion-v1-5 \n", "\n", "\n", "def V2(token):\n", "\n", - " if not os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", - " %cd /content/\n", - " clear_output()\n", - " !mkdir \"/content/stable-diffusion-V2\"\n", - " %cd \"/content/stable-diffusion-V2\"\n", + " if not os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", + " %cd {working_notebook_dir}\n", + " # clear_output()\n", + " !mkdir {working_notebook_dir}/stable-diffusion-V2\n", + " %cd {working_notebook_dir}/stable-diffusion-V2\n", " !git init\n", " !git lfs install --system --skip-repo\n", " if Model_Version == \"V2.1-768px\":\n", @@ -245,48 +273,48 @@ " !git config core.sparsecheckout true\n", " !echo -e \"scheduler\\ntext_encoder\\ntokenizer\\nunet\\nvae\\nmodel_index.json\" > .git/info/sparse-checkout\n", " !git pull origin main\n", - " %cd /content\n", + " %cd {working_notebook_dir}\n", " !wget -O convertosdv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertosdv2.py\n", - " clear_output()\n", - " !python /content/convertosdv2.py --fp16 /content/stable-diffusion-V2 /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt\n", - " if os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", - " model='/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", - " clear_output()\n", + " # clear_output()\n", + " !python {working_notebook_dir}/convertosdv2.py --fp16 {working_notebook_dir}/stable-diffusion-V2 {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt\n", + " if os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", + " model=f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", + " # clear_output()\n", " print('\u001b[1;32mDONE !')\n", " else:\n", " print('\u001b[1;31mSomething went wrong, try again')\n", "\n", " else:\n", - " model='/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", - " clear_output()\n", + " model=f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", + " # clear_output()\n", " print('\u001b[1;32mModel already exists, check the box \"Redownload_the_original_model\" to redownload/download the V2.')\n", "\n", - " if os.path.exists('/content/.git'):\n", - " !rm -r /content/.git\n", - " !rm -r /content/convertosdv2.py\n", - " if os.path.exists('/content/stable-diffusion-V2'):\n", - " !rm -r /content/stable-diffusion-V2\n", + " if os.path.exists(f'{working_notebook_dir}/.git'):\n", + " !rm -r {working_notebook_dir}/.git\n", + " !rm -r {working_notebook_dir}/convertosdv2.py\n", + " if os.path.exists(f'{working_notebook_dir}/stable-diffusion-V2'):\n", + " !rm -r {working_notebook_dir}/stable-diffusion-V2\n", "\n", "def inpmdl(token):\n", "\n", - " if not os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'):\n", + " if not os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'):\n", " if token==\"\":\n", " token=input(\"Insert your huggingface token :\")\n", - " %cd /content/\n", + " %cd {working_notebook_dir}\n", " clear_output()\n", " !git init\n", " !git lfs install --system --skip-repo\n", " !$fgitclone --branch fp16 \"https://USER:{token}@huggingface.co/runwayml/stable-diffusion-inpainting\"\n", - " if os.path.exists('/content/stable-diffusion-inpainting'):\n", + " if os.path.exists(f'{working_notebook_dir}/stable-diffusion-inpainting'):\n", " !$fgitclone \"https://USER:{token}@huggingface.co/stabilityai/sd-vae-ft-mse\"\n", - " !rm -r /content/stable-diffusion-inpainting/vae\n", - " !mv /content/sd-vae-ft-mse /content/stable-diffusion-inpainting/vae \n", + " !rm -r {working_notebook_dir}/stable-diffusion-inpainting/vae\n", + " !mv {working_notebook_dir}/sd-vae-ft-mse {working_notebook_dir}/stable-diffusion-inpainting/vae \n", " !wget -O convertosd.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertosd.py\n", - " !sed -i '201s@.*@ model_path = \"/content/stable-diffusion-inpainting\"@' /content/convertosd.py\n", - " !sed -i '202s@.*@ checkpoint_path= \"/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/sd-v1-5-inpainting.ckpt\"@' /content/convertosd.py\n", + " !sed -i '201s@.*@ model_path = \"{working_notebook_dir}/stable-diffusion-inpainting\"@' {working_notebook_dir}/convertosd.py\n", + " !sed -i '202s@.*@ checkpoint_path= \"{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/sd-v1-5-inpainting.ckpt\"@' {working_notebook_dir}/convertosd.py\n", " clear_output() \n", - " !python /content/convertosd.py \n", - " if os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'):\n", + " !python {working_notebook_dir}/convertosd.py \n", + " if os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'):\n", " clear_output()\n", " print('\u001b[1;32mDONE !')\n", " else:\n", @@ -298,11 +326,11 @@ " clear_output()\n", " print('\u001b[1;32mModel already exists.')\n", "\n", - " if os.path.exists('/content/.git'):\n", - " !rm -r /content/.git\n", + " if os.path.exists(f'{working_notebook_dir}/.git'):\n", + " !rm -r {working_notebook_dir}/.git\n", "\n", - " if os.path.exists('/content/stable-diffusion-inpainting'):\n", - " !rm -r /content/stable-diffusion-inpainting \n", + " if os.path.exists(f'{working_notebook_dir}/stable-diffusion-inpainting'):\n", + " !rm -r {working_notebook_dir}/stable-diffusion-inpainting \n", "\n", "\n", "if (Path_to_CKPT !=''):\n", @@ -318,19 +346,19 @@ " model=Path_to_CKPT\n", "\n", "elif Link_CKPT != \"\":\n", - " if os.path.exists('/content/mainmodel.ckpt'):\n", - " !rm /content/mainmodel.ckpt\n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion\n", + " if os.path.exists(f'{working_notebook_dir}/mainmodel.ckpt'):\n", + " !rm {working_notebook_dir}/mainmodel.ckpt\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion\n", " !wget -q -O model.ckpt https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/precompiled/attention.py\n", - " !mv /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f \n", + " !mv {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f \n", " time.sleep(2)\n", - " !rm /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f\n", + " !rm {persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/trashfile.f\n", " time.sleep(2)\n", " clear_output()\n", " !gdown --fuzzy -O model.ckpt $Link_CKPT\n", - " if os.path.exists('/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", - " if os.path.getsize(\"/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt\") > 1810671599:\n", - " model='/content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", + " if os.path.exists(f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'):\n", + " if os.path.getsize(f\"{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt\") > 1810671599:\n", + " model=f'{persistent_storage_dir}/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt'\n", " clear_output()\n", " print('\u001b[1;32mModel downloaded, using the trained model.')\n", " else:\n", @@ -386,26 +414,26 @@ " !npm install -g localtunnel\n", "\n", "with capture.capture_output() as cap: \n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/\n", " time.sleep(1)\n", " !wget -O webui.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.py\n", - " !sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py\n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/\n", + " !sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' {persistent_storage_dir}/sd/stable-diffusion-webui/webui.py\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui/modules/\n", " !wget -O ui.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/modules/ui.py\n", - " !sed -i 's@css = \"\".*@with open(os.path.join(script_path, \"style.css\"), \"r\", encoding=\"utf8\") as file:\\n css = file.read()@' /content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/ui.py\n", - " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui\n", + " !sed -i 's@css = \"\".*@with open(os.path.join(script_path, \"style.css\"), \"r\", encoding=\"utf8\") as file:\\n css = file.read()@' {persistent_storage_dir}/sd/stable-diffusion-webui/modules/ui.py\n", + " %cd {persistent_storage_dir}/sd/stable-diffusion-webui\n", " !wget -O style.css https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/style.css\n", - " !sed -i 's@min-height: 4.*@min-height: 5.5em;@g' /content/gdrive/MyDrive/sd/stable-diffusion-webui/style.css\n", - " !sed -i \"s@'extensions/depthmap2mask/scripts/depthmap_for_depth2img.py'@\\\"/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/depthmap2mask/scripts/depthmap_for_depth2img.py\\\"@\" /content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/depthmap2mask/scripts/depth2image_depthmask.py\n", - " !sed -i 's@\"repositories/BoostingMonocularDepth\"@\\\"/content/gdrive/MyDrive/sd/stablediffusion/repositories/BoostingMonocularDepth\\\"@' /content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/stable-diffusion-webui-depthmap-script/scripts/depthmap.py\n", - " !sed -i 's@\"multiple_tqdm\": true,@\\\"multiple_tqdm\": false,@' /content/gdrive/MyDrive/sd/stable-diffusion-webui/config.json \n", - " %cd /content\n", + " !sed -i 's@min-height: 4.*@min-height: 5.5em;@g' {persistent_storage_dir}/sd/stable-diffusion-webui/style.css\n", + " !sed -i \"s@'extensions/depthmap2mask/scripts/depthmap_for_depth2img.py'@\\\"{persistent_storage_dir}/sd/stable-diffusion-webui/extensions/depthmap2mask/scripts/depthmap_for_depth2img.py\\\"@\" {persistent_storage_dir}/sd/stable-diffusion-webui/extensions/depthmap2mask/scripts/depth2image_depthmask.py\n", + " !sed -i 's@\"repositories/BoostingMonocularDepth\"@\\\"{persistent_storage_dir}/sd/stablediffusion/repositories/BoostingMonocularDepth\\\"@' {persistent_storage_dir}/sd/stable-diffusion-webui/extensions/stable-diffusion-webui-depthmap-script/scripts/depthmap.py\n", + " !sed -i 's@\"multiple_tqdm\": true,@\\\"multiple_tqdm\": false,@' {persistent_storage_dir}/sd/stable-diffusion-webui/config.json \n", + " %cd {working_notebook_dir}\n", "\n", "\n", "share=''\n", "if Use_Gradio_Server:\n", " share='--share'\n", - " for line in fileinput.input('/usr/local/lib/python3.8/dist-packages/gradio/blocks.py', inplace=True):\n", + " for line in fileinput.input(f'{packages_dir}/gradio/blocks.py', inplace=True):\n", " if line.strip().startswith('self.server_name ='):\n", " line = ' self.server_name = server_name\\n'\n", " if line.strip().startswith('self.server_port ='):\n", @@ -417,11 +445,11 @@ " share=''\n", " !nohup lt --port 7860 > srv.txt 2>&1 &\n", " time.sleep(2)\n", - " !grep -o 'https[^ ]*' /content/srv.txt >srvr.txt\n", + " !grep -o 'https[^ ]*' {working_notebook_dir}/srv.txt >srvr.txt\n", " time.sleep(2)\n", - " srv= getoutput('cat /content/srvr.txt')\n", + " srv= getoutput(f'cat {working_notebook_dir}/srvr.txt')\n", "\n", - " for line in fileinput.input('/usr/local/lib/python3.8/dist-packages/gradio/blocks.py', inplace=True):\n", + " for line in fileinput.input(f'{packages_dir}/gradio/blocks.py', inplace=True):\n", " if line.strip().startswith('self.server_name ='):\n", " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", " if line.strip().startswith('self.server_port ='):\n", @@ -434,27 +462,27 @@ " line = '' \n", " sys.stdout.write(line)\n", " \n", - " !sed -i '13s@.*@ \"PUBLIC_SHARE_TRUE\": \"\u001b[32mConnected\",@' /usr/local/lib/python3.8/dist-packages/gradio/strings.py\n", + " !sed -i '13s@.*@ \"PUBLIC_SHARE_TRUE\": \"\u001b[32mConnected\",@' {packages_dir}/gradio/strings.py\n", " \n", - " !rm /content/srv.txt\n", - " !rm /content/srvr.txt\n", + " !rm {working_notebook_dir}/srv.txt\n", + " !rm {working_notebook_dir}/srvr.txt\n", "\n", "with capture.capture_output() as cap: \n", - " %cd /content/gdrive/MyDrive/sd/stablediffusion\n", + " %cd {persistent_storage_dir}/sd/stablediffusion\n", "\n", "api = '--api' if Enable_API else ''\n", "\n", "if Model_Version == \"V2.1-768\":\n", - " configf=\"--config /content/gdrive/MyDrive/sd/stablediffusion/configs/stable-diffusion/v2-inference-v.yaml\"\n", - " !sed -i 's@def load_state_dict(checkpoint_path: str, map_location.*@def load_state_dict(checkpoint_path: str, map_location=\"cuda\"):@' /usr/local/lib/python3.8/dist-packages/open_clip/factory.py \n", + " configf=\"--config {persistent_storage_dir}/sd/stablediffusion/configs/stable-diffusion/v2-inference-v.yaml\"\n", + " !sed -i 's@def load_state_dict(checkpoint_path: str, map_location.*@def load_state_dict(checkpoint_path: str, map_location=\"cuda\"):@' {packages_dir}/open_clip/factory.py \n", "elif Model_Version == \"V2.1-512\":\n", - " configf=\"--config /content/gdrive/MyDrive/sd/stablediffusion/configs/stable-diffusion/v2-inference.yaml\"\n", - " !sed -i 's@def load_state_dict(checkpoint_path: str, map_location.*@def load_state_dict(checkpoint_path: str, map_location=\"cuda\"):@' /usr/local/lib/python3.8/dist-packages/open_clip/factory.py \n", + " configf=\"--config {persistent_storage_dir}/sd/stablediffusion/configs/stable-diffusion/v2-inference.yaml\"\n", + " !sed -i 's@def load_state_dict(checkpoint_path: str, map_location.*@def load_state_dict(checkpoint_path: str, map_location=\"cuda\"):@' {packages_dir}/open_clip/factory.py \n", "else:\n", " configf=\"\"\n", - " !sed -i 's@def load_state_dict(checkpoint_path: str, map_location.*@def load_state_dict(checkpoint_path: str, map_location=\"cpu\"):@' /usr/local/lib/python3.8/dist-packages/open_clip/factory.py \n", + " !sed -i 's@def load_state_dict(checkpoint_path: str, map_location.*@def load_state_dict(checkpoint_path: str, map_location=\"cpu\"):@' {packages_dir}/open_clip/factory.py \n", "\n", - "if os.path.exists('/usr/local/lib/python3.8/dist-packages/xformers'):\n", + "if os.path.exists(f'{packages_dir}/xformers'):\n", " xformers=\"--xformers\" \n", "else:\n", " xformers=\"\"\n", @@ -462,11 +490,11 @@ "try:\n", " model\n", " if os.path.isfile(model):\n", - " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --enable-insecure-extension-access --no-half-vae --ckpt \"$model\" $configf $xformers\n", + " !python {persistent_storage_dir}/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --enable-insecure-extension-access --no-half-vae --ckpt \"$model\" $configf $xformers\n", " else:\n", - " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --enable-insecure-extension-access --no-half-vae --ckpt-dir \"$model\" $configf $xformers\n", + " !python {persistent_storage_dir}/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --enable-insecure-extension-access --no-half-vae --ckpt-dir \"$model\" $configf $xformers\n", "except:\n", - " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --enable-insecure-extension-access --no-half-vae $configf $xformers" + " !python {persistent_storage_dir}/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --enable-insecure-extension-access --no-half-vae $configf $xformers" ] } ], @@ -477,11 +505,18 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3.9.6 64-bit", + "language": "python", "name": "python3" }, "language_info": { - "name": "python" + "name": "python", + "version": "3.9.6" + }, + "vscode": { + "interpreter": { + "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" + } } }, "nbformat": 4, From 79f331511b5299cf54968cfcadff1016a4cc2e53 Mon Sep 17 00:00:00 2001 From: Dillon Erb <585865+dte@users.noreply.github.com> Date: Tue, 13 Dec 2022 14:01:30 -0500 Subject: [PATCH 2/3] Update fast_stable_diffusion_AUTOMATIC1111.ipynb --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 70346bc6..58f19c8b 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -511,12 +511,6 @@ }, "language_info": { "name": "python", - "version": "3.9.6" - }, - "vscode": { - "interpreter": { - "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" - } } }, "nbformat": 4, From 90641d6a005f2b06d91bff4768ebb1720941153e Mon Sep 17 00:00:00 2001 From: Dillon Erb <585865+dte@users.noreply.github.com> Date: Tue, 13 Dec 2022 14:01:48 -0500 Subject: [PATCH 3/3] Update fast_stable_diffusion_AUTOMATIC1111.ipynb --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 58f19c8b..cbe04bcd 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -510,7 +510,7 @@ "name": "python3" }, "language_info": { - "name": "python", + "name": "python" } }, "nbformat": 4,