Skip to content

Instantly share code, notes, and snippets.

@primeinc
Last active March 7, 2023 05:33
Show Gist options
  • Save primeinc/2d06ca5232b4d47ecf1710fa2008a0cc to your computer and use it in GitHub Desktop.
Save primeinc/2d06ca5232b4d47ecf1710fa2008a0cc to your computer and use it in GitHub Desktop.
SD-Automatic-Root-Script
#!/usr/bin/env bash
#########################################################
# Uncomment and change the variables below to your need:#
#########################################################
# Check if COMMANDLINE_ARGS is set
if [[ -z "${COMMANDLINE_ARGS}" ]]; then
export COMMANDLINE_ARGS="--share --disable-safe-unpickle --enable-insecure-extension-access \
--no-half-vae --no-half --xformers --no-hashing --disable-console-progressbars \
--no-download-sd-model --api --allow-code --theme dark"
else
echo "COMMANDLINE_ARGS is set to ${COMMANDLINE_ARGS}."
fi
# Uncomment to enable accelerated launch
if [[ -z "${ACCELERATE}" ]]; then
export ACCELERATE="True"
fi
###########################################
# Read variables from webui-user.sh
# shellcheck source=/dev/null
if [[ -f webui-user.sh ]]; then
source ./webui-user.sh
fi
# Set defaults
# Install directory without trailing slash
if [[ -z "${install_dir}" ]]; then
install_dir="/content"
fi
# Name of the subdirectory (defaults to stable-diffusion-webui)
if [[ -z "${clone_dir}" ]]; then
clone_dir="sd-webui"
fi
# python3 executable
if [[ -z "${python_cmd}" ]]; then
python_cmd="python3"
fi
# git executable
if [[ -z "${GIT}" ]]; then
export GIT="git"
fi
if [[ -z "${LAUNCH_SCRIPT}" ]]; then
LAUNCH_SCRIPT="launch.py"
fi
# Disable sentry logging
export ERROR_REPORTING=FALSE
# Do not reinstall existing pip packages on Debian/Ubuntu
if [[ -z "${PIP_IGNORE_INSTALLED}" ]]; then
export PIP_IGNORE_INSTALLED=0
fi
# Pretty print
delimiter="################################################################"
printf "\n%s\n" "${delimiter}"
printf "\e[1m\e[32mInstall script for stable-diffusion + Web UI\n"
printf "\e[1m\e[34mTested on Debian 11 (Bullseye)\e[0m"
printf "\n%s\n" "${delimiter}"
printf "\n%s\n" "${delimiter}"
printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)"
printf "\n%s\n" "${delimiter}"
if [[ -d .git ]]; then
printf "\n%s\n" "${delimiter}"
printf "Repo already cloned, using it as install directory"
printf "\n%s\n" "${delimiter}"
install_dir="${PWD}/../"
clone_dir="${PWD##*/}"
fi
# Check prerequisites
gpu_info=$(lspci 2>/dev/null | grep VGA)
case "$gpu_info" in
*"Navi 1"* | *"Navi 2"*)
export HSA_OVERRIDE_GFX_VERSION=10.3.0
;;
*"Renoir"*)
export HSA_OVERRIDE_GFX_VERSION=9.0.0
printf "\n%s\n" "${delimiter}"
printf "Experimental support for Renoir: make sure to have at least 4GB of VRAM and 10GB of RAM or enable cpu mode: --use-cpu all --no-half"
printf "\n%s\n" "${delimiter}"
;;
*) ;;
esac
if echo "$gpu_info" | grep -q "AMD" && [[ -z "${TORCH_COMMAND}" ]]; then
export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2"
fi
for preq in "${GIT}" "${python_cmd}"; do
if ! hash "${preq}" &>/dev/null; then
printf "\n%s\n" "${delimiter}"
printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}"
printf "\n%s\n" "${delimiter}"
exit 1
fi
done
cd "${install_dir}"/ || {
printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting...\e[0m" "${install_dir}"
exit 1
}
cd "${clone_dir}"/ || {
printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"
exit 1
}
if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]; then
printf "\n%s\n" "${delimiter}"
printf "Accelerating launch.py..."
printf "\n%s\n" "${delimiter}"
exec accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@"
else
printf "\n%s\n" "${delimiter}"
printf "Launching launch.py..."
printf "\n%s\n" "${delimiter}"
exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment