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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#################################################
|
| 3 |
+
# Please do not make any changes to this file, #
|
| 4 |
+
# change the variables in webui-user.sh instead #
|
| 5 |
+
#################################################
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
use_venv=1
|
| 9 |
+
if [[ $venv_dir == "-" ]]; then
|
| 10 |
+
use_venv=0
|
| 11 |
+
fi
|
| 12 |
+
|
| 13 |
+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# If run from macOS, load defaults from webui-macos-env.sh
|
| 17 |
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
| 18 |
+
if [[ -f "$SCRIPT_DIR"/webui-macos-env.sh ]]
|
| 19 |
+
then
|
| 20 |
+
source "$SCRIPT_DIR"/webui-macos-env.sh
|
| 21 |
+
fi
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
# Read variables from webui-user.sh
|
| 25 |
+
# shellcheck source=/dev/null
|
| 26 |
+
if [[ -f "$SCRIPT_DIR"/webui-user.sh ]]
|
| 27 |
+
then
|
| 28 |
+
source "$SCRIPT_DIR"/webui-user.sh
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
# Set defaults
|
| 32 |
+
# Install directory without trailing slash
|
| 33 |
+
if [[ -z "${install_dir}" ]]
|
| 34 |
+
then
|
| 35 |
+
install_dir="$SCRIPT_DIR"
|
| 36 |
+
fi
|
| 37 |
+
|
| 38 |
+
# Name of the subdirectory (defaults to stable-diffusion-webui)
|
| 39 |
+
if [[ -z "${clone_dir}" ]]
|
| 40 |
+
then
|
| 41 |
+
clone_dir="stable-diffusion-webui"
|
| 42 |
+
fi
|
| 43 |
+
|
| 44 |
+
# python3 executable
|
| 45 |
+
if [[ -z "${python_cmd}" ]]
|
| 46 |
+
then
|
| 47 |
+
python_cmd="python3"
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
# git executable
|
| 51 |
+
if [[ -z "${GIT}" ]]
|
| 52 |
+
then
|
| 53 |
+
export GIT="git"
|
| 54 |
+
fi
|
| 55 |
+
|
| 56 |
+
if [[ -z "${LAUNCH_SCRIPT}" ]]
|
| 57 |
+
then
|
| 58 |
+
LAUNCH_SCRIPT="launch.py"
|
| 59 |
+
fi
|
| 60 |
+
|
| 61 |
+
# this script cannot be run as root by default
|
| 62 |
+
can_run_as_root=0
|
| 63 |
+
|
| 64 |
+
# read any command line flags to the webui.sh script
|
| 65 |
+
while getopts "f" flag > /dev/null 2>&1
|
| 66 |
+
do
|
| 67 |
+
case ${flag} in
|
| 68 |
+
f) can_run_as_root=1;;
|
| 69 |
+
*) break;;
|
| 70 |
+
esac
|
| 71 |
+
done
|
| 72 |
+
|
| 73 |
+
# Disable sentry logging
|
| 74 |
+
export ERROR_REPORTING=FALSE
|
| 75 |
+
|
| 76 |
+
# Do not reinstall existing pip packages on Debian/Ubuntu
|
| 77 |
+
export PIP_IGNORE_INSTALLED=0
|
| 78 |
+
|
| 79 |
+
# Pretty print
|
| 80 |
+
delimiter="################################################################"
|
| 81 |
+
|
| 82 |
+
printf "\n%s\n" "${delimiter}"
|
| 83 |
+
printf "\e[1m\e[32mInstall script for stable-diffusion + Web UI\n"
|
| 84 |
+
printf "\e[1m\e[34mTested on Debian 11 (Bullseye)\e[0m"
|
| 85 |
+
printf "\n%s\n" "${delimiter}"
|
| 86 |
+
|
| 87 |
+
# Do not run as root
|
| 88 |
+
if [[ $(id -u) -eq 0 && can_run_as_root -eq 0 ]]
|
| 89 |
+
then
|
| 90 |
+
printf "\n%s\n" "${delimiter}"
|
| 91 |
+
printf "\e[1m\e[31mERROR: This script must not be launched as root, aborting...\e[0m"
|
| 92 |
+
printf "\n%s\n" "${delimiter}"
|
| 93 |
+
exit 1
|
| 94 |
+
else
|
| 95 |
+
printf "\n%s\n" "${delimiter}"
|
| 96 |
+
printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)"
|
| 97 |
+
printf "\n%s\n" "${delimiter}"
|
| 98 |
+
fi
|
| 99 |
+
|
| 100 |
+
if [[ $(getconf LONG_BIT) = 32 ]]
|
| 101 |
+
then
|
| 102 |
+
printf "\n%s\n" "${delimiter}"
|
| 103 |
+
printf "\e[1m\e[31mERROR: Unsupported Running on a 32bit OS\e[0m"
|
| 104 |
+
printf "\n%s\n" "${delimiter}"
|
| 105 |
+
exit 1
|
| 106 |
+
fi
|
| 107 |
+
|
| 108 |
+
if [[ -d .git ]]
|
| 109 |
+
then
|
| 110 |
+
printf "\n%s\n" "${delimiter}"
|
| 111 |
+
printf "Repo already cloned, using it as install directory"
|
| 112 |
+
printf "\n%s\n" "${delimiter}"
|
| 113 |
+
install_dir="${PWD}/../"
|
| 114 |
+
clone_dir="${PWD##*/}"
|
| 115 |
+
fi
|
| 116 |
+
|
| 117 |
+
# Check prerequisites
|
| 118 |
+
gpu_info=$(lspci 2>/dev/null | grep -E "VGA|Display")
|
| 119 |
+
case "$gpu_info" in
|
| 120 |
+
*"Navi 1"*)
|
| 121 |
+
export HSA_OVERRIDE_GFX_VERSION=10.3.0
|
| 122 |
+
if [[ -z "${TORCH_COMMAND}" ]]
|
| 123 |
+
then
|
| 124 |
+
pyv="$(${python_cmd} -c 'import sys; print(".".join(map(str, sys.version_info[0:2])))')"
|
| 125 |
+
if [[ $(bc <<< "$pyv <= 3.10") -eq 1 ]]
|
| 126 |
+
then
|
| 127 |
+
# Navi users will still use torch 1.13 because 2.0 does not seem to work.
|
| 128 |
+
export TORCH_COMMAND="pip install torch==1.13.1+rocm5.2 torchvision==0.14.1+rocm5.2 --index-url https://download.pytorch.org/whl/rocm5.2"
|
| 129 |
+
else
|
| 130 |
+
printf "\e[1m\e[31mERROR: RX 5000 series GPUs must be using at max python 3.10, aborting...\e[0m"
|
| 131 |
+
exit 1
|
| 132 |
+
fi
|
| 133 |
+
fi
|
| 134 |
+
;;
|
| 135 |
+
*"Navi 2"*) export HSA_OVERRIDE_GFX_VERSION=10.3.0
|
| 136 |
+
;;
|
| 137 |
+
*"Navi 3"*) [[ -z "${TORCH_COMMAND}" ]] && \
|
| 138 |
+
export TORCH_COMMAND="pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/rocm5.6"
|
| 139 |
+
# Navi 3 needs at least 5.5 which is only on the nightly chain, previous versions are no longer online (torch==2.1.0.dev-20230614+rocm5.5 torchvision==0.16.0.dev-20230614+rocm5.5 torchaudio==2.1.0.dev-20230614+rocm5.5)
|
| 140 |
+
# so switch to nightly rocm5.6 without explicit versions this time
|
| 141 |
+
;;
|
| 142 |
+
*"Renoir"*) export HSA_OVERRIDE_GFX_VERSION=9.0.0
|
| 143 |
+
printf "\n%s\n" "${delimiter}"
|
| 144 |
+
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"
|
| 145 |
+
printf "\n%s\n" "${delimiter}"
|
| 146 |
+
;;
|
| 147 |
+
*)
|
| 148 |
+
;;
|
| 149 |
+
esac
|
| 150 |
+
if ! echo "$gpu_info" | grep -q "NVIDIA";
|
| 151 |
+
then
|
| 152 |
+
if echo "$gpu_info" | grep -q "AMD" && [[ -z "${TORCH_COMMAND}" ]]
|
| 153 |
+
then
|
| 154 |
+
export TORCH_COMMAND="pip install torch==2.0.1+rocm5.4.2 torchvision==0.15.2+rocm5.4.2 --index-url https://download.pytorch.org/whl/rocm5.4.2"
|
| 155 |
+
fi
|
| 156 |
+
fi
|
| 157 |
+
|
| 158 |
+
for preq in "${GIT}" "${python_cmd}"
|
| 159 |
+
do
|
| 160 |
+
if ! hash "${preq}" &>/dev/null
|
| 161 |
+
then
|
| 162 |
+
printf "\n%s\n" "${delimiter}"
|
| 163 |
+
printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}"
|
| 164 |
+
printf "\n%s\n" "${delimiter}"
|
| 165 |
+
exit 1
|
| 166 |
+
fi
|
| 167 |
+
done
|
| 168 |
+
|
| 169 |
+
if [[ $use_venv -eq 1 ]] && ! "${python_cmd}" -c "import venv" &>/dev/null
|
| 170 |
+
then
|
| 171 |
+
printf "\n%s\n" "${delimiter}"
|
| 172 |
+
printf "\e[1m\e[31mERROR: python3-venv is not installed, aborting...\e[0m"
|
| 173 |
+
printf "\n%s\n" "${delimiter}"
|
| 174 |
+
exit 1
|
| 175 |
+
fi
|
| 176 |
+
|
| 177 |
+
cd "${install_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting...\e[0m" "${install_dir}"; exit 1; }
|
| 178 |
+
if [[ -d "${clone_dir}" ]]
|
| 179 |
+
then
|
| 180 |
+
cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
|
| 181 |
+
else
|
| 182 |
+
printf "\n%s\n" "${delimiter}"
|
| 183 |
+
printf "Clone stable-diffusion-webui"
|
| 184 |
+
printf "\n%s\n" "${delimiter}"
|
| 185 |
+
"${GIT}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}"
|
| 186 |
+
cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
|
| 187 |
+
fi
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
# Try using TCMalloc on Linux
|
| 191 |
+
prepare_tcmalloc() {
|
| 192 |
+
if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then
|
| 193 |
+
TCMALLOC="$(PATH=/usr/sbin:$PATH ldconfig -p | grep -Po "libtcmalloc(_minimal|)\.so\.\d" | head -n 1)"
|
| 194 |
+
if [[ ! -z "${TCMALLOC}" ]]; then
|
| 195 |
+
echo "Using TCMalloc: ${TCMALLOC}"
|
| 196 |
+
export LD_PRELOAD="${TCMALLOC}"
|
| 197 |
+
else
|
| 198 |
+
printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n"
|
| 199 |
+
fi
|
| 200 |
+
fi
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
KEEP_GOING=1
|
| 204 |
+
export SD_WEBUI_RESTART=tmp/restart
|
| 205 |
+
while [[ "$KEEP_GOING" -eq "1" ]]; do
|
| 206 |
+
if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]; then
|
| 207 |
+
printf "\n%s\n" "${delimiter}"
|
| 208 |
+
printf "Accelerating launch.py..."
|
| 209 |
+
printf "\n%s\n" "${delimiter}"
|
| 210 |
+
prepare_tcmalloc
|
| 211 |
+
accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@"
|
| 212 |
+
else
|
| 213 |
+
printf "\n%s\n" "${delimiter}"
|
| 214 |
+
printf "Launching launch.py..."
|
| 215 |
+
printf "\n%s\n" "${delimiter}"
|
| 216 |
+
prepare_tcmalloc
|
| 217 |
+
"${python_cmd}" -u "${LAUNCH_SCRIPT}" "$@"
|
| 218 |
+
fi
|
| 219 |
+
|
| 220 |
+
if [[ ! -f tmp/restart ]]; then
|
| 221 |
+
KEEP_GOING=0
|
| 222 |
+
fi
|
| 223 |
+
done
|