Note: these instructions are hastily put together and suitable for someone comfortable with command line.
The script in this repo is meant to setup a suitable enviroment for Stable Diffusion with UI on an ubuntu gpu instance such as those provided by Paperspace so that you can forward a local port and play with stable diffusion in your browser.
Here's a referral link for Paperspace, it should give you 10$ off if you don't already have an account.
- NVidia Driver
- CUDA
- cuDNN
- CUDA toolkit
- CompVis/stable-diffusion
- hlky/stable-diffusion-ui
(This is what I do on a paperspace instance of Ubuntu)
git clone https://github.com/webel/Stable-diffusion-In-a-Box.git
cd Stable-diffusion-In-a-Box
- Run the prepare script;
bash prepare.sh
, NOTE the host will likely disconnect at this point due to needing to reboot, ssh in again and run this command again. - Accept any NVIDIA prompts by clicking enter.
- Run the script that git clones stable diffusion and the ui, as well as prepares them:
bash install-sd.sh
. - (Optional)
pip install gdown
for a google drive downloader. - Grab your weights, either with wget, or by copying from your local machine with scp, or (fastest I've found so far)
gdown [google-drive-link]
# Make sure to change the location of where your weights are
scp ~/dev/sd-v1-4.ckpt [user]@[server-ip]:stable-diffusion/models/ldm/stable-diffusion-v1/model.ckpt`
Test the usual on the command-line, make sure you're in the ldm environment, try
python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms
Run the UI
python scripts/webui-relauncher.py
The above script will spit out an endpoint, localhost:7860
.
We'll use SSH tunneling to forward our local port to the server port;
ssh -NL 7860:[server-ip]:7860 [user]@[server-ip]
You can now go to localhost:7860
in your browser and go wild 🎉.
Use scp to copy the output directory back to your local device,
scp -qpr [user]@[server-ip]:stable-diffusion/outputs ./
I want to create a single command, say artfart.sh
that
- starts the machine
- runs the webui on startup
- forwards the local port
- stops the machine on script exit
Programmatically starting and stopping:
# paperspace-cli
paperspace machines start \
--apiKey "" \
--machineId ""
paperspace machines stop \
--apiKey "" \
--machineId ""
paperspace machines waitfor \
--apiKey "" \
--machineId "" \
--state "ready"
# node
paperspace.machines.start(
{
machineId: "",
},
function (err, res) {
// handle error or result
}
);
paperspace.machines.stop(
{
machineId: "",
},
function (err, res) {
// handle error or result
}
);
paperspace.machines.waitfor(
{
machineId: "",
state: "ready",
},
function (err, res) {
// handle error or result
}
);
- Script on startup,
.startup.sh
#!/bin/bash
cd stable-diffusion
. ~/miniconda3/etc profile.d/conda.sh
conda activate ldm
# python scripts/relauncher.py
- Add to end of
.profile
:
# enable ldm and move straight into stable-diffusion
if [ -d "$HOME/stable-diffusion" ] ; then
. "$HOME/.startup.sh"
fi