{ "cells": [ { "cell_type": "markdown", "source": [ "# Paperspace Stable Diffusion Notebook\n", "\n", "This Notebook contains instructions and easy steps for generating images with Stable Diffusion on any of Paperspace's GPUs with little set up required. Follow the instructions in the markdown cells in this Notebook to quickly launch the Stable Diffusion Web UI or begin generating images using the Diffusers Stable Diffusion Pipeline.\n", "\n", "Contents:\n", "\n", "- Use the Stable Diffusion Web UI\n", " - Loading in the Stable Diffusion models for the Web UI with support for v1-5 and v2 models\n", "- The Diffusers Stable Diffusion Pipeline\n", " - Loading in the Stable Diffusion models for the Diffusers StableDiffusionPipeline with support for v1-4, v1-5 and v2 models\n", " - Access additional models: log in to HuggingFace for online access model files\n", " - Inference with the Diffusers pipeline\n", "- CLIP reranking\n", "- GFPGAN face restoration and image upscaling\n", "- CodeFormer face restoration and image upscaling" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Setup\n", "\n", "First, run the cell below to get everything we need for this Notebook to run." ], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "!pip install --upgrade git+https://github.com/huggingface/diffusers.git \n", "!pip install -U transformers accelerate scipy\n", "!pip install flax==0.5.0 --no-deps\n", "!pip install msgpack rich optax accelerate ftfy scipy\n", "!pip install ipywidgets\n", "!jupyter nbextension enable --py widgetsnbextension\n", "!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n", "!mkdir outputs\n", "!pip uninstall -y torch torchvision torchaudio\n", "!pip3 install torch torchvision torchaudio --no-cache-dir --index-url https://download.pytorch.org/whl/cu118\n" ], "outputs": [], "metadata": { "collapsed": true, "execution": { "iopub.execute_input": "2022-11-29T01:17:34.402699Z", "iopub.status.busy": "2022-11-29T01:17:34.401879Z", "iopub.status.idle": "2022-11-29T01:17:58.874403Z", "shell.execute_reply": "2022-11-29T01:17:58.873489Z", "shell.execute_reply.started": "2022-11-29T01:17:34.402612Z" }, "jupyter": { "outputs_hidden": true } } }, { "cell_type": "markdown", "source": [ "## Use the Stable Diffusion Web UI\n", "\n", "Run the cell below to setup, and launch the Automatic1111 Stable Diffusion Web UI from this notebook. Click the Gradio link after the setup completes to access the Web UI in your local browser. \n", "\n", "Skip this step to use the Diffusers library methodology.\n", "\n", "### Loading in the Stable Diffusion models for the Web UI \n", "\n", "To make accessing the Stable Diffusion models easy and not take up any storage, we have added the Stable Diffusion v1-5 and v2 models as mountable public datasets!\n", "\n", "> These files will not count towards the storage limit for free notebooks.\n", "\n", "To access the model files:\n", "\n", "First, navigate to the \"Data Sources\" tab using the navigator on the far left of the page.\n", "\n", "Next, click \"Public\" to switch into the Gradient Public Datasets, and scroll down until you find the Stable Diffusion datasets near the bottom of the list. You can mount `stable-diffusion-classic` for access to the v1-5 model checkpoints for the web UI, `stable-diffusion-diffusers` for the v1-5 models as Diffusers StableDiffusionPipeline binaries, `stable-diffusion-classic-v2` for access to the v2 model checkpoints and config file for use with the web UI, and `stable-diffusion-diffusers-v2` for access to the v2 models as Diffusers StableDiffusionPipeline binaries.\n", "\n", "Finally, click \"mount\" to make any of these Public Datasets accessible from the \"datasets\" directory. This directory is in the root folder, so access it with the path `~/../datasets/stable-diffusion-classic/SDv1.5.ckpt`. For example, after mounting, the v1-5 checkpoint can be found at `~/../datasets/stable-diffusion-classic/SDv1.5.ckpt`\n", "\n", "See the video below for a video guide to for help mounting these files. \n" ], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "# Launch the Stable Diffusion Web UI. \n", "# Be sure to hash out whichever you are not using.\n", "%cd stable-diffusion-webui\n", "\n", "## Launch Web UI for Stable Diffusion v2 models. Note: this prevents users from using checkpoints and embeddings trained on v1-X models.\n", "!python launch.py --share --config ~/../datasets/stable-diffusion-classic-v2/768-v-ema.yaml --ckpt ~/../datasets/stable-diffusion-classic-v2/768-v-ema.ckpt\n", "\n", "## Launch Web UI for Stable Diffusion v1-x models.\n", "!python launch.py --share --ckpt ../../datasets/stable-diffusion-classic/SDv1.5.ckpt\n" ], "outputs": [], "metadata": {} }, { "cell_type": "markdown", "source": [ "# The Diffusers Stable Diffusion Pipeline\n", "\n", "## Loading in the Stable Diffusion v1-5 and v2 models for the Diffusers StableDiffusionPipeline\n", "\n", "To make accessing the Stable Diffusion models easy and not take up any storage, we have added the Stable Diffusion models as mountable public datasets! To access the models this way, simply navigate to the \"Data Sources\" tab using the navigator on the far left of the page. \n", "\n", "Then click \"Public\" to switch into the Gradient Public Datasets, and scroll down until you find the datasets starting with \"stable-diffusion\" near the bottom of the list. We recommend mounting each of these public datasets: `stable-diffusion-classic` (v1-5 checkpoint), `stable-diffusion-diffusers` (v1-5 diffusers), `stable-diffusion-classic-v2` (v2 checkpoint & config), and `stable-diffusion-diffusers-v2` (v2 diffusers). \n", "\n", "Click \"mount\" to make each of them accessible from the \"datasets\" directory. This directory is in the root folder, so access the two directories with the paths `~/../datasets/` and `../datasets/stable-diffusion-diffusers-v2/stable-diffusion-2/`\n", "\n", "