Skip to content

Instantly share code, notes, and snippets.

@ShMcK
Last active April 12, 2024 16:45
Show Gist options
  • Save ShMcK/d14d90abea1437fdc9cfe8ecda864b06 to your computer and use it in GitHub Desktop.
Save ShMcK/d14d90abea1437fdc9cfe8ecda864b06 to your computer and use it in GitHub Desktop.
Config for running Automatic1111 Stable Diffusion WebUI on an AWS SageMaker Notebook
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Stable Diffusion WebUI (AUTOMATIC1111) for SageMaker Studio Lab\n",
"\n",
"This notebook will install and run the [stable-diffusion-webui repository by AUTOMATIC1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) on SageMaker Studio Lab\n",
"\n",
"With the default model you can run textual inversion training, hypernetwork training and image generation, but no native training\n",
"\n",
"You will need a ngrok (reverse proxy) auth token to run it, as gradio sharing doesn't work on SageMaker Studio Lab\n",
"\n",
"If you don't have a ngrok account yet, create one here: https://dashboard.ngrok.com/signup\n",
"\n",
"It's free for non-commercial use\n",
"\n",
"If you use the default model, you will also need a Huggingface user token. Alternatively you can download a model from Google Drive or MEGA, without needing a Huggingface token"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "OHCtG9MT0jLq"
},
"source": [
"# Installation: Clone webui repository\n",
"***You only need to do this once on your SageMaker SL account***"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"id": "sBbcB4vwj_jm"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"%cd ~/SageMaker/\n",
"!git clone --depth 1 https://github.com/AUTOMATIC1111/stable-diffusion-webui\n",
"#create softlink to /tmp/outputs for storing images\n",
"#contents of /tmp folder will be deleted when each session ends\n",
"!ln -vs /tmp/outputs stable-diffusion-webui/outputs\n",
"#create softlink to /tmp in ~/SageMaker/\n",
"!ln -vs /tmp ~/SageMaker/tmp\n",
"#create softlink to /tmp/models in stable-diffusion-webui/models/Stable-diffusion/\n",
"!ln -vs /tmp/models stable-diffusion-webui/models/Stable-diffusion/tmp_models\n",
"\n",
"# change default settings (not necessary)\n",
"%cd stable-diffusion-webui\n",
"!wget https://raw.githubusercontent.com/Miraculix200/StableDiffusionUI_Colab/main/config.json\n",
"!wget https://raw.githubusercontent.com/Miraculix200/StableDiffusionUI_Colab/main/ui-config.json\n",
"learning_rate = \"5e-5:100, 5e-6:1500, 5e-7:2000, 5e-5:2100, 5e-7:3000, 5e-5:3100, 5e-7:4000, 5e-5:4100, 5e-7:5000, 5e-5:5100, 5e-7:6000, 5e-5:6100, 5e-7:7000, 5e-5:7100, 5e-7:8000, 5e-5:8100, 5e-7:9000, 5e-5:9100, 5e-7:10000, 5e-6:10100, 5e-8:11000, 5e-6:11100, 5e-8:12000, 5e-6:12100, 5e-8:13000, 5e-6:13100, 5e-8:14000, 5e-6:14100, 5e-8:15000, 5e-6:15100, 5e-8:16000, 5e-6:16100, 5e-8:17000, 5e-6:17100, 5e-8:18000, 5e-6:18100, 5e-8:19000, 5e-6:19100, 5e-8:20000, 5e-5:20100, 5e-7:21000, 5e-5:21100, 5e-7:22000, 5e-5:22100, 5e-7:23000, 5e-5:23100, 5e-7:24000, 5e-5:24100, 5e-7:25000, 5e-5:25100, 5e-7:26000, 5e-5:26100, 5e-7:27000, 5e-5:27100, 5e-7:28000, 5e-5:28100, 5e-7:29000, 5e-5:29100, 5e-7:30000, 5e-6:30100, 5e-8:31000, 5e-6:31100, 5e-8:32000, 5e-6:32100, 5e-8:33000, 5e-6:33100, 5e-8:34000, 5e-6:34100, 5e-8:35000, 5e-6:35100, 5e-8:36000, 5e-6:36100, 5e-8:37000, 5e-6:37100, 5e-8:38000, 5e-6:38100, 5e-8:39000, 5e-6:39100, 5e-8:40000\"\n",
"!echo \"a photo of a [filewords]\" >textual_inversion_templates/hypernetwork2.txt\n",
"#!sed -i 's/label=\"Use dropout\"/value=\"True\",label=\"Use dropout\"/' modules/ui.py\n",
"#!sed -i 's/value=\"0.00001\"/value=\"{learning_rate}\"/' modules/ui.py\n",
"#!sed -i -E 's/dataset_directory = gr.Textbox\\(/dataset_directory = gr.Textbox\\(value=\\\"\\/tmp\\/processed\\\", /' modules/ui.py\n",
"#!sed -i 's/style_filewords.txt/hypernetwork2.txt/' modules/ui.py\n",
"\n",
"# install extensions (not necessary)\n",
"%cd extensions\n",
"!git clone --depth 1 https://github.com/yfszzx/stable-diffusion-webui-images-browser\n",
"!git clone --depth 1 https://github.com/toshiaki1729/stable-diffusion-webui-dataset-tag-editor.git"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "F0EINk5M0s-w"
},
"source": [
"# Installation: Download model(s) from Huggingface\n",
"***You only need to do this once on your SageMaker SL account***\n",
"\n",
"Alternatively you can use the JupyterLab file browser to upload one or more .ckpt files to the `~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/` folder\n",
"\n",
"There are optional model downloads below this cell, where a Huggingface token is not necessary\n",
"\n",
"To save disk space, you can move models to `/tmp/models` and restart the webui. These models will be deleted when the runtime ends"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Download model(s)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Check free disk space"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"!df -h | grep -E 'Avail|home'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Huggingface token\n",
"You only have to enter this once, as the token will persist in ~/.huggingface/token across sessions"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d044b4111e8a49d5aa2f72f919c65095",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Text(value='HUGGING_FACE_TOKEN', description='Token:')"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"token_textbox = widgets.Text(\n",
" value='HUGGING_FACE_TOKEN',\n",
" description='Token:',\n",
")\n",
"token_textbox"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The next cell will download model `v1-5-pruned-emaonly.ckpt` (4GB) \n",
"\n",
"This model can be used for training textual inversion embeddings and hypernetworks\n",
"\n",
"Comment out and uncomment lines in the next cell to download different models\n",
"\n",
"Go to these pages and ***accept the licenses*** before running the next cell:\n",
"\n",
"https://huggingface.co/runwayml/stable-diffusion-v1-5\n",
"\n",
"https://huggingface.co/CompVis/stable-diffusion-v-1-4-original\n",
"\n",
"https://huggingface.co/runwayml/stable-diffusion-inpainting"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"id": "CT_J9L7oqLxG",
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"huggingface_token = \"\"\n",
"\n",
"import os\n",
"\n",
"token_path = os.path.expanduser('~/.huggingface/token')\n",
"\n",
"if os.path.isfile(token_path):\n",
" with open(token_path) as f:\n",
" lines = f.readlines()\n",
" huggingface_token = lines[0]\n",
"else:\n",
" try:\n",
" token_textbox\n",
" except NameError:\n",
" raise RuntimeError(\"Enter Huggingface token\")\n",
" else:\n",
" !mkdir -p ~/.huggingface\n",
" !echo -n \"{token_textbox.value}\" > ~/.huggingface/token\n",
" huggingface_token = token_textbox.value\n",
"\n",
"user_header = f\"\\\"Authorization: Bearer {huggingface_token}\\\"\"\n",
"\n",
"%cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n",
"\n",
"# Choose here which model(s) to download #############################################################################\n",
"\n",
"# Model 1.4\n",
"#!wget --header={user_header} https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt\n",
"\n",
"# Model 1.5 (8GB) - only necessary for native training, not for embeddings/hypernetworks\n",
"#!wget --header={user_header} https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.ckpt \n",
"\n",
"# Model 1.5 (4GB)\n",
"!wget --header={user_header} https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt \n",
"\n",
"# Inpainting model 1.5 (4GB)\n",
"#!wget --header={user_header} https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Recommended Optional: Download variational autoencoder (VAE)\n",
"\n",
"Doing so can improve the quality of generated images, if you select the VAE in the webui settings\n",
"\n",
"Go to these pages and ***accept the licenses*** before running the next cell:\n",
"\n",
"https://huggingface.co/stabilityai/sd-vae-ft-ema-original\n",
"\n",
"https://huggingface.co/stabilityai/sd-vae-ft-mse-original"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"# sd-vae-ft-ema-original\n",
"#%cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n",
"#!wget --header={user_header} https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-560000-ema-pruned.ckpt\n",
"\n",
"# sd-vae-ft-mse-original\n",
"#%cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n",
"#!wget --header={user_header} https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt\n",
"\n",
"# sd-vae-ft-mse-original\n",
"# Use this if you downloaded v1-5-pruned-emaonly.ckpt above and want to autoselect the VAE every time you load this model in the webui\n",
"%cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n",
"!wget --header={user_header} https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt -O v1-5-pruned-emaonly.vae.pt \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"### Optional: Download various models\n",
"\n",
"Change values from False to True to download a model\n",
"\n",
"A Huggingface token is not necessary for these downloads"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"############################################################\n",
"\n",
"download_to_temp_folder = True # models will be deleted when the SageMaker session ends \n",
"\n",
"anything_v3 = True # Anything V3 model with VAE\n",
"anything_xtron = False # AnythingXtron model\n",
"gigachad = False # Gigachad model\n",
"midjourney_v4 = False # Midjourney V4 Diffusion\n",
"waifu = False # Waifu Division with Anime VAE\n",
"modidi = False # Modern Disney Diffusion\n",
"nitrodiffusion = False # Multi-Style Model trained from scratch\n",
"sd15_cloned = False # Cloned version of model 1.5 (not token necessary)\n",
"secret_ai = False # Anime/furry model with VAE and hypernetworks\n",
"\n",
"############################################################\n",
"\n",
"if download_to_temp_folder:\n",
" !mkdir -p /tmp/models\n",
" %cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/tmp_models\n",
"else:\n",
" %cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n",
"\n",
"if anything_v3:\n",
" !wget https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/Anything-V3.0-pruned.ckpt\n",
" !wget https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/Anything-V3.0.vae.pt -O Anything-V3.0-pruned.vae.pt\n",
"\n",
"if anything_xtron:\n",
" !wget https://huggingface.co/CrasHthe2nd2/anything-tron/resolve/main/anythingXtron.ckpt\n",
" !wget https://huggingface.co/CrasHthe2nd2/anything-tron/resolve/main/Anything-V3.0.vae.pt -O anythingXtron.vae.pt\n",
"\n",
"if gigachad:\n",
" !wget https://huggingface.co/SpiteAnon/gigachad-diffusion/resolve/main/gigachad_2000.ckpt\n",
"\n",
"if midjourney_v4:\n",
" !wget https://huggingface.co/prompthero/midjourney-v4-diffusion/resolve/main/mdjrny-v4.ckpt\n",
"\n",
"if modidi:\n",
" !wget https://huggingface.co/nitrosocke/mo-di-diffusion/resolve/main/moDi-v1-pruned.ckpt\n",
"\n",
"if nitrodiffusion:\n",
" !wget https://huggingface.co/nitrosocke/Nitro-Diffusion/resolve/main/nitroDiffusion-v1.ckpt\n",
"\n",
"if sd15_cloned:\n",
" !wget https://huggingface.co/acheong08/SD-V1-5-cloned/resolve/main/v1-5-pruned-emaonly.ckpt\n",
"\n",
"if secret_ai:\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/animefull-final-pruned/model.ckpt -O secret_ai.ckpt\n",
" %cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/animevae.pt\n",
" !mkdir -p ~/SageMaker/stable-diffusion-webui/models/hypernetworks/\n",
" %cd ~/SageMaker/stable-diffusion-webui/models/hypernetworks/\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/aini.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/anime.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/anime_2.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/anime_3.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_2.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_3.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_kemono.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_protogen.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_scalie.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_transformation.pt\n",
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/pony.pt\n",
"\n",
"# waifu division\n",
"if waifu:\n",
" %cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n",
" !wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/models/wd-1-3-penultimate-ucg-cont.ckpt\n",
"\n",
" %cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n",
" !wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime.ckpt\n",
" !wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Sources: \n",
"\n",
"https://huggingface.co/SpiteAnon/gigachad-diffusion\n",
"\n",
"https://huggingface.co/CrasHthe2nd2/anything-tron\n",
"\n",
"https://huggingface.co/Linaqruf/anything-v3.0\n",
"\n",
"https://huggingface.co/prompthero/midjourney-v4-diffusion\n",
"\n",
"https://huggingface.co/hakurei/waifu-diffusion-v1-4\n",
"\n",
"https://huggingface.co/nitrosocke/mo-di-diffusion\n",
"\n",
"https://huggingface.co/nitrosocke/Nitro-Diffusion\n",
"\n",
"https://huggingface.co/acheong08"
]
},
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"### Optional: Download a model from Google Drive"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Copy the file ID from your URL and paste it into the `GOOGLE_FILE_ID` variable below, before running this cell"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install gdown"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"###########################################################\n",
"GOOGLE_FILE_ID = \"1wHFgl0ivCmIZv88hVZXkb8oy9qCuaBGA\"\n",
"###########################################################\n",
"\n",
"# above file ID is Stable Diffusion model 1.4. Replace it with the file ID of the model you want to download from Google Drive\n",
"\n",
"import gdown\n",
"\n",
"%cd /content/stable-diffusion-webui/models/Stable-diffusion/\n",
"url = \"https://drive.google.com/u/0/uc?id=\" + GOOGLE_FILE_ID + \"&export=download&confirm=t\"\n",
"print(\"Downloading \" + url)\n",
"gdown.download(url)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"### Optional: Download a model from MEGA"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Change `MEGA_DOWNLOAD_URL` to the URL of the model, then run the cell\n",
"\n",
"Download can be very slow (>30 minutes for a 4GB model)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"##########################################################\n",
"MEGA_DOWNLOAD_URL = \"https://mega.nz/file/mdcVARhL#FUq5TL2xp7FuzzgMS4B20sOYYnPZsyPMw93sPMHeQ78\"\n",
"##########################################################\n",
"\n",
"%cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n",
"\n",
"%pip install mega.py\n",
"from mega import Mega\n",
"\n",
"mega = Mega()\n",
"print(\"Connecting to MEGA\")\n",
"m = mega.login()\n",
"print(\"Downloading file (no progress display available)\")\n",
"m.download_url(MEGA_DOWNLOAD_URL)\n",
"print(\"Download complete\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Installation: Install glib to prevent libgthread error when starting webui\n",
"\n",
"***You only need to do this once on your SageMaker SL account***"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"!conda install glib=2.51.0 -y"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "S8nvm5f6AfaL"
},
"source": [
"# Update: Change into Web UI directory and download updates\n",
"This is not strictly necessary. You can run this every time before you start the webui"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"%cd ~/SageMaker/stable-diffusion-webui\n",
"!git pull"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Update: Install webui requirements.txt\n",
"This is necessary sometimes after you did a `!git pull` above"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"%cd ~/SageMaker/stable-diffusion-webui\n",
"%pip install -r requirements.txt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run: Enter ngrok auth token\n",
"You only need to run this once, until you delete your auth token on ngrok.com"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d0a6d68849bd4ccf8ac8840e5f87c86d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Text(value='YOUR_NGROK_TOKEN', description='Token:')"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"ngrok_token_textbox = widgets.Text(\n",
" value='YOUR_NGROK_TOKEN',\n",
" description='Token:',\n",
")\n",
"ngrok_token_textbox"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xt8lbdmC04ox"
},
"source": [
"# Run: Launch web ui\n",
"\n",
"You will get a ngrok.io link. Follow it and enter the username and password shown below. You may want to change username and password for security reasons.\n",
"\n",
"Note that every time you stop the SageMaker Studio Lab runtime the generated images will be lost, as they are stored in the /tmp folder"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "R-xAdMA5wxXd"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"##################################\n",
"\n",
"WEBUI_USERNAME=\"\"\n",
"WEBUI_PASSWORD=\"\"\n",
"\n",
"##################################\n",
"\n",
"import subprocess\n",
"import os\n",
"import sys\n",
"\n",
"ngrok_token = \"\"\n",
"\n",
"# Check if ngrok token exists\n",
"if 'ngrok_token_textbox' in locals():\n",
" print(\"Saving ngrok auth token to ~/.ngrok_token\")\n",
" !echo -n \"{ngrok_token_textbox.value}\" > ~/.ngrok_token\n",
" ngrok_token = ngrok_token_textbox.value\n",
"\n",
"else:\n",
" full_path = os.path.expanduser('~/.ngrok_token')\n",
" if not os.path.exists(full_path):\n",
" #print('\u001b[1;31mNo ngrok auth token found')\n",
" sys.exit(\"No ngrok auth token found\")\n",
" else:\n",
" with open(full_path) as f:\n",
" ngrok_token = f.readline()\n",
" print(\"Using ngrok auth token from ~/.ngrok_token\")\n",
"\n",
"# create /tmp/outputs folder for storing generated images for this session\n",
"!mkdir -p /tmp/outputs\n",
"!mkdir -p /tmp/models\n",
"\n",
"# show free disk space\n",
"# print(\"Free disk space:\")\n",
"# print(subprocess.check_output('df -h | grep Avail', shell=True))\n",
"# print(subprocess.check_output('df -h | grep home', shell=True))\n",
"# print(subprocess.check_output('df -h | grep overlay', shell=True))\n",
"# print(\" \")\n",
"# print(\" \")\n",
"# print(\" \")\n",
"\n",
"# launch webui\n",
"%cd ~/SageMaker/stable-diffusion-webui\n",
"ARGS = \"\\\"--disable-console-progressbars --gradio-debug --gradio-auth \" + WEBUI_USERNAME + \":\" + WEBUI_PASSWORD + \" --ngrok \" + ngrok_token + \"\\\"\"\n",
"!COMMANDLINE_ARGS=$ARGS REQS_FILE=\"requirements.txt\" python launch.py\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Commandline arguments are:\n",
" - `--share` - create online gradio.app link (currently this doesn't work on SageMaker SL)\n",
" - `--gradio-debug` - print outputs to console\n",
" - `--ngrok` - start ngrok reverse proxy with supplied auth token"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9qrpRUJpno7L",
"tags": []
},
"source": [
"End: Commands for ***after*** you're done with a session\n",
"============================================================================\n",
"Click the square stop button before running these cells"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zB-L8JpElKp-"
},
"source": [
"### Create .tar.gz archive of images for downloading \n",
"\n",
"Location will be `~/SageMaker/tmp/outputs.tar.gz` and `/tmp/outputs.tar.gz`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%cd /tmp\n",
"!echo \"Creating archive. Please wait...\"\n",
"!tar -czf /tmp/outputs.tar.gz outputs\n",
"!echo \"You can now download the archive with generated images\""
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [
"9qrpRUJpno7L"
],
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3.9.16 ('codeserver_py39': conda)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"vscode": {
"interpreter": {
"hash": "aca522a4f3a95a8cc19c0c49aa2b52717208ab4d9caac282bf163cf809ab5536"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
@ShMcK
Copy link
Author

ShMcK commented Apr 8, 2023

Modified from https://github.com/Miraculix200/StableDiffusionUI_SageMakerSL to work with a SageMaker Notebook instead of SageMaker Studio Labs. Requires a GPU instance (eg. P3).

@Canyayan
Copy link

thank u so much, finally I can run sd on asw studiolab!

@AIadopts
Copy link

hii.. could you check the notebook? is it still working on your side? i'm stuck at
ngrok public url, with 3200 ngrok error code..
been trying some turn around, and manage to forward to my ip address for 1 sec then connection errored out..

@gilroff
Copy link

gilroff commented Oct 9, 2023

Getting error:
Launching Web UI with arguments: --disable-console-progressbars --gradio-debug --gradio-auth : --ngrok "my token was here"
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
Traceback (most recent call last):
File "launch.py", line 48, in
main()
File "launch.py", line 44, in main
start()
File "/home/studio-lab-user/new/stable-diffusion-webui/modules/launch_utils.py", line 432, in start
import webui
File "/home/studio-lab-user/new/stable-diffusion-webui/webui.py", line 13, in
initialize.imports()
File "/home/studio-lab-user/new/stable-diffusion-webui/modules/initialize.py", line 33, in imports
from modules import shared_init
File "/home/studio-lab-user/new/stable-diffusion-webui/modules/shared_init.py", line 5, in
from modules import shared
File "/home/studio-lab-user/new/stable-diffusion-webui/modules/shared.py", line 5, in
from modules import shared_cmd_options, shared_gradio_themes, options, shared_items, sd_models_types
File "/home/studio-lab-user/new/stable-diffusion-webui/modules/options.py", line 74, in
class Options:
File "/home/studio-lab-user/new/stable-diffusion-webui/modules/options.py", line 77, in Options
def init(self, data_labels: dict[str, OptionInfo], restricted_opts):
TypeError: 'type' object is not subscriptable

@NullEqualsZero
Copy link

NullEqualsZero commented Nov 9, 2023

I am also getting an error this one
Saving ngrok auth token to ~/.ngrok_token
/home/studio-lab-user/SageMaker/stable-diffusion-webui
fatal: No names found, cannot describe anything.
Python 3.9.0 | packaged by conda-forge | (default, Oct 14 2020, 22:59:50)
[GCC 7.5.0]
Version: 1.6.1
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Cloning Stable Diffusion into /home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/stable-diffusion-stability-ai...
Cloning into '/home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/stable-diffusion-stability-ai'...
remote: Enumerating objects: 580, done.
remote: Counting objects: 100% (580/580), done.
remote: Compressing objects: 100% (284/284), done.
remote: Total 580 (delta 281), reused 492 (delta 275), pack-reused 0
Receiving objects: 100% (580/580), 73.43 MiB | 49.15 MiB/s, done.
Resolving deltas: 100% (281/281), done.
Cloning Stable Diffusion XL into /home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/generative-models...
Cloning into '/home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/generative-models'...
remote: Enumerating objects: 740, done.
remote: Counting objects: 100% (383/383), done.
remote: Compressing objects: 100% (145/145), done.
remote: Total 740 (delta 301), reused 238 (delta 238), pack-reused 357
Receiving objects: 100% (740/740), 22.31 MiB | 27.46 MiB/s, done.
Resolving deltas: 100% (377/377), done.
Cloning K-diffusion into /home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/k-diffusion...
Cloning into '/home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/k-diffusion'...
remote: Enumerating objects: 1323, done.
remote: Counting objects: 100% (605/605), done.
remote: Compressing objects: 100% (76/76), done.
remote: Total 1323 (delta 565), reused 535 (delta 529), pack-reused 718
Receiving objects: 100% (1323/1323), 237.11 KiB | 3.34 MiB/s, done.
Resolving deltas: 100% (928/928), done.
Cloning CodeFormer into /home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/CodeFormer...
Cloning into '/home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/CodeFormer'...
remote: Enumerating objects: 594, done.
remote: Counting objects: 100% (245/245), done.
remote: Compressing objects: 100% (90/90), done.
remote: Total 594 (delta 176), reused 170 (delta 155), pack-reused 349
Receiving objects: 100% (594/594), 17.30 MiB | 62.83 MiB/s, done.
Resolving deltas: 100% (287/287), done.
Cloning BLIP into /home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/BLIP...
Cloning into '/home/studio-lab-user/SageMaker/stable-diffusion-webui/repositories/BLIP'...
remote: Enumerating objects: 277, done.
remote: Counting objects: 100% (165/165), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 277 (delta 137), reused 136 (delta 135), pack-reused 112
Receiving objects: 100% (277/277), 7.03 MiB | 45.59 MiB/s, done.
Resolving deltas: 100% (153/153), done.
Launching Web UI with arguments: --skip-torch-cuda-test --disable-console-progressbars --gradio-debug --gradio-auth NullEqualsZero:0 --ngrok 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
Traceback (most recent call last):
File "/home/studio-lab-user/SageMaker/stable-diffusion-webui/launch.py", line 48, in
main()
File "/home/studio-lab-user/SageMaker/stable-diffusion-webui/launch.py", line 44, in main
start()
File "/home/studio-lab-user/SageMaker/stable-diffusion-webui/modules/launch_utils.py", line 432, in start
import webui
File "/home/studio-lab-user/SageMaker/stable-diffusion-webui/webui.py", line 13, in
initialize.imports()
File "/home/studio-lab-user/SageMaker/stable-diffusion-webui/modules/initialize.py", line 14, in imports
import torch # noqa: F401
File "/home/studio-lab-user/.conda/envs/default/lib/python3.9/site-packages/torch/init.py", line 26, in
from ._utils import _import_dotted_name, classproperty
ModuleNotFoundError: No module named 'torch._utils'

@21x2-42
Copy link

21x2-42 commented Feb 4, 2024

Is there a way to not use ngrok? Running SD hits the consumption limit of a free ngrok account in like two days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment