Automatic1111 & Stable Diffusion - Google Colab & Google Drive Setup
text
Google Colab Setup
For troubleshooting any issues with this Google Colab setup, please go to the DeepLizard Discord server and discuss the issue in the channel for this course.
It's important to note that Google Colab has restricted the use of the Automatic1111 UI under the free version. It's no longer possible at the moment to use the Automatic1111 UI with Google Colab for free.
The Colab product lead has said that the team cannot support the usage growth of the Automatic1111 UI and Stable Diffusion on their budget. This was mentioned in this tweet.
This section covers how to get Google Colab setup for this course. The general steps for getting Colab setup are as follows:
- Go to Google Colab
- Upload notebook:
deeplizard-colab-automatic1111-ui.ipynb
- Configure GPU
- Download Automatic1111 Interface from GitHub
- Download Stable Diffusion from HuggingFace
- Connect to Google Drive
- Launch the Automatic1111 Stable Diffusion Web UI
Let's breakdown each of these steps.
The Notebook
A notebook for running the Automatic1111 interface as been included in the course resource files. Locate this notebook and upload it to Google Colab.
Configure Colab to use a GPU by choosing: Choose: Runtime > Change runtime type > Hardware accelerator > GPU
After configuring the GPU, run the Test GPU cell below:
# Test GPU
!nvidia-smi
THe output should look something like this:
+-----------------------------------------------------------------------------+ | NVIDIA-SMI 510.47.03 Driver Version: 510.47.03 CUDA Version: 11.6 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 | | N/A 57C P0 27W / 70W | 0MiB / 15360MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
Next, we are ready to download the Automatic1111 UI.
Download Automatic1111 Interface
We are downloading the Automatic1111 interface from GitHub using the code below:
!pip install fastapi==0.90
!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
%cd stable-diffusion-webui/
!git checkout 2c1bb46c7ad5b4536f6587d327a03f0ff7811c5d
!python launch.py --xformers
Note that we are installing fastapi==0.90
. This fixes a bug that prevents the sharing of the Gradio app. Sharing is required to access the interface after it is up and running on the Google server.
We are simply cloning the repo and then checking out the commit that was used in this course. The checkout helps keep everything in the course consistent.
Finally, we are navigating to the repo directory and launching the application. When the application launches, the application will install any required resources.
When this cell finishes, we will see that the application is asking us to download the Stable Diffusion .ckpt
file. This is the next step.
No checkpoints found. When searching for checkpoints, looked at: - file .\stable-diffusion-webui\model.ckpt - directory .\stable-diffusion-webui\models\Stable-diffusion Can't run without a checkpoint. Find and place a .ckpt file into any of those locations. The program will exit.
Download Stable Diffusion
To download Stable Diffusion from HuggingFace, we run the command below:
!curl -L https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt --output "/content/stable-diffusion-webui/models/Stable-diffusion/sd-v1-4.ckpt"
This command will download the sd-v1-4.ckpt
file to the directory that the Automatic1111 application expects.
This is all that is needed to run the application. However, to avoid doing these downloads every time we run the notebook. We can connect to Google Dive and move the installation over to the Drive.
Google Drive
Running the application from Google Drive will allow us to avoid downloading every time the notebook is relaunched.
Additionally, using Google Drive will make accessing our generated images easier because they will be saved directly to Google Drive. We can mount to Google Drive and check that it is connected by running the following code:
# Mount Google Drive
from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
# Test Google Drive
google_drive = '/content/gdrive/MyDrive'
%ls $google_drive
Finally, we can move our Automatic1111 application installation to Google Drive, using the following command:
!cp -a /content/stable-diffusion-webui/ /content/gdrive/MyDrive/automatic1111/stable-diffusion-webui
The application will be moved to:
/content/MyDrive/automatic1111/stable-diffusion-webui
Launching Automatic1111 in Google Colab
Given what we have done so far, we have two options for running the application:
- Launch from the Google machine
- Launch from the Google Drive
We can launch from the Google machine like so:
%cd /content/stable-diffusion-webui !python launch.py --xformers --share --gradio-auth username:password
We can launch from the Google Drive like so:
%cd /content/gdrive/MyDrive/automatic1111/stable-diffusion-webui !python launch.py --xformers --share --gradio-auth username:password
Launching from Google Drive gives us the advantage that all of our work will be saved after our session is complete. Specifically, the following will be saved in Google Drive:
- Software downloads
- App configurations
- Generated images
Note that we are specifying that we want to --share
our interface. This will give us a public link to the web interface.
Therefore, anyone with the link will be able to access the web app that is being hosted by the Google Colab instance. See Gradio: Sharing Your App for more information.
Finally, note that the --gradio-auth
parameter allows us to specify a username and password to accessing the app. This restricts the access as the credentials are required. The values in the notebook are place holders.
Change --gradio-auth username:password
to something unique. For example:
--gradio-auth chris:4b0b8933c202fdb9ccf88c066a74d560d79b4987
Now, after running the launch.py
script, we will be provided with a link like so:
Running on public URL: https://bbc224fe-3857-4682.gradio.live
We click the link, and we are ready to go!
Practice with Flashcards
Challenge your grasp of the concepts by exploring these interactive flashcards.
quiz
resources
updates
Committed by on