2022-09-08 13:02:54 -06:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
2022-09-11 16:35:36 -06:00
"id": "gfKvWAVnz8OB",
"tags": []
2022-09-08 13:02:54 -06:00
},
"source": [
2022-10-04 10:57:09 -06:00
"# AUTOMATIC1111's Stable Diffusion WebUI\n",
2022-09-08 13:02:54 -06:00
"\n",
2022-10-07 00:09:27 -06:00
"https://github.com/AUTOMATIC1111/stable-diffusion-webui\n",
2022-09-11 16:35:36 -06:00
"\n",
2022-10-07 00:09:27 -06:00
"Loosely based on https://colab.research.google.com/drive/1kw3egmSn-KgWsikYvOMjJkVDsPLjEMzl\n",
2022-09-11 16:35:36 -06:00
"\n",
"**Guides**\n",
"- [Getting started on Paperspace](https://github.com/Engineer-of-Stuff/stable-diffusion-paperspace/blob/main/Docs/Paperspace%20Guide%20for%20Retards.md)\n",
"- [Using the WebUI](https://rentry.org/voldy)\n",
"- [Using the Inpainter](https://rentry.org/drfar)\n",
"- [Textual Inversion](https://rentry.org/aikgx)\n",
"- [Crowd-Sourced Prompts](https://lexica.art/)\n",
2022-09-28 22:32:59 -06:00
"- [Artist Name Prompts](https://sgreens.notion.site/sgreens/4ca6f4e229e24da6845b6d49e6b08ae7?v=fdf861d1c65d456e98904fe3f3670bd3)\n",
"- [Stable Diffusion Models](https://cyberes.github.io/stable-diffusion-models)\n",
"- [Textual Inversion Models](https://cyberes.github.io/stable-diffusion-textual-inversion-models/)\n",
"- [Have I Been Trained?](https://haveibeentrained.com/)"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
2022-10-31 19:34:37 -06:00
"# Installation and Setup\n",
2022-09-08 13:02:54 -06:00
"\n",
2022-09-28 22:32:59 -06:00
"You must reinstall everything each time you restart the machine. If already downloaded, dependencies will be auto-updated."
2022-09-08 13:02:54 -06:00
]
},
2022-09-10 14:24:12 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Where to store the models**\n",
"\n",
2022-11-09 23:28:37 -07:00
"`/storage/` is persistent storage shared across all machines on your account. Mounted to your machine.\n",
2022-09-10 14:24:12 -06:00
"\n",
2022-11-09 23:28:37 -07:00
"`/notebooks/` is storage for this notebook only. This directory has to be copied into your machine which can increase start/stop times if the directory is very large. To avoid this, put large files in `/storage/`.\n",
2022-09-10 14:24:12 -06:00
"\n",
2022-10-06 23:29:36 -06:00
"`/tmp/` <mark style=\"background-color:lime\">is not a persistent directory, meaning your files there will be deleted when the machine turns off.</mark>\n",
2022-10-01 13:41:10 -06:00
"\n",
"<br>\n",
"\n",
2022-10-06 23:29:36 -06:00
"<mark style=\"background-color: #ff780082\">If you are having storage issues</mark>, set `repo_storage_dir` to `/tmp/stable-diffusion`.\n",
2022-10-01 13:41:10 -06:00
"\n",
2022-10-27 10:00:21 -06:00
"<br><br>\n",
"\n",
"<mark>You must uncomment the correct section and run the block below or else the notebook won't work!</mark>\n",
"\n",
"Select the section you want and do `ctrl + /` to uncomment.\n",
2022-09-16 13:14:05 -06:00
"\n",
2022-10-30 13:52:49 -06:00
"Make sure there isn't a space in front of any variable. Don't put a trailing slash on directory paths. If you change any settings here, rerun this cell."
2022-09-10 14:24:12 -06:00
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "code",
"execution_count": null,
2022-09-10 14:24:12 -06:00
"metadata": {},
2022-09-08 13:02:54 -06:00
"outputs": [],
"source": [
2022-10-01 12:55:11 -06:00
"# Free tier\n",
2022-11-09 23:28:37 -07:00
"# symlink_to_notebooks = True # Enables the creation of symlinks back to /notebooks/\n",
2022-10-18 09:51:36 -06:00
"# model_storage_dir = '/tmp/stable-diffusion/models' # Where the models will be downloaded to.\n",
"# repo_storage_dir = '/notebooks' # Where the repository will be downloaded to.\n",
2022-09-10 14:24:12 -06:00
"\n",
2022-10-01 12:55:11 -06:00
"# Paid Tier\n",
2022-11-09 23:28:37 -07:00
"# symlink_to_notebooks = False\n",
2022-11-01 19:02:38 -06:00
"# model_storage_dir = '/storage/models'\n",
"# repo_storage_dir = '/notebooks'\n",
2022-10-01 12:55:11 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"\n",
2022-11-09 23:28:37 -07:00
"# Other optional settings\n",
"# You don't have to change these if you don't want to\n",
"\n",
2022-11-01 19:02:38 -06:00
"activate_xformers = False # Enables the xformers optimizations using pre-built wheels.\n",
2022-10-18 09:51:36 -06:00
" # Setting to True will automatically set up your environment/machine for xformers. \n",
"\n",
2022-10-27 10:00:21 -06:00
"link_novelai_anime_vae = False # Enables the linking of animevae.pt to each of the NovelAI models.\n",
2022-10-18 09:51:36 -06:00
" # Set to True if you've downloaded both the NovelAI models and hypernetworks.\n",
2022-10-27 10:00:21 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"download_scripts = False # Download custom scripts? Only reason why you would leave it disabled is because it may\n",
" # take a while to complete.\n",
"\n",
"activate_deepdanbooru = False # Enable and install DeepDanbooru -> https://github.com/KichangKim/DeepDanbooru\n",
"\n",
2022-10-30 12:44:37 -06:00
"activate_medvram = True # Enable medvram option.\n",
2022-10-30 13:52:49 -06:00
" # These are model optimizations which will reduce VRAM usage at the expense of some speed.\n",
" # Set to False if you have a lot of VRAM.\n",
2022-10-30 12:44:37 -06:00
"\n",
2022-10-30 13:52:49 -06:00
"disable_pickle_check = False # Disable the automatic check for unexpected data in model files.\n",
" # Leave this set to False unless you have a reason to disable the check.\n",
2022-10-30 12:44:37 -06:00
"\n",
2022-10-30 13:52:49 -06:00
"gradio_port = False # Launch Gradio on a specific port. Set to False to let Gradio choose a port.\n",
" # This disables online Gradio app mode and you will only be able to access it on your local network.\n",
2022-11-09 05:20:48 -07:00
"\n",
"gradio_auth = False # Enable gradio_auth and insecure-extension-access option.\n",
2022-11-19 00:10:34 -07:00
" # Set to \"me:password\" to enable.\n",
2022-11-09 05:20:48 -07:00
"\n",
2022-11-13 11:47:51 -07:00
"search_paperspace_datasets = True # Enable searching for checkpoints in /datasets to link to the webui\n",
"\n",
2022-11-19 00:10:34 -07:00
"ui_theme = None # Set the WEB UI theme. Values can be None (default) or 'dark'.\n",
2022-11-13 14:40:31 -07:00
"\n",
2022-11-30 20:54:29 -07:00
"insecure_extension_access = False # Force enable extensions without a password.\n",
" # If you don't set a password, anyone can install and run arbitrary code on your machine!\n",
" # Instead, use gradio_auth which will automatically enable extensions when set.\n",
"\n",
2022-12-01 16:24:24 -07:00
"\n",
2022-11-30 20:54:29 -07:00
"# ===================================================================================================\n",
2022-10-01 12:55:11 -06:00
"# Save variables to Jupiter's temp storage so we can access it even if the kernel restarts.\n",
2022-12-01 16:24:24 -07:00
"%store symlink_to_notebooks model_storage_dir repo_storage_dir activate_xformers link_novelai_anime_vae download_scripts activate_deepdanbooru activate_medvram disable_pickle_check gradio_port gradio_auth search_paperspace_datasets ui_theme insecure_extension_access"
2022-09-08 13:02:54 -06:00
]
},
2022-10-06 23:29:36 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-10-30 13:52:49 -06:00
"<mark>If you see any errors please check your settings!</mark>\n",
"\n",
"**Don't forget, there's a block in the Tools section at the bottom to update this notebook to [the latest version](https://github.com/Engineer-of-Stuff/stable-diffusion-paperspace/blob/main/StableDiffusionUI_Voldemort_paperspace.ipynb) on GitHub.**"
2022-10-06 23:29:36 -06:00
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
2022-11-30 20:54:29 -07:00
"## Clone the WebUI repository"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
2022-09-08 19:55:21 -06:00
"id": "sBbcB4vwj_jm",
"tags": []
2022-09-08 13:02:54 -06:00
},
"outputs": [],
"source": [
2022-10-01 12:55:11 -06:00
"import os\n",
2022-11-09 23:28:37 -07:00
"%store -r symlink_to_notebooks model_storage_dir repo_storage_dir\n",
2022-12-06 12:46:30 -07:00
"# You'll see this little code block at the beginning of every cell. It makes sure you have ran the first block that defines your settings.\n",
2022-12-01 16:24:24 -07:00
"try:\n",
" test = [symlink_to_notebooks, model_storage_dir, repo_storage_dir, activate_xformers, link_novelai_anime_vae, download_scripts, activate_deepdanbooru, activate_medvram, disable_pickle_check, gradio_port, gradio_auth, search_paperspace_datasets, ui_theme]\n",
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
"\n",
2022-10-04 10:57:09 -06:00
"%cd /notebooks/\n",
2022-10-01 12:55:11 -06:00
"\n",
"def delete_broken_symlinks(path):\n",
" # make sure to pass this function a path without a trailing slash\n",
" for file in os.listdir(path):\n",
" if os.path.islink(f'{path}/{file}') and not os.path.exists(os.readlink(f'{path}/{file}')):\n",
" print(f'Symlink broken, removing: {file}')\n",
" os.unlink(f'{path}/{file}')\n",
"\n",
2022-10-06 23:29:36 -06:00
"def update_repo_if_not_exists(path, repo_clone_url, pre=None):\n",
" if pre is not None:\n",
" pre() \n",
" if not os.path.exists(path):\n",
" !git clone \"{repo_clone_url}\" \"{path}\"\n",
" else:\n",
" print(f'{repo_clone_url.split(\"/\")[-1]} already downloaded, updating...')\n",
2022-10-07 00:09:27 -06:00
" !cd \"{path}\" && git pull # no % so we don't interfere with the main process\n",
2022-10-06 23:29:36 -06:00
"\n",
"def init_free():\n",
2022-11-09 23:28:37 -07:00
" if (symlink_to_notebooks and repo_storage_dir != '/notebooks'):\n",
2022-10-01 12:55:11 -06:00
" delete_broken_symlinks('/notebooks/') # remove broken symlinks since it might have been installed in a non-persistent directory\n",
2022-10-04 10:57:09 -06:00
" if not os.path.exists(repo_storage_dir):\n",
2022-10-01 13:41:10 -06:00
" !mkdir -p \"{repo_storage_dir}\"\n",
" !ln -s \"{repo_storage_dir}\" /notebooks/\n",
2022-10-06 23:29:36 -06:00
" !ls -la /notebooks/stable-diffusion\n",
"update_repo_if_not_exists(f'{repo_storage_dir}/stable-diffusion-webui', 'https://github.com/AUTOMATIC1111/stable-diffusion-webui', init_free)"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "C68TUpkq0nj_",
"tags": []
},
"source": [
2022-10-31 19:34:37 -06:00
"## Install requirements and download repositories"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SaAJk33ppFw1",
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
2022-11-09 23:28:37 -07:00
"%store -r symlink_to_notebooks model_storage_dir repo_storage_dir activate_xformers download_scripts activate_deepdanbooru\n",
2022-12-01 16:24:24 -07:00
"try:\n",
" test = [symlink_to_notebooks, model_storage_dir, repo_storage_dir, activate_xformers, link_novelai_anime_vae, download_scripts, activate_deepdanbooru, activate_medvram, disable_pickle_check, gradio_port, gradio_auth, search_paperspace_datasets, ui_theme]\n",
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-01 12:55:11 -06:00
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
2022-11-30 20:54:29 -07:00
"\n",
"!pip install --upgrade pip\n",
"\n",
2022-10-18 09:51:36 -06:00
"import os\n",
2022-09-08 13:02:54 -06:00
"\n",
2022-09-21 12:51:39 -06:00
"# Import launch.py which will automatically run the install script but not launch the WebUI.\n",
"# They require a few specific external git repo commits so we have to do it their way. \n",
"import launch\n",
2022-10-18 09:51:36 -06:00
"launch.prepare_enviroment()\n",
2022-09-21 12:51:39 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"# The installer isn't installing deepdanbooru right now so we'll do it manually\n",
"if activate_deepdanbooru:\n",
" !pip install \"git+https://github.com/KichangKim/DeepDanbooru.git@edf73df4cdaeea2cf00e9ac08bd8a9026b7a7b26#egg=deepdanbooru[tensorflow]\" # tensorflow==2.10.0 tensorflow-io==0.27.0 flatbuffers==1.12\n",
2022-10-06 23:29:36 -06:00
"\n",
2022-10-04 10:57:09 -06:00
"# latent-diffusion is a requirement but launch.py isn't downloading it so we'll do it manually.\n",
"if not os.path.exists(f'{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion'):\n",
" !git clone https://github.com/crowsonkb/k-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/k-diffusion\"\n",
2022-10-01 12:55:11 -06:00
" !git clone https://github.com/Hafiidz/latent-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion\"\n",
"\n",
2022-11-21 02:07:10 -07:00
"# For things in this notebook\n",
"!pip install requests\n",
" \n",
2022-10-06 23:29:36 -06:00
"# Download popular custom scripts. This is basically remote code execution so be careful.\n",
"# See https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts\n",
2022-10-18 09:51:36 -06:00
"if download_scripts:\n",
" import shutil\n",
" import requests\n",
" !pip install moviepy==1.0.3\n",
" !apt update\n",
" !apt install -y potrace python3-tk\n",
"\n",
" def download_file_dir(url, output_dir):\n",
" # output_dir must have a trailing slash\n",
" local_filename = url.split('/')[-1]\n",
" with requests.get(url, stream=True) as r:\n",
" r.raise_for_status()\n",
" with open(f'{output_dir}{local_filename}', 'wb') as f:\n",
" for chunk in r.iter_content(chunk_size=8192):\n",
" f.write(chunk)\n",
" return local_filename\n",
" def do_script_download(scripts_list, domain, path):\n",
" for item in scripts_list:\n",
" download_file_dir(f'https://{domain}/{item}', path)\n",
" print(f'{item.split(\"/\")[-1]} downloaded...')\n",
"\n",
" do_script_download([\n",
" 'GRMrGecko/stable-diffusion-webui-automatic/advanced_matrix/scripts/advanced_prompt_matrix.py',\n",
" 'dfaker/stable-diffusion-webui-cv2-external-masking-script/main/external_masking.py',\n",
" 'memes-forever/Stable-diffusion-webui-video/main/videos.py',\n",
" 'yownas/seed_travel/main/scripts/seed_travel.py',\n",
" 'Animator-Anon/Animator/main/animation.py',\n",
" 'Filarius/stable-diffusion-webui/master/scripts/vid2vid.py',\n",
" 'GeorgLegato/Txt2Vectorgraphics/main/txt2vectorgfx.py',\n",
" 'yownas/shift-attention/main/scripts/shift_attention.py',\n",
" 'DiceOwl/StableDiffusionStuff/main/loopback_superimpose.py',\n",
" 'Engineer-of-Stuff/stable-diffusion-paperspace/main/lfs/save_steps.py',\n",
" 'Pfaeff/sd-web-ui-scripts/main/moisaic.py'\n",
" ], 'raw.githubusercontent.com', f'{repo_storage_dir}/stable-diffusion-webui/scripts/')\n",
"\n",
" do_script_download([\n",
" 'dfaker/f88aa62e3a14b559fe4e5f6b345db664/raw/791dabfa0ab26399aa2635bcbc1cf6267aa4ffc2/alternate_sampler_noise_schedules.py',\n",
" 'camenduru/9ec5f8141db9902e375967e93250860f/raw/c1a03eb447548adbef1858c0e69d3567a390d2f4/run_n_times.py'\n",
" ], 'gist.githubusercontent.com', f'{repo_storage_dir}/stable-diffusion-webui/scripts/')\n",
"\n",
" # Download and set up txt2img2img\n",
" update_repo_if_not_exists(f'{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root', 'https://github.com/ThereforeGames/txt2img2img.git')\n",
" !cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root/scripts\" \"{repo_storage_dir}/stable-diffusion-webui\"\n",
" !cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root/txt2img2img\" \"{repo_storage_dir}/stable-diffusion-webui\"\n",
" !cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root/venv\" \"{repo_storage_dir}/stable-diffusion-webui\"\n",
"\n",
" # Download and set up txt2mask\n",
" update_repo_if_not_exists(f'{repo_storage_dir}/stable-diffusion-webui/txt2mask', 'https://github.com/ThereforeGames/txt2mask.git')\n",
" !echo \"Copying txt2mask...\"\n",
" !cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2mask/repositories/clipseg\" \"{repo_storage_dir}/stable-diffusion-webui/repositories\"\n",
" !cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2mask/scripts/\" \"{repo_storage_dir}/stable-diffusion-webui/\"\n",
"\n",
2022-10-30 14:08:23 -06:00
" # Install the dynamic-prompts/wildcard script\n",
2022-12-01 16:24:24 -07:00
" # !git clone https://github.com/adieyal/sd-dynamic-prompting/ extensions/dynamic-prompts\n",
2022-10-18 09:51:36 -06:00
"\n",
"if activate_xformers:\n",
2022-11-03 13:25:32 -06:00
" print('Installing xformers...')\n",
2022-11-01 18:59:16 -06:00
" import subprocess\n",
" def download_release(url):\n",
" binary = 'xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl' # have to save the binary as a specific name that pip likes\n",
" tmp_dir = subprocess.check_output(['mktemp', '-d']).decode('ascii').strip('\\n')\n",
" !wget \"{url}\" -O \"{tmp_dir}/{binary}\"\n",
" return os.path.join(tmp_dir, binary)\n",
"\n",
2022-10-18 09:51:36 -06:00
" # Set up pip packages\n",
" !pip uninstall -y torch torchvision torchaudio # Remove existing pytorch install.\n",
" !pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 # Install pytorch for cuda 11.3\n",
2022-11-03 13:25:32 -06:00
" s = subprocess.getoutput('nvidia-smi')\n",
2022-10-18 09:51:36 -06:00
" if 'A4000' in s:\n",
2022-11-01 18:59:16 -06:00
" xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/A4000-Oct-28-2022/a4000-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
" elif 'A5000' in s:\n",
" xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/A5000-Nov-1-2022/a5000-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
" elif 'A6000' in s:\n",
" xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/A6000-Nov-1-2022/a6000-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
2022-10-18 09:51:36 -06:00
" elif 'P5000' in s:\n",
2022-11-01 18:59:16 -06:00
" xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/P5000-Nov-1-2022/p5000-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
2022-10-18 09:51:36 -06:00
" elif 'RTX 4000' in s:\n",
2022-11-01 18:59:16 -06:00
" xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/RTX-4000-Nov-1-2022/rtx4000-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
" elif 'RTX 5000' in s:\n",
" xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/RTX-5000-Nov-1-2022/rtx5000-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
2022-10-27 10:00:21 -06:00
" elif 'A100' in s:\n",
2022-11-01 18:59:16 -06:00
" xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/A100-Nov-1-2022/a100-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
" elif 'M4000' in s:\n",
" print('xformers for M4000 hasn\\'t been built yet.')\n",
" # xformers_whl = download_release('https://github.com/Cyberes/xformers-compiled/releases/download/A100-Nov-1-2022/a100-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl')\n",
2022-10-18 09:51:36 -06:00
" else:\n",
2022-10-30 13:52:49 -06:00
" print('GPU not matched to xformers binary so a one-size-fits-all binary was installed. If you have any issues, please build xformers using the Tools block below.')\n",
2022-11-01 18:59:16 -06:00
" xformers_whl = download_release('https://raw.githubusercontent.com/Cyberes/xformers-compiled/main/various/xformers-0.0.14.dev0-cp37-cp37m-linux_x86_64.whl')\n",
" !pip install --force-reinstall \"{xformers_whl}\"\n",
2022-10-06 23:29:36 -06:00
"\n",
2022-09-21 12:51:39 -06:00
"# Make sure your models storage directory exists\n",
2022-10-18 09:51:36 -06:00
"!mkdir -p \"{model_storage_dir}/hypernetworks\"\n",
2022-11-30 20:54:29 -07:00
"!mkdir -p \"{model_storage_dir}/vae\"\n",
2022-10-18 09:51:36 -06:00
"!mkdir -p \"{repo_storage_dir}/stable-diffusion-webui/models/hypernetworks\"\n",
2022-09-28 22:32:59 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"# Link the output folders to /notebooks/outputs\n",
"!mkdir -p \"{repo_storage_dir}/stable-diffusion-webui/log/images\"\n",
2022-10-01 12:55:11 -06:00
"!mkdir -p \"{repo_storage_dir}/stable-diffusion-webui/outputs\"\n",
2022-10-18 09:51:36 -06:00
"!ln -s \"{repo_storage_dir}/stable-diffusion-webui/outputs\" /notebooks/\n",
"!ln -s \"{repo_storage_dir}/stable-diffusion-webui/log\" \"{repo_storage_dir}/stable-diffusion-webui/outputs\"\n",
"\n",
2022-11-30 20:54:29 -07:00
"# Link /storage/ to /notebooks/\n",
"!ln -s /storage/ /notebooks/\n",
"\n",
2022-11-03 13:25:32 -06:00
"!echo -e \"\\n===================================\\nDone! If you're seeing this the process has exited successfully.\\n\""
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
2022-09-08 15:49:49 -06:00
"id": "F0EINk5M0s-w",
"tags": []
2022-09-08 13:02:54 -06:00
},
"source": [
2022-10-31 19:34:37 -06:00
"## Download the Model"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-10-27 10:00:21 -06:00
"You don't need to repeat this step if you've already downloaded the models.\n",
2022-09-08 19:55:21 -06:00
"\n",
2022-10-27 10:00:21 -06:00
"<br>\n",
2022-09-08 19:55:21 -06:00
"\n",
2022-10-27 10:00:21 -06:00
"**There are additional models available here: https://cyberes.github.io/stable-diffusion-models**\n",
2022-09-09 12:15:51 -06:00
"\n",
2022-10-27 10:00:21 -06:00
"Textual inversion: https://cyberes.github.io/stable-diffusion-textual-inversion-models\n",
"\n",
"DreamBooth: https://cyberes.github.io/stable-diffusion-dreambooth-library\n",
"\n",
"<br>\n",
2022-09-10 14:24:12 -06:00
"\n",
2022-10-31 19:34:37 -06:00
"### Filesize and Storage Disclaimer\n",
2022-10-27 10:00:21 -06:00
"\n",
"Paperspace free tier has only 5GB of storage space. If you're having storage issues, here are a few suggestions.\n",
2022-11-30 20:54:29 -07:00
"1. Download everything to `/tmp/` each time you start the machine.\n",
2022-10-01 12:55:11 -06:00
"2. Add a payment method to your account. Storage overages are billed at \\$0.29/GB and billing occurs monthly and runs at midnight on the first of each month. With a payment method on file, Paperspace will let you use more storage and if you time it right you shouldn't actually be charged for it.\n",
"3. Upgrade to a Pro account. They'll give you 15GB and you'll get longer runtimes and more powerful free GPUs.\n",
2022-11-30 20:54:29 -07:00
"4. Use my referral code `KQLRH37`. You'll get \\$10 credit that you should be able to put towards the storage overage charges. Redeem the code at the bottom of the Billing page.\n",
2022-09-14 10:16:23 -06:00
"\n",
2022-10-31 19:34:37 -06:00
"### Torrent Instructions\n",
2022-09-14 10:16:23 -06:00
"\n",
"Aria2 may show some errors/warnings while downloading. Those are fine, when it eventually says \"Download Complete\" that means everything worked as it should."
2022-09-08 13:02:54 -06:00
]
},
2022-11-30 20:54:29 -07:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Stable Diffusion 2.0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**768x768**\n",
"\n",
"This model can generate images 768 pixels by 768 pixels."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-12-01 16:24:24 -07:00
"!wget https://huggingface.co/stabilityai/stable-diffusion-2/resolve/main/768-v-ema.ckpt -O \"{model_storage_dir}/sd-v2-0-768-v-ema.ckpt\"\n",
"!wget https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yaml -O \"{model_storage_dir}/sd-v2-0-768-v-ema.yaml\""
2022-11-30 20:54:29 -07:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**512x512 Base**\n",
"\n",
"Referred to as the \"base\" model, this model generates images in the standard 512x512 resolution."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-12-01 16:24:24 -07:00
"!wget https://huggingface.co/stabilityai/stable-diffusion-2-base/resolve/main/512-base-ema.ckpt -O \"{model_storage_dir}/sd-v2-0-512-base-ema.ckpt\"\n",
"!wget https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yaml -O \"{model_storage_dir}/sd-v2-0-512-base-ema.yaml\""
2022-11-30 20:54:29 -07:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Depth Model**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
"!wget https://huggingface.co/stabilityai/stable-diffusion-2-depth/resolve/main/512-depth-ema.ckpt -O \"{model_storage_dir}/sd-v2-0-512-depth-ema.ckpt\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**4x Upscaler**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
"!wget https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler/resolve/main/x4-upscaler-ema.ckpt -O \"{model_storage_dir}/sd-v2-0-x4-upscaler-ema.ckpt\""
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
2022-11-30 20:54:29 -07:00
"### Stable Diffusion 1.0"
2022-10-27 10:00:21 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-11-13 02:58:41 -07:00
"**v1.5**\n",
"\n",
2022-11-13 11:47:51 -07:00
"Paperspace includes this model in its public data sources, which don't use up your storage quota. To add it, click on `Data Sources` in the toolbar, `Public`, and `stable-diffusion-classic`. The file is mounted at `/datasets/stable-diffusion-classic/`. You only need to do this once, it will stay mounted between sessions. Make sure the setting `search_paperspace_datasets` is set to `True` so the program will link it to the WebUI.\n",
"\n",
"Otherwise, you can download it yourself:"
2022-10-27 10:00:21 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-27 10:00:21 -06:00
"!apt update\n",
"!apt install -y aria2\n",
2022-11-03 13:25:32 -06:00
"%cd \"{model_storage_dir}\"\n",
2022-11-30 20:54:29 -07:00
"!aria2c --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:2daef5b5f63a16a9af9169a529b1a773fc452637&dn=v1-5-pruned-emaonly.ckpt&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&tr=udp%3a%2f%2f9.rarbg.com%3a2810%2fannounce&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a6969%2fannounce&tr=udp%3a%2f%2fopentracker.i2p.rocks%3a6969%2fannounce&tr=https%3a%2f%2fopentracker.i2p.rocks%3a443%2fannounce&tr=http%3a%2f%2ftracker.openbittorrent.com%3a80%2fannounce&tr=udp%3a%2f%2ftracker.torrent.eu.org%3a451%2fannounce&tr=udp%3a%2f%2fopen.stealth.si%3a80%2fannounce&tr=udp%3a%2f%2fvibe.sleepyinternetfun.xyz%3a1738%2fannounce&tr=udp%3a%2f%2ftracker2.dler.org%3a80%2fannounce&tr=udp%3a%2f%2ftracker1.bt.moack.co.kr%3a80%2fannounce&tr=udp%3a%2f%2ftracker.zemoj.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.tiny-vps.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.theoks.net%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.publictracker.xyz%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.monitorit4.me%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.moeking.me%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.lelux.fi%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.dler.org%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.army%3a6969%2fannounce\"\n",
"!mv \"v1-5-pruned-emaonly.ckpt\" \"sd-v1-5-pruned-emaonly.ckpt\""
2022-10-27 10:00:21 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**v1.5 Inpainting**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-27 10:00:21 -06:00
"!apt update\n",
"!apt install -y aria2\n",
2022-11-03 13:25:32 -06:00
"%cd \"{model_storage_dir}\"\n",
2022-10-27 10:00:21 -06:00
"!aria2c --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:b523a9e71ae02e27b28007eca190f41999c2add1&dn=sd-v1-5-inpainting.ckpt&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&tr=udp%3a%2f%2f9.rarbg.com%3a2810%2fannounce&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a6969%2fannounce&tr=http%3a%2f%2ftracker.openbittorrent.com%3a80%2fannounce&tr=udp%3a%2f%2fopentracker.i2p.rocks%3a6969%2fannounce&tr=https%3a%2f%2fopentracker.i2p.rocks%3a443%2fannounce&tr=udp%3a%2f%2ftracker.torrent.eu.org%3a451%2fannounce&tr=udp%3a%2f%2fopen.stealth.si%3a80%2fannounce&tr=udp%3a%2f%2fvibe.sleepyinternetfun.xyz%3a1738%2fannounce&tr=udp%3a%2f%2ftracker2.dler.org%3a80%2fannounce&tr=udp%3a%2f%2ftracker1.bt.moack.co.kr%3a80%2fannounce&tr=udp%3a%2f%2ftracker.zemoj.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.tiny-vps.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.theoks.net%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.swateam.org.uk%3a2710%2fannounce&tr=udp%3a%2f%2ftracker.publictracker.xyz%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.pomf.se%3a80%2fannounce&tr=udp%3a%2f%2ftracker.monitorit4.me%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.moeking.me%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.lelux.fi%3a6969%2fannounce\""
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-10-27 10:00:21 -06:00
"**v1.4**"
2022-09-08 19:55:21 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
2022-10-01 12:55:11 -06:00
"metadata": {
"tags": []
},
2022-09-08 19:55:21 -06:00
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-09-08 19:55:21 -06:00
"!apt update\n",
"!apt install -y aria2\n",
2022-11-03 13:25:32 -06:00
"%cd \"{model_storage_dir}\"\n",
2022-10-18 09:51:36 -06:00
"!aria2c --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:3A4A612D75ED088EA542ACAC52F9F45987488D1C&tr=udp://tracker.opentrackr.org:1337/announce\""
2022-09-08 19:55:21 -06:00
]
},
{
"cell_type": "markdown",
2022-10-18 09:51:36 -06:00
"metadata": {
"tags": []
},
2022-09-08 19:55:21 -06:00
"source": [
2022-10-31 19:34:37 -06:00
"### Waifu Diffusion"
2022-10-27 10:00:21 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-10-18 09:51:36 -06:00
"**v1.3**"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
2022-10-18 09:51:36 -06:00
"metadata": {},
2022-09-08 13:02:54 -06:00
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-18 09:51:36 -06:00
"!apt update\n",
"!apt install -y aria2\n",
"%cd \"{model_storage_dir}\"\n",
"!aria2c --seed-time=0 --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:AWJJJZNFOOK7R2XXXGZ4GFNKUEU2TSFP&dn=wd-v1-3-float16.ckpt&xl=2132889245&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce\""
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
2022-10-18 09:51:36 -06:00
"metadata": {},
2022-09-08 13:02:54 -06:00
"source": [
2022-10-18 09:51:36 -06:00
"**v1.2**"
2022-09-08 13:02:54 -06:00
]
},
2022-09-08 15:49:49 -06:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-09-09 12:40:33 -06:00
"!apt update\n",
"!apt install -y aria2\n",
2022-10-01 12:55:11 -06:00
"%cd \"{model_storage_dir}\"\n",
2022-10-18 09:51:36 -06:00
"!aria2c --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:153590FD7E93EE11D8DB951451056C362E3A9150&dn=wd-v1-2-full-ema-pruned.ckpt&tr=udp://tracker.opentrackr.org:1337\""
2022-09-09 12:40:33 -06:00
]
},
2022-09-11 17:44:13 -06:00
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
2022-10-31 19:34:37 -06:00
"### trinart_stable_diffusion_v2"
2022-09-11 17:44:13 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-10-01 12:55:11 -06:00
"Another anime finetune. Designed to nudge SD to an anime/manga style. Seems to be more \"stylized\" and \"artistic\" than Waifu Diffusion, if that makes any sense.\n",
2022-09-11 18:07:05 -06:00
"\n",
2022-10-01 12:55:11 -06:00
"The 60,000 steps version is the original, the 115,000 and 95,000 versions is the 60,000 with additional training. Use the 60,000 step version if the style nudging is too much.\n",
2022-09-18 13:16:32 -06:00
"\n",
2022-09-28 22:51:29 -06:00
"[See the comparison here.](https://cyberes.github.io/stable-diffusion-models/#model-comparison)"
2022-09-11 18:07:05 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-09-18 00:25:08 -06:00
"**60000**"
2022-09-11 17:44:13 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-01 12:55:11 -06:00
"!wget https://huggingface.co/naclbit/trinart_stable_diffusion_v2/resolve/main/trinart2_step60000.ckpt -O \"{model_storage_dir}/trinart2_step60000.ckpt\""
2022-09-11 17:44:13 -06:00
]
},
2022-09-11 18:07:05 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-09-18 00:25:08 -06:00
"**95000**"
2022-09-11 18:07:05 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-01 12:55:11 -06:00
"!wget https://huggingface.co/naclbit/trinart_stable_diffusion_v2/resolve/main/trinart2_step95000.ckpt -O \"{model_storage_dir}/trinart2_step95000.ckpt\""
2022-09-08 15:49:49 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-09-18 00:25:08 -06:00
"**115000**"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-01 12:55:11 -06:00
"!wget https://huggingface.co/naclbit/trinart_stable_diffusion_v2/resolve/main/trinart2_step115000.ckpt -O \"{model_storage_dir}/trinart2_step115000.ckpt\""
2022-09-08 13:02:54 -06:00
]
},
2022-10-27 10:00:21 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-10-31 19:34:37 -06:00
"### trinart_characters_19-2m_stable_diffusion_v1\n",
2022-10-27 10:00:21 -06:00
"\n",
"Trained on 19.2M anime/manga-style images. This model seeks for a sweet spot between artistic style and anatomical quality."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-27 10:00:21 -06:00
"!wget https://huggingface.co/naclbit/trinart_characters_19.2m_stable_diffusion_v1/resolve/main/trinart_characters_it4_v1.ckpt -O \"{model_storage_dir}/trinart_characters_it4_v1.ckpt\""
]
},
2022-10-18 09:51:36 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-10-31 19:34:37 -06:00
"### NovelAI Leak"
2022-10-18 09:51:36 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**animefull-final-pruned**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-18 09:51:36 -06:00
"!apt update\n",
"!apt install -y aria2\n",
"metalink = 'magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc&dn=novelaileak&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce'\n",
"import re\n",
"infohash = re.search(\"^magnet:\\?xt=urn:btih:(.*?)&.*?$\", metalink).group(1)\n",
"import subprocess\n",
"tmp_dir = subprocess.check_output(['mktemp', '-d']).decode('ascii').strip('\\n')\n",
"%cd \"{tmp_dir}\"\n",
"# Have to convert the metalink to a torrent file so aria2c can read the files inside\n",
"!aria2c -d . --bt-metadata-only=true --bt-save-metadata=true --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc&dn=novelaileak&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce\"\n",
"!aria2c --select-file=64,65 --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"{infohash}.torrent\"\n",
"!mv \"novelaileak/stableckpt/animefull-final-pruned/config.yaml\" \"{model_storage_dir}/novelai-animefull-final-pruned.yaml\"\n",
"!mv \"novelaileak/stableckpt/animefull-final-pruned/model.ckpt\" \"{model_storage_dir}/novelai-animefull-final-pruned.ckpt\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**animesfw-final-pruned**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-18 09:51:36 -06:00
"!apt update\n",
"!apt install -y aria2\n",
"metalink = 'magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc&dn=novelaileak&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce'\n",
"import re\n",
"infohash = re.search(\"^magnet:\\?xt=urn:btih:(.*?)&.*?$\", metalink).group(1)\n",
"import subprocess\n",
"tmp_dir = subprocess.check_output(['mktemp', '-d']).decode('ascii').strip('\\n')\n",
"%cd \"{tmp_dir}\"\n",
"# Have to convert the metalink to a torrent file so aria2c can read the files inside\n",
"!aria2c -d . --bt-metadata-only=true --bt-save-metadata=true --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc&dn=novelaileak&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce\"\n",
"!aria2c --select-file=70,71 --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"{infohash}.torrent\"\n",
"!mv \"novelaileak/stableckpt/animesfw-final-pruned/config.yaml\" \"{model_storage_dir}/novelai-animesfw-final-pruned.yaml\"\n",
"!mv \"novelaileak/stableckpt/animesfw-final-pruned/model.ckpt\" \"{model_storage_dir}/novelai-animesfw-final-pruned.ckpt\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Hypernetworks**\n",
"\n",
"A hypernetwork is trained much like a neural network and helps to guide the neural net towards the intended output."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-06 12:46:30 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-18 09:51:36 -06:00
"!apt update\n",
"!apt install -y aria2\n",
"metalink = 'magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc&dn=novelaileak&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce'\n",
"import re\n",
"infohash = re.search(\"^magnet:\\?xt=urn:btih:(.*?)&.*?$\", metalink).group(1)\n",
"import subprocess\n",
"tmp_dir = subprocess.check_output(['mktemp', '-d']).decode('ascii').strip('\\n')\n",
"%cd \"{tmp_dir}\"\n",
"# Have to convert the metalink to a torrent file so aria2c can read the files inside\n",
"!aria2c -d . --bt-metadata-only=true --bt-save-metadata=true --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc&dn=novelaileak&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce\"\n",
"!aria2c --select-file=76,81,82,83,84,85,86,87,88,89,90,91,92,93 --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"{infohash}.torrent\"\n",
"# -exec mv doesn't work with python variables so we'll set an environment variable instead\n",
"import os\n",
"os.environ[\"MODEL_STORAGE_DIR\"] = model_storage_dir\n",
"!rm novelaileak/stableckpt/extra-sd-prune/sd-prune/anime700k-64bs-0.1ucg-penultimate-1epoch-clip-ema-continue-76000.pt # aria2 downloads this file even though I told it not to\n",
"!find novelaileak/ -type f -name '*.pt' -exec mv {} \"$MODEL_STORAGE_DIR/hypernetworks\" \\;"
]
},
2022-09-09 10:19:44 -06:00
{
"cell_type": "markdown",
2022-09-10 14:24:12 -06:00
"metadata": {
"tags": []
},
2022-09-09 10:19:44 -06:00
"source": [
2022-10-31 19:34:37 -06:00
"## Clean up and restart the kernel"
2022-09-09 10:19:44 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-05 22:29:39 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-05 22:29:39 -07:00
" test = [model_storage_dir, repo_storage_dir]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-09-16 13:07:57 -06:00
"\n",
"# Get some storage back\n",
"!pip cache purge\n",
2022-10-01 12:55:11 -06:00
"!cd \"{model_storage_dir}\" && rm *.aria2\n",
2022-09-28 22:32:59 -06:00
"!apt remove --purge -y aria2 p7zip-full\n",
2022-09-21 12:51:39 -06:00
"!apt autoremove --purge -y\n",
2022-09-21 12:57:16 -06:00
"!apt clean\n",
2022-09-16 13:07:57 -06:00
"\n",
"# Restart the kernel\n",
2022-09-09 10:19:44 -06:00
"import os\n",
"os.kill(os.getpid(), 9)"
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "markdown",
2022-09-18 00:25:08 -06:00
"metadata": {},
2022-09-08 13:02:54 -06:00
"source": [
2022-10-31 19:34:37 -06:00
"## Link the models directory\n",
2022-09-18 00:25:08 -06:00
"\n",
2022-09-18 13:13:28 -06:00
"Create symlinks. The file will be stored in the models storage directory and linked to where the WebUI expects the files to be."
2022-09-08 13:02:54 -06:00
]
},
{
2022-09-18 00:25:08 -06:00
"cell_type": "code",
"execution_count": null,
2022-09-08 13:02:54 -06:00
"metadata": {},
2022-09-18 00:25:08 -06:00
"outputs": [],
2022-09-08 13:02:54 -06:00
"source": [
2022-11-13 11:47:51 -07:00
"%store -r model_storage_dir repo_storage_dir link_novelai_anime_vae search_paperspace_datasets\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-05 22:29:39 -07:00
" test = [model_storage_dir, repo_storage_dir, link_novelai_anime_vae, search_paperspace_datasets]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-09-18 00:25:08 -06:00
"import os\n",
2022-10-18 09:51:36 -06:00
"import glob\n",
2022-11-13 11:47:51 -07:00
"import subprocess\n",
2022-11-30 20:54:29 -07:00
"import re\n",
"from pathlib import Path\n",
"import sys\n",
"\n",
"if not os.path.isdir(model_storage_dir):\n",
" print('Your model storage directory does not exist:', model_storage_dir)\n",
" sys.exit(1)\n",
"\n",
"webui_model_path = Path(repo_storage_dir, 'stable-diffusion-webui/models')\n",
"webui_sd_models = Path(webui_model_path, 'Stable-diffusion')\n",
"webui_hypernetworks = Path(webui_model_path, 'hypernetworks')\n",
"webui_vaes = Path(webui_model_path, 'VAE')\n",
2022-10-18 09:51:36 -06:00
"\n",
"def delete_broken_symlinks(dir):\n",
" deleted = False\n",
" for file in os.listdir(dir):\n",
" path = f'{dir}/{file}'\n",
" if os.path.islink(path) and not os.path.exists(os.readlink(path)):\n",
" print(f'Symlink broken, removing: {file}')\n",
" os.unlink(path)\n",
" deleted = True\n",
" if deleted:\n",
" print('')\n",
2022-11-30 20:54:29 -07:00
" \n",
"def create_symlink(source, dest):\n",
" if os.path.isdir(dest):\n",
" dest = Path(dest, os.path.basename(source))\n",
" if not os.path.exists(dest):\n",
" !ln -s \"{source}\" \"{dest}\"\n",
" print(source, '->', Path(dest).absolute())\n",
2022-09-18 17:28:01 -06:00
"\n",
"# Check for broken symlinks and remove them\n",
2022-11-30 20:54:29 -07:00
"print('Removing broken symlinks...')\n",
"delete_broken_symlinks(webui_sd_models)\n",
"delete_broken_symlinks(webui_hypernetworks)\n",
"delete_broken_symlinks(webui_vaes)\n",
"\n",
"# Link .ckpt files (recursive)\n",
"print('\\nLinking .ckpt files...')\n",
"for file in glob.glob(f'{model_storage_dir}/**/*.ckpt', recursive=True):\n",
" if not re.search(r'hypernetworks|vae', file):\n",
" if not os.path.exists(file):\n",
" print('New model:', os.path.basename(file))\n",
" create_symlink(file, webui_sd_models)\n",
2022-10-27 10:00:21 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"# Link config yaml files\n",
2022-11-30 20:54:29 -07:00
"print('\\nLinking config .yaml files...')\n",
"for file in glob.glob(f'{model_storage_dir}/**/*.yaml', recursive=True):\n",
" create_symlink(file, webui_sd_models)\n",
2022-09-18 17:28:01 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"# Link hypernetworks\n",
2022-11-30 20:54:29 -07:00
"print('\\nLinking hypernetworks...')\n",
"source_hypernetworks = Path(model_storage_dir, 'hypernetworks')\n",
"if os.path.isdir(source_hypernetworks):\n",
" for file in os.listdir(source_hypernetworks):\n",
" create_symlink(Path(source_hypernetworks, file), webui_hypernetworks)\n",
"else:\n",
" print('Hypernetwork storage directory not found:', source_hypernetworks)\n",
"\n",
"# Link VAEs\n",
"print('\\nLinking VAEs...')\n",
"source_vaes = Path(model_storage_dir, 'vae')\n",
"if os.path.isdir(source_vaes):\n",
" for file in os.listdir(source_vaes):\n",
" create_symlink(Path(source_vaes, file), webui_vaes)\n",
"else:\n",
" print('VAE storage directory not found:', source_vaes)\n",
2022-11-19 00:10:34 -07:00
"\n",
2022-10-18 09:51:36 -06:00
"# Link the NovelAI files for each of the NovelAI models\n",
2022-11-30 20:54:29 -07:00
"print('\\nLinking NovelAI files for each of the NovelAI models...')\n",
"for model in glob.glob(f'{model_storage_dir}/novelai-*.ckpt'):\n",
2022-10-18 09:51:36 -06:00
" yaml = model.replace('.ckpt', '.yaml')\n",
2022-11-30 20:54:29 -07:00
" if os.path.exists(yaml):\n",
" if not os.path.exists(yaml):\n",
" print(f'New NovelAI model config: {yaml}')\n",
" create_symlink(yaml, webui_sd_models)\n",
2022-10-18 09:51:36 -06:00
"\n",
"if link_novelai_anime_vae:\n",
2022-11-30 20:54:29 -07:00
" print('\\nLinking NovelAI anime VAE...')\n",
2022-10-18 09:51:36 -06:00
" for model in glob.glob('novelai-*.ckpt'):\n",
2022-11-30 20:54:29 -07:00
" if os.path.exists(Path(model_storage_dir, 'hypernetworks/animevae.pt')):\n",
2022-10-18 09:51:36 -06:00
" vae = model.replace('.ckpt', '.vae.pt')\n",
2022-11-30 20:54:29 -07:00
" if not os.path.exists(webui_vaes):\n",
2022-10-18 09:51:36 -06:00
" print(f'Linking NovelAI {vae} and {model}')\n",
2022-11-30 20:54:29 -07:00
" create_symlink(Path(model_storage_dir, 'hypernetworks/animevae.pt'), webui_vaes)\n",
2022-10-18 09:51:36 -06:00
" else:\n",
2022-11-13 11:47:51 -07:00
" print(f'{model_storage_dir}/hypernetworks/animevae.pt NOT FOUND')\n",
" \n",
"\n",
"if search_paperspace_datasets:\n",
2022-11-30 20:54:29 -07:00
" if os.path.isdir('/datasets'):\n",
" print('\\nSearching /datasets')\n",
" for file in glob.glob(f'/datasets/**/*.ckpt', recursive=True):\n",
" create_symlink(file, webui_sd_models)\n",
" else:\n",
" print('\\nNo datasets mounted!')"
2022-09-08 13:02:54 -06:00
]
},
2022-09-10 14:24:12 -06:00
{
"cell_type": "markdown",
2022-09-18 00:25:08 -06:00
"metadata": {
"id": "xt8lbdmC04ox"
},
2022-09-10 14:24:12 -06:00
"source": [
2022-09-18 00:25:08 -06:00
"# Launch the WebUI"
2022-09-10 14:24:12 -06:00
]
},
{
"cell_type": "markdown",
2022-10-06 23:29:36 -06:00
"metadata": {
"tags": []
},
2022-09-10 14:24:12 -06:00
"source": [
2022-09-18 00:25:08 -06:00
"Run this block to launch the WebUI. You will get a link to nnn.gradio.app, that's your WebUI. Follow it.\n",
"\n",
2022-11-01 18:59:16 -06:00
"See [shared.py](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/shared.py#L22) to view the code for the launch args. There's a lot of good info in there about exactly what the args do. If you aren't a programmer, [here's the wiki](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Command-Line-Arguments-and-Settings).\n",
2022-09-28 22:32:59 -06:00
"\n",
2022-10-06 23:29:36 -06:00
"#### Troubleshooting\n",
2022-09-28 22:32:59 -06:00
"- If you have any issues, try restarting the kernel.\n",
2022-10-06 23:29:36 -06:00
"- `EOFError: Ran out of input` probably means you ran out of storage space and the model `.ckpt` file wasn't downloaded completely. Try cleaning up your files. There are some helpful scripts in the Tools section below.\n",
2022-11-03 13:25:32 -06:00
"- `The file may be malicious, so the program is not going to read it` means the program encountered unexpected data in the model file (the technical term is \"pickle\"). Merging models can cause this. You can disable this feature by setting `disable_pickle_check` to True in the settings block.\n",
"- Try updating your notebook using the block in the Tools section below.\n",
"- If you're still having issues, delete `stable-diffusion-webui` and reinstall."
2022-09-10 14:24:12 -06:00
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {
2022-09-08 15:49:49 -06:00
"id": "R-xAdMA5wxXd",
2022-11-01 18:59:16 -06:00
"scrolled": true,
2022-09-08 15:49:49 -06:00
"tags": []
2022-09-08 13:02:54 -06:00
},
"outputs": [],
"source": [
2022-11-30 20:54:29 -07:00
"%store -r model_storage_dir repo_storage_dir activate_xformers activate_deepdanbooru activate_medvram disable_pickle_check gradio_port gradio_auth ui_theme insecure_extension_access\n",
2022-12-01 16:24:24 -07:00
"try:\n",
2022-12-05 22:29:39 -07:00
" test = [model_storage_dir, repo_storage_dir, activate_xformers, activate_deepdanbooru, activate_medvram, disable_pickle_check, gradio_port, gradio_auth, ui_theme, insecure_extension_access]\n",
2022-12-01 16:24:24 -07:00
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-11-30 20:54:29 -07:00
"\n",
2022-10-01 12:55:11 -06:00
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
2022-10-06 23:29:36 -06:00
"\n",
2022-11-21 02:07:10 -07:00
"# Code to set the options you want as defined in the very first block\n",
2022-10-18 09:51:36 -06:00
"x_arg = '--xformers' if activate_xformers else ''\n",
"dd_arg = '--deepdanbooru' if activate_deepdanbooru else ''\n",
2022-10-30 12:44:37 -06:00
"mvram_arg = '--medvram' if activate_medvram else ''\n",
2022-10-30 13:52:49 -06:00
"pickled = '--disable-safe-unpickle' if disable_pickle_check else ''\n",
"port = f'--port {gradio_port}' if gradio_port else '--share'\n",
2022-11-09 05:20:48 -07:00
"auth = f'--gradio-auth {gradio_auth} --enable-insecure-extension-access' if gradio_auth else ''\n",
2022-11-13 14:40:31 -07:00
"theme = f'--theme {ui_theme}' if ui_theme else ''\n",
2022-11-30 20:54:29 -07:00
"insecure_extension_access = '--enable-insecure-extension-access' if insecure_extension_access else ''\n",
2022-10-30 13:52:49 -06:00
"\n",
2022-10-06 23:29:36 -06:00
"# Launch args go below:\n",
2022-11-13 14:40:31 -07:00
"!python webui.py {x_arg} {dd_arg} {mvram_arg} {pickled} {port} {auth} {theme} --gradio-debug"
2022-09-09 15:48:47 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"# Export Generations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-09-28 22:32:59 -06:00
"This block will rename and compress the outputs with 7zip max compression. It expects you to have `log/` and `outputs/` in `/notebooks/stable-diffusion-webui/`."
2022-09-09 15:48:47 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
2022-09-10 14:24:12 -06:00
"metadata": {
"scrolled": true,
"tags": []
},
2022-09-09 15:48:47 -06:00
"outputs": [],
"source": [
2022-11-30 20:54:29 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-05 23:44:44 -07:00
"try:\n",
" test = [model_storage_dir, repo_storage_dir]\n",
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-09-10 06:21:31 -06:00
"!apt update\n",
2022-09-09 15:48:47 -06:00
"!apt install -y p7zip-full\n",
"from datetime import datetime\n",
"datetime_str = datetime.now().strftime('%m-%d-%Y_%H:%M:%S')\n",
"%cd /notebooks/\n",
2022-10-18 09:51:36 -06:00
"!mkdir -p \"{datetime_str}/log\"\n",
"!cd \"{repo_storage_dir}/stable-diffusion-webui/log/\" && mv * \"/notebooks/{datetime_str}/log\"\n",
2022-10-01 12:55:11 -06:00
"!cd \"{repo_storage_dir}/stable-diffusion-webui/outputs/\" && mv * \"/notebooks/{datetime_str}\"\n",
"!TEMP=\"/notebooks/{datetime_str}\" # find command has issues with ipynb variables??\n",
2022-12-06 12:46:30 -07:00
"!find \"{TEMP}\" -name .ipynb_checkpoints -exec rm -rf \"{}\" +\n",
2022-10-01 12:55:11 -06:00
"!7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on \"{datetime_str}.7z\" \"/notebooks/{datetime_str}/\""
2022-09-09 15:48:47 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Delete old output folder\n",
"\n",
"This block will delete the folder you just compressed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-10-27 10:00:21 -06:00
"# !rm -rf \"/notebooks/{datetime_str}/\"\n",
"# !echo Deleted /notebooks/{datetime_str}/"
2022-09-08 15:49:49 -06:00
]
2022-09-10 14:24:12 -06:00
},
{
"cell_type": "markdown",
"metadata": {
2022-09-18 17:28:01 -06:00
"jp-MarkdownHeadingCollapsed": true,
2022-09-10 14:24:12 -06:00
"tags": []
},
"source": [
"# Tools"
]
},
2022-09-11 16:42:53 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-09-28 22:32:59 -06:00
"### Show graphics card info"
2022-09-11 16:42:53 -06:00
]
},
2022-09-10 14:24:12 -06:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!nvidia-smi"
]
2022-09-11 16:42:53 -06:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-09-28 22:32:59 -06:00
"### Download the latest version of this notebook from Github\n",
2022-09-11 16:42:53 -06:00
"\n",
2022-09-18 13:17:48 -06:00
"Run this and refresh the page (press F5). Don't save anything or you will overwrite the downloaded file."
2022-09-11 16:42:53 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-09-28 22:32:59 -06:00
"!mv /notebooks/StableDiffusionUI_Voldemort_paperspace.ipynb /notebooks/StableDiffusionUI_Voldemort_paperspace.ipynb.backup # save your old notebook to a backup\n",
2022-10-18 09:51:36 -06:00
"!wget https://raw.githubusercontent.com/Engineer-of-Stuff/stable-diffusion-paperspace/main/StableDiffusionUI_Voldemort_paperspace.ipynb -O /notebooks/StableDiffusionUI_Voldemort_paperspace.ipynb\n",
"!echo \"Downloaded! Now, refresh the page (press F5). Don't save anything or you will overwrite the downloaded file.\""
2022-09-11 16:42:53 -06:00
]
2022-09-28 22:32:59 -06:00
},
{
"cell_type": "markdown",
2022-10-06 23:29:36 -06:00
"metadata": {
"tags": []
},
2022-09-28 22:32:59 -06:00
"source": [
"### Reset Repository\n",
"\n",
2022-10-01 12:55:11 -06:00
"Sometimes AUTOMATIC1111 breaks something. Go to https://github.com/AUTOMATIC1111/stable-diffusion-webui/commits/master and choose a commit to revert to.\n",
"\n",
2022-10-18 09:51:36 -06:00
"If you're looking for a specific date, do: `git log --since='Sept 17 2022' --until='Sept 18 2022'`\n",
"\n",
"\n",
2022-10-01 12:55:11 -06:00
"**This shouldn't delete your outputs or any changes you've made to files, but I'd back up anything important just to be safe.**"
2022-09-28 22:32:59 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-06 12:46:30 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-05 23:44:44 -07:00
"try:\n",
" test = [model_storage_dir, repo_storage_dir]\n",
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-10-01 12:55:11 -06:00
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
2022-09-28 22:32:59 -06:00
"!git reset --hard <commit>"
]
},
2022-10-06 23:29:36 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Delete .ipynb_checkpoints\n",
"\n",
"Jupyter stores temporary files in folders named `.ipynb_checkpoints`. It gets a little excessive sometimes so if you're running low on storage space or getting weird errors about a directory named `.ipynb_checkpoints`, run this block."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!find . -type d -name .ipynb_checkpoints -delete"
]
},
2022-09-28 22:32:59 -06:00
{
"cell_type": "markdown",
2022-10-01 12:55:11 -06:00
"metadata": {
"tags": []
},
2022-09-28 22:32:59 -06:00
"source": [
2022-10-01 12:55:11 -06:00
"### Reset storage\n",
2022-09-28 22:32:59 -06:00
"\n",
2022-10-01 12:55:11 -06:00
"This will delete ALL your files in `/notebooks/`, `/storage/`, `model_storage_dir`, and `repo_storage_dir`. Use if you're having issues with zero storage space and you don't want to delete your notebook."
2022-09-28 22:32:59 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Uncomment the lines below to run this block. You can highlight the lines and do ctrl + /\n",
2022-12-01 16:24:24 -07:00
"# %store -r model_storage_dir repo_storage_dir\n",
"# YOU_DIDNT_RUN_THE_FIRST_BLOCK_WHERE_YOU_DEFINE_YOUR_SETTINGS()\n",
2022-09-28 22:32:59 -06:00
"# !rm -rf /storage/*\n",
2022-10-01 12:55:11 -06:00
"# !mv /notebooks/*.ipynb / # move the notebook out of the directory before we nuke it\n",
2022-09-28 22:32:59 -06:00
"# !rm -rf /notebooks/*\n",
2022-10-01 12:55:11 -06:00
"# !mv /*.ipynb /notebooks/ # move it back\n",
"# !rm -rf {model_storage_dir}\n",
"# !rm -rf {repo_storage_dir}"
2022-09-28 22:32:59 -06:00
]
2022-10-06 23:29:36 -06:00
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
2022-10-18 09:51:36 -06:00
"### Build and Install Xformers\n",
2022-10-06 23:29:36 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"This is an advanced feature that should boost your generation speeds.\n",
2022-10-06 23:29:36 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"1. Run the block below to download the install script to `/notebooks/`\n",
"2. Go to https://developer.nvidia.com/cuda-gpus and find the Cuda arch for your GPU model. It's likely 7.5, but double check.\n",
"3. Once you have read these instructions, uncomment the second line and insert your Cuda arch.\n",
2022-11-01 18:59:16 -06:00
"4. Enable xformers in the settings block above.\n",
2022-10-06 23:30:39 -06:00
"\n",
2022-10-18 09:51:36 -06:00
"If you have any issues, open the Jpyter Lab and run `build-xformers.sh` from the terminal."
2022-10-06 23:29:36 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-10-18 09:51:36 -06:00
"!wget https://raw.githubusercontent.com/Engineer-of-Stuff/stable-diffusion-paperspace/main/other/build-xformers.sh -O /notebooks/build-xformers.sh\n",
"# !bash /notebooks/build-xformers.sh [your cuda arch]\n",
"!echo \"COMPLETED!\""
2022-10-06 23:29:36 -06:00
]
2022-11-21 02:07:10 -07:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Automated Model Downloader\n",
"\n",
"Here's a tool to download a model from a torrent magnet link, web link, or HuggingFace."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2022-12-01 16:24:24 -07:00
"%store -r model_storage_dir repo_storage_dir\n",
2022-12-05 23:44:44 -07:00
"try:\n",
" test = [model_storage_dir, repo_storage_dir]\n",
"except NameError as e:\n",
" print(\"There is an issue with your variables.\")\n",
" print(\"Please go back to the first block and make sure your settings are correct, then run the cell.\")\n",
" print('Error:', e)\n",
" import sys\n",
" sys.exit(1)\n",
2022-12-01 16:24:24 -07:00
"\n",
2022-11-21 02:07:10 -07:00
"model_uri = input('URI of model to download: ')\n",
"import re\n",
"import requests\n",
"\n",
"def pretty_exit(str):\n",
" print(str)\n",
" raise\n",
2022-12-05 22:29:39 -07:00
"\n",
"if 'drive.google.com' in model_uri:\n",
" pretty_exit(\"Can't parse Google Drive links. Download the file yourself then upload it to the machine.\")\n",
"\n",
2022-11-21 02:07:10 -07:00
"magnet_match = re.search(r'magnet:\\?xt=urn:btih:[A-Za-z0-9&=%.]*', model_uri)\n",
"web_match = re.search(r'(https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,})', model_uri)\n",
"web_dl_file = None\n",
"if magnet_match:\n",
" !apt update\n",
" !apt install -y aria2\n",
" %cd \"{model_storage_dir}\"\n",
" bash_var = magnet_match[0]\n",
" !aria2c --seed-time=0 --max-overall-upload-limit=1K --bt-max-peers=120 --summary-interval=0 --file-allocation=none \"{bash_var}\"\n",
" exit\n",
"elif 'https://huggingface.co/' in model_uri:\n",
" response = requests.head(web_match[0], allow_redirects=True)\n",
" if 'octet-stream' not in response.headers['content-type']:\n",
" response = requests.head(web_match[0].replace('/blob/', '/resolve/'), allow_redirects=True)\n",
" if 'octet-stream' not in response.headers['content-type']:\n",
" pretty_exit(f'Wrong content-type: {response.headers[\"content-type\"].split(\";\")[0]}') if 'octet-stream' not in response.headers['content-type'] else None\n",
" else:\n",
" web_dl_file = web_match[0].replace('/blob/', '/resolve/')\n",
" else:\n",
" web_dl_file = web_match[0]\n",
"elif web_match:\n",
" response = requests.head(web_match[0], allow_redirects=True)\n",
" pretty_exit(f'Wrong content-type: {response.headers[\"content-type\"].split(\";\")[0]}') if 'octet-stream' not in response.headers['content-type'] else None\n",
" web_dl_file = web_match[0]\n",
"if web_dl_file is not None:\n",
" %cd \"{model_storage_dir}\"\n",
" !wget \"{web_dl_file}\" \n",
"else:\n",
" print('Could not parse your URI')"
]
2022-09-08 13:02:54 -06:00
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [],
"private_outputs": true,
"provenance": []
},
"gpuClass": "standard",
"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",
2022-11-21 02:07:10 -07:00
"version": "3.9.13"
2022-09-08 13:02:54 -06:00
}
},
"nbformat": 4,
"nbformat_minor": 4
}