Skip to content

Instantly share code, notes, and snippets.

@silviot
Last active July 25, 2024 13:34
Show Gist options
  • Save silviot/bdf1d0d68901419935463e8d74bc0cd6 to your computer and use it in GitHub Desktop.
Save silviot/bdf1d0d68901419935463e8d74bc0cd6 to your computer and use it in GitHub Desktop.
Setup stable diffusion UI on a vast.ai machine
#!/bin/bash
# Use this script to set up a stable diffusion web GUI on a vast.ai machine. Invoke it like this:
# run:
#
# wget -q -O - https://gist.githubusercontent.com/silviot/bdf1d0d68901419935463e8d74bc0cd6/raw/vast.ai.sd.setup.sh | bash
AUTOMATIC1111_VERSION=${AUTOMATIC1111_VERSION:-master}
touch ~/.no_auto_tmux
export DEBIAN_FRONTEND=noninteractive
export TZ=Etc/UTC
add-apt-repository ppa:deadsnakes/ppa
sudo -E DEBIAN_FRONTEND=noninteractive -E TZ=Etc/UTC apt install -y htop byobu unzip bash-completion wget python3.10 libgl1-mesa-glx aria2 bmon locales pbzip2
ln -s $(which python3.10) /usr/bin/python
byobu new-session -d -s 'ai' bash -c 'htop; bash'
byobu new-window "aria2c 'magnet:?xt=urn:btih:3A4A612D75ED088EA542ACAC52F9F45987488D1C&tr=udp://tracker.opentrackr.org:1337'"
byobu new-window "curl https://rclone.org/install.sh | sudo bash"
byobu new-window "cd /usr/local/bin && wget -O - getmic.ro | bash"
wget https://bootstrap.pypa.io/get-pip.py -O - | /usr/bin/python
[ -d /home/sduser ] || useradd -s /bin/bash -m sduser
chown sduser:sduser /home/sduser/ -R
sudo -u sduser git clone -b ${AUTOMATIC1111_VERSION} https://github.com/AUTOMATIC1111/stable-diffusion-webui.git /home/sduser/stable-diffusion-webui
sudo -u sduser mkdir -p /home/sduser/stable-diffusion-webui/log/images/
# cd /home/sduser/ && sudo -u sduser wget -q https://eu2.contabostorage.com/55b89d240dba4119bef0d60e8402458a:ai-stuff/public%2Flocal-python.tar.bz2 -O - | tar xvjf -
cd /tmp/
[ -f /home/sduser/.local/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_infer.so.8 ] || aria2c -x 16 https://eu2.contabostorage.com/55b89d240dba4119bef0d60e8402458a:ai-stuff/public/local-python.tar.bz2
cd /home/sduser/
[ -f /home/sduser/.local/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_infer.so.8 ] || sudo -u sduser tar xvjf /tmp/local-python.tar.bz2
cd /home/sduser/stable-diffusion-webui
sudo -u sduser -E HOME=/home/sduser bash -c '/usr/bin/python -m pip install -r requirements.txt'
sudo -u sduser -E HOME=/home/sduser bash -c 'python -c "from torch import cuda; cuda._check_cubins()" 2>&1 | grep sm_86 && python -m pip install -U torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116'
ln /root/sd-v1-4.ckpt /home/sduser/stable-diffusion-webui/model.ckpt || ln /workspace/sd-v1-4.ckpt /home/sduser/stable-diffusion-webui/model.ckpt
byobu new-window sudo -u sduser -E HOME=/home/sduser bash -c '/usr/bin/python launch.py --precision full --no-half; bash'
# TODO: detect GPU available RAM and remove `--precision full --no-half` parameters from launch line above if too low
# TODO: set CUDA_VISIBLE_DEVICES to enumerate all available GPUs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment