Kizi-Art commited on
Commit
be673ae
1 Parent(s): dcff4da

Upload webui.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. webui.sh +255 -0
webui.sh ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
57
+ if [[ -z "${venv_dir}" ]] && [[ $use_venv -eq 1 ]]
58
+ then
59
+ venv_dir="venv"
60
+ fi
61
+
62
+ if [[ -z "${LAUNCH_SCRIPT}" ]]
63
+ then
64
+ LAUNCH_SCRIPT="launch.py"
65
+ fi
66
+
67
+ # this script cannot be run as root by default
68
+ can_run_as_root=0
69
+
70
+ # read any command line flags to the webui.sh script
71
+ while getopts "f" flag > /dev/null 2>&1
72
+ do
73
+ case ${flag} in
74
+ f) can_run_as_root=1;;
75
+ *) break;;
76
+ esac
77
+ done
78
+
79
+ # Disable sentry logging
80
+ export ERROR_REPORTING=FALSE
81
+
82
+ # Do not reinstall existing pip packages on Debian/Ubuntu
83
+ export PIP_IGNORE_INSTALLED=0
84
+
85
+ # Pretty print
86
+ delimiter="################################################################"
87
+
88
+ printf "\n%s\n" "${delimiter}"
89
+ printf "\e[1m\e[32mInstall script for stable-diffusion + Web UI\n"
90
+ printf "\e[1m\e[34mTested on Debian 11 (Bullseye)\e[0m"
91
+ printf "\n%s\n" "${delimiter}"
92
+
93
+ # Do not run as root
94
+ if [[ $(id -u) -eq 0 && can_run_as_root -eq 0 ]]
95
+ then
96
+ printf "\n%s\n" "${delimiter}"
97
+ printf "\e[1m\e[31mERROR: This script must not be launched as root, aborting...\e[0m"
98
+ printf "\n%s\n" "${delimiter}"
99
+ exit 1
100
+ else
101
+ printf "\n%s\n" "${delimiter}"
102
+ printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)"
103
+ printf "\n%s\n" "${delimiter}"
104
+ fi
105
+
106
+ if [[ $(getconf LONG_BIT) = 32 ]]
107
+ then
108
+ printf "\n%s\n" "${delimiter}"
109
+ printf "\e[1m\e[31mERROR: Unsupported Running on a 32bit OS\e[0m"
110
+ printf "\n%s\n" "${delimiter}"
111
+ exit 1
112
+ fi
113
+
114
+ if [[ -d .git ]]
115
+ then
116
+ printf "\n%s\n" "${delimiter}"
117
+ printf "Repo already cloned, using it as install directory"
118
+ printf "\n%s\n" "${delimiter}"
119
+ install_dir="${PWD}/../"
120
+ clone_dir="${PWD##*/}"
121
+ fi
122
+
123
+ # Check prerequisites
124
+ gpu_info=$(lspci 2>/dev/null | grep -E "VGA|Display")
125
+ case "$gpu_info" in
126
+ *"Navi 1"*)
127
+ export HSA_OVERRIDE_GFX_VERSION=10.3.0
128
+ if [[ -z "${TORCH_COMMAND}" ]]
129
+ then
130
+ pyv="$(${python_cmd} -c 'import sys; print(".".join(map(str, sys.version_info[0:2])))')"
131
+ if [[ $(bc <<< "$pyv <= 3.10") -eq 1 ]]
132
+ then
133
+ # Navi users will still use torch 1.13 because 2.0 does not seem to work.
134
+ 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"
135
+ else
136
+ printf "\e[1m\e[31mERROR: RX 5000 series GPUs must be using at max python 3.10, aborting...\e[0m"
137
+ exit 1
138
+ fi
139
+ fi
140
+ ;;
141
+ *"Navi 2"*) export HSA_OVERRIDE_GFX_VERSION=10.3.0
142
+ ;;
143
+ *"Navi 3"*) [[ -z "${TORCH_COMMAND}" ]] && \
144
+ export TORCH_COMMAND="pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/rocm5.6"
145
+ # 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)
146
+ # so switch to nightly rocm5.6 without explicit versions this time
147
+ ;;
148
+ *"Renoir"*) export HSA_OVERRIDE_GFX_VERSION=9.0.0
149
+ printf "\n%s\n" "${delimiter}"
150
+ 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"
151
+ printf "\n%s\n" "${delimiter}"
152
+ ;;
153
+ *)
154
+ ;;
155
+ esac
156
+ if ! echo "$gpu_info" | grep -q "NVIDIA";
157
+ then
158
+ if echo "$gpu_info" | grep -q "AMD" && [[ -z "${TORCH_COMMAND}" ]]
159
+ then
160
+ 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"
161
+ fi
162
+ fi
163
+
164
+ for preq in "${GIT}" "${python_cmd}"
165
+ do
166
+ if ! hash "${preq}" &>/dev/null
167
+ then
168
+ printf "\n%s\n" "${delimiter}"
169
+ printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}"
170
+ printf "\n%s\n" "${delimiter}"
171
+ exit 1
172
+ fi
173
+ done
174
+
175
+ if [[ $use_venv -eq 1 ]] && ! "${python_cmd}" -c "import venv" &>/dev/null
176
+ then
177
+ printf "\n%s\n" "${delimiter}"
178
+ printf "\e[1m\e[31mERROR: python3-venv is not installed, aborting...\e[0m"
179
+ printf "\n%s\n" "${delimiter}"
180
+ exit 1
181
+ fi
182
+
183
+ cd "${install_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting...\e[0m" "${install_dir}"; exit 1; }
184
+ if [[ -d "${clone_dir}" ]]
185
+ then
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
+ else
188
+ printf "\n%s\n" "${delimiter}"
189
+ printf "Clone stable-diffusion-webui"
190
+ printf "\n%s\n" "${delimiter}"
191
+ "${GIT}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}"
192
+ cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
193
+ fi
194
+
195
+ if [[ $use_venv -eq 1 ]] && [[ -z "${VIRTUAL_ENV}" ]];
196
+ then
197
+ printf "\n%s\n" "${delimiter}"
198
+ printf "Create and activate python venv"
199
+ printf "\n%s\n" "${delimiter}"
200
+ cd "${install_dir}"/"${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
201
+ if [[ ! -d "${venv_dir}" ]]
202
+ then
203
+ "${python_cmd}" -m venv "${venv_dir}"
204
+ first_launch=1
205
+ fi
206
+ # shellcheck source=/dev/null
207
+ if [[ -f "${venv_dir}"/bin/activate ]]
208
+ then
209
+ source "${venv_dir}"/bin/activate
210
+ else
211
+ printf "\n%s\n" "${delimiter}"
212
+ printf "\e[1m\e[31mERROR: Cannot activate python venv, aborting...\e[0m"
213
+ printf "\n%s\n" "${delimiter}"
214
+ exit 1
215
+ fi
216
+ else
217
+ printf "\n%s\n" "${delimiter}"
218
+ printf "python venv already activate or run without venv: ${VIRTUAL_ENV}"
219
+ printf "\n%s\n" "${delimiter}"
220
+ fi
221
+
222
+ # Try using TCMalloc on Linux
223
+ prepare_tcmalloc() {
224
+ if [[ "${OSTYPE}" == "linux"* ]] && [[ -z "${NO_TCMALLOC}" ]] && [[ -z "${LD_PRELOAD}" ]]; then
225
+ TCMALLOC="$(PATH=/usr/sbin:$PATH ldconfig -p | grep -Po "libtcmalloc(_minimal|)\.so\.\d" | head -n 1)"
226
+ if [[ ! -z "${TCMALLOC}" ]]; then
227
+ echo "Using TCMalloc: ${TCMALLOC}"
228
+ export LD_PRELOAD="${TCMALLOC}"
229
+ else
230
+ printf "\e[1m\e[31mCannot locate TCMalloc (improves CPU memory usage)\e[0m\n"
231
+ fi
232
+ fi
233
+ }
234
+
235
+ KEEP_GOING=1
236
+ export SD_WEBUI_RESTART=tmp/restart
237
+ while [[ "$KEEP_GOING" -eq "1" ]]; do
238
+ if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]; then
239
+ printf "\n%s\n" "${delimiter}"
240
+ printf "Accelerating launch.py..."
241
+ printf "\n%s\n" "${delimiter}"
242
+ prepare_tcmalloc
243
+ accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@"
244
+ else
245
+ printf "\n%s\n" "${delimiter}"
246
+ printf "Launching launch.py..."
247
+ printf "\n%s\n" "${delimiter}"
248
+ prepare_tcmalloc
249
+ "${python_cmd}" -u "${LAUNCH_SCRIPT}" "$@"
250
+ fi
251
+
252
+ if [[ ! -f tmp/restart ]]; then
253
+ KEEP_GOING=0
254
+ fi
255
+ done