AUTOMATIC1111/stable-diffusion-webui SETUP

Software tutorials of interest.
Post Reply
Message
Author
jstenner
Site Admin
Posts: 82
Joined: Wed Jan 27, 2010 7:33 pm

AUTOMATIC1111/stable-diffusion-webui SETUP

#1 Post by jstenner »

To run WebUI on HiPerGator is pretty straight forward, but it's a sort of hybrid between running something "local" and running it "remote." Here's what to do:

First we're going to install everything, then quit and relaunch it with a SLURM batch script using the same technique as running a Jupyter Notebook locally. In day to day use, you'll use the SLURM batch script.

Move to your working directory on "blue":

Code: Select all

cd /blue/art4612/share/<gatorlink>/

Code: Select all

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Move into our cloned directory and edit webui-user.sh to reflect our installation path:

Code: Select all

cd stable-diffusion-webui
nano webui-user.sh
Notice that I've uncommented (removed the #) on particular lines below:
Screen Shot 2022-10-17 at 9.49.52 AM.png
Modify "install_dir" and "clone_dir" to reflect your paths. Note that $(whoami) is a variable substitution that will automatically substitute your gator username.

Modify the TORCH_COMMAND to be:

Code: Select all

export TORCH_COMMAND="pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113"
Save your changes to webui-user.sh the normal way (Ctrl + o, Enter, Ctrl + x).

Grab a GPU. Modify this based on how long you want, etc:

Code: Select all

srun -p gpu --nodes=1 --gpus=a100:1 --time=2:00:00 --mem=16gb --ntasks=1 --cpus-per-task=1 --pty -u -A art4612 -q art4612 bash -i
Load up some modules and save the grouping as "webui":

Code: Select all

module load cuda
module load gcc
module load git
module load pytorch/1.10
module load ffmpeg/4.3.1
module save webui
Once you've saved your module list, in the future, we'll restore these modules in our batch script with:

Code: Select all

module r webui
You can list the modules you have loaded with:

Code: Select all

module list
At some point in the future you may need to change version of the software you're loading via the module system. Use "spider" to see what versions are available. For example:

Code: Select all

module spider ffmpeg
For the next step, we need to get a basic stable diffusion model downloaded and placed inside the "models/Stable-diffusion" directory. I have placed a selection of models in "/blue/art4612/share/models/". To copy a model into your stable-diffusion-webui directory, do this:

Code: Select all

cd models/Stable-diffusion
cp ../../../../models/Stable-diffusion/sd-v1-4.ckpt .
"ls" to check if you did that properly (the number of ../ depends on your particular setup). You should see your model.

Now we can proceed with installing the necessary dependencies and run webui.
Change directories from your current location (models/Stable-diffusion) to the root install directory (stable-diffusion-webui):

Code: Select all

cd ../../
Run webui:

Code: Select all

bash webui.sh
Everything should install properly (be patient) and the application/server should launch. You won't have any way to access the server, though, unless we set up a SSH Tunnel. I have written a shell script that does that for us. It is adapted from the shell script that launches Jupyter Lab. If you've cloned my fork of WebUI, the script is included, otherwise you can grab it from my "slurm_examples" repository. You'll know the installation has finished and the app is waiting to be used because the terminal will present you with a localhost (or 127.0.0.1) URL. Let's kill it now by typing "Ctrl + c".

Move out of our current working directory and clone "slurm_examples":

Code: Select all

cd ..
git clone https://github.com/jstenner/slurm_examples.git
Inside "slurm_examples" there is a batch script called "webui_sbatch.sh". Copy that file to your "stable-diffusion-webui" directory. From now on, that's the script you'll launch to run AUTOMATIC1111/stable-diffusion-webui.

By now, you should know how to edit SLURM batch scripts to customize them for your purposes (e.g. runtime). Move to your webui working directory and edit the batch script:

Code: Select all

cd stable-diffusion-webui
nano webui_sbatch.sh
Change <gatorusername> to your own username so you get notifications.
Set the time you want the job to run. Set your gradio-auth USERNAME:PASSWD in the python command on the last line.
Save your changes: Ctrl + o, Enter, Ctrl + x.

Now LAUNCH:

Code: Select all

sbatch webui_sbatch.sh
The batch script will output a log file called "webui_<jobid>.out". We need to look at this log file to see how to connect to the application and to monitor its operation. Let's use "tail". Remember to substitute your actual filename with the proper job id in place of "webui_<jobid>" below:

Code: Select all

tail -f webui_<jobid>.out
Notice two lines in the output. You'll see "SSH tunnel command:" and "Local browser URI:" Copy/paste the "ssh" line into a NEW Terminal window and authenticate. That creates a secure shell tunnel to HiPerGator allowing the web server (http) running Stable Diffusion to be accessible on your local machine.

Finally, copy/paste the "Local browser URI" into your web browser. It may not work immediately because the application is still loading the model and starting up. After a minute or two, the Gradio login page should appear and you're ready to login and get started!
Screen Shot 2022-11-08 at 8.04.18 AM.png
Notice that as you render, you'll get feedback about what's happening in your main terminal window (the one with "tail" running). At first webui needs to download certain models and support files so it may be a bit slow. Once everything is available to you, it's very quick.

HAVE FUN!

To quit, type "Ctrl + c" in your shell tunnel terminal window to close that down.
Type "Ctrl + c" in your main terminal window to close "tail". Then type:

Code: Select all

squeuemine 
and notice the Job ID. Use that number to close down your SLURM session:

Code: Select all

scancel <JOBID>
End your session with:

Code: Select all

exit
:-)
The master of disaster!

Post Reply