-
Notifications
You must be signed in to change notification settings - Fork 1
/
a1111-setup.sh
829 lines (743 loc) · 23.2 KB
/
a1111-setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
#!/usr/bin/env bash
# File: a1111-setup.sh
#
# Usage: a1111-setup.sh
#
# Description: Simple and easy Stable Diffusion WebUI (Automatic1111) and Forge install script for Mac
#
# Options: ---
# Requirements: MacOS
# Bugs: ---
# Notes: ---
# Author: Aleksandar Milanovic (viking1304)
# Version: 0.2.4
# Created: 2023/12/12 19:30:51
# Last modified: 2024/07/28 17:04:42
# Copyright (c) 2024 Aleksandar Milanovic
# https://github.com/viking1304/
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
readonly VERSION='0.2.4'
readonly YEAR='2024'
# declare variables
declare debug
declare ignore_vm
declare dry_run
declare show_info
declare -i ram
vm=false
# available colors for console output
# shellcheck disable=SC2034
readonly green='\033[32m'
# shellcheck disable=SC2034
readonly red='\033[31m'
# shellcheck disable=SC2034
readonly yellow='\033[33m'
# shellcheck disable=SC2034
readonly blue='\033[34m'
# shellcheck disable=SC2034
readonly magenta='\033[35m'
# shellcheck disable=SC2034
readonly cyan='\033[36m'
# shellcheck disable=SC2034
readonly nc='\033[0m' # no color
# default colors
color='blue'
warn_color='yellow'
err_color='red'
# repositories and default destination folders
readonly a1111_repo="https://github.com/AUTOMATIC1111/stable-diffusion-webui.git"
readonly a1111_dest_dir="${HOME}/stable-diffusion-webui"
readonly forge_repo="https://github.com/lllyasviel/stable-diffusion-webui-forge.git"
readonly forge_dest_dir="${HOME}/stable-diffusion-webui-forge"
# do not update Homebrew unless requested
update_brew=false
# install A1111 by default
fork="a1111"
# only fix errors
fix="errors"
# use recommended PyTorch version
torch_version="automatic"
# basic message without a new line
msg_nb() {
local text="$1"
local color_name='nc'
if [[ -n "$2" ]]; then
color_name="$2"
fi
# get color code from name
local color="${!color_name}"
# shellcheck disable=SC2059
printf "${color}${text}${nc}"
}
# basic message
msg() {
msg_nb "$1\n" "$2"
}
# display blank line
msg_br() {
msg ""
}
# colored message
msg_c() {
msg "$1" "${color}"
}
# colored message without a new line
msg_c_nb() {
msg_nb "$1" "${color}"
}
# only the first part of message is colored
msg_cn() {
msg_c_nb "$1"; msg "$2"
}
# only the first part of message without a new line is colored
msg_cn_nb() {
msg_c_nb "$1"; msg_nb "$2"
}
# only the second part of message is colored
msg_nc() {
msg_nb "$1"; msg_c "$2"
}
# only the second part of message without a new line is colored
msg_nc_nb() {
msg_nb "$1"; msg_c_nb "$2"
}
# warning message
warn_msg() {
local warn_subject="$1"
local warn_message="$2"
if [[ -z "$2" ]]; then
warn_subject="WARNING: "
warn_message="$1"
fi
msg_nb "${warn_subject}" "${warn_color}"; msg "${warn_message}"
}
# error message
err_msg() {
local err_subject="$1"
local err_message="$2"
if [[ -z "$2" ]]; then
err_subject="ERROR: "
err_message="$1"
fi
msg_nb "${err_subject}" "${err_color}"; msg "${err_message}"
}
# debug header
dbg_hdr () {
msg "$1" "${warn_color}"
}
# debug message
dbg_msg() {
msg_cn "$1:" " $2"
}
# dry run message
dry_msg() {
msg_cn "TEST RUN " "$1"
}
# display welcome message
welcome_message() {
msg "Welcome to"
msg_c " _ _ _ _ _ __ __ _ "
msg_c " ___| |_ __ _| |__ | | ___ __| (_)/ _|/ _|_ _ ___(_) ___ _ __ "
msg_c "/ __| __/ _\` | '_ \| |/ _ \ / _\` | | |_| |_| | | / __| |/ _ \| '_ \ "
msg_c "\__ \ || (_| | |_) | | __/ | (_| | | _| _| |_| \__ \ | (_) | | | | "
msg_c "|___/\__\__,_|_.__/|_|\___| \__,_|_|_| |_| \__,_|___/_|\___/|_| |_| "
msg_br
msg_nc " I N S T A L L E R " "v${VERSION}"
msg_br
msg_nc_nb "Copyright " "(c) ${YEAR}"; msg_nc_nb " Aleksandar Milanovic (" "viking1304"; msg ")"
msg_br
msg_nc "https://" "github.com/viking1304/a111-setup"
msg_br
}
# check if sudo requires a password and ask user to enter it if necessary
is_password_required () {
# check if sudo requires a password
if ! sudo -n true 2>/dev/null; then
# show custom password prompt
msg_nc_nb "Please enter password for user " "$USER"; msg_nb ": "
if [[ "${dry_run}" != true ]]; then
# ask for user password
sudo -v -p ""
else
msg_br
fi
else
msg_nc_nb "Password for user " "$USER"; msg " not required."
fi
msg_br
}
# keep-alive by updating existing 'sudo' time stamp until script has finished
keep_sudo_alive() {
while true; do
sudo -n true
sleep 30
done &
SUDO_KEEP_ALIVE_PID=$!
if [[ "${debug}" == true ]]; then
msg_nc "keep_sudo_alive process started with PID: " "$SUDO_KEEP_ALIVE_PID"
msg_br
fi
}
# parse command line arguments
parase_command_line_arguments() {
# convert error color to color code
local ec="${!err_color}"
# postpone displaying the help until all arguments are parsed
local help=false
# display help
display_help() {
display_help_header () {
msg_cn "$0" " usage:"
}
display_help_item () {
local item="$1"
local description="$2"
msg_nb " ["; msg_cn "${item}" "] ${description}"
}
display_help_header
display_help_item "-h" "display help"
display_help_item "-r" "dry run, only show what would be done"
display_help_item "-b" "update Homebrew"
display_help_item "-t" "use development version of PyTorch"
display_help_item "-i" "show debug info and exit"
display_help_item "-f all|none" "apply all fixes or none"
display_help_item "-d folder_name" "specify the destination folder for webui installation"
display_help_item "-o forge" "install Forge"
display_help_item "-c red|green|yellow|blue|magenta|cyan|no-color" "use specified color for messages"
msg_br
}
# parse command line arguments using getopts
while getopts ':hbtrif:d:o:c:' opt; do
case $opt in
h)
# just set the flag, because the user might want to use a custom color
help=true
;;
b)
update_brew=true
;;
t)
torch_version="develop"
;;
r)
dry_run=true
;;
i)
show_info=true
;;
f)
if [[ "${OPTARG}" != "all" && "${OPTARG}" != "none" ]]; then
err_msg "Valid arguments for the parameter ${ec}-f${nc} are all and none"
exit 1
fi
fix="${OPTARG}"
;;
d)
# ensure that destination does not start with dot
if [[ "${OPTARG}" == .* ]]; then
err_msg "Do not install webui under a directory with leading dot (.)"
msg_cn "MORE INFO: " "https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292"
exit 1
fi
dest_dir="${OPTARG}"
;;
o)
if [[ "${OPTARG}" != "forge" ]]; then
err_msg "Valid argument for the parameter ${ec}-o${nc} is forge"
exit 1
fi
fork="${OPTARG}"
;;
c)
# handle invalid colors
if [[ "${OPTARG}" != "red" && "${OPTARG}" != "green" && "${OPTARG}" != "yellow" &&
"${OPTARG}" != "blue" && "${OPTARG}" != "magenta" && "${OPTARG}" != "cyan" &&
"${OPTARG}" != "no-color"
]]; then
err_msg "Valid arguments for the parameter ${ec}-c${nc} are red, green, yellow, blue, magenta, cyan and no-color"
exit 1
fi
color="${OPTARG}"
;;
\?)
# handle invalid options
err_msg "Invalid option ${ec}-${OPTARG}${nc}"
exit 1
;;
:)
# handle missing arguments
err_msg "Option ${ec}-${OPTARG}${nc} requires an argument"
exit 1
;;
esac
done
# finally display help if the flag was set
if [[ "${help}" == true ]]; then
display_help
exit 0
fi
}
# get basic system info
get_basic_system_info() {
msg "Detecting basic system information..."
if [[ "$(sysctl -n machdep.cpu.brand_string)" =~ ^.*"Intel".*$ ]]; then
cpu="intel"
msg_nc "Running on " "Intel"
else
cpu="arm"
msg_nc "Running on " "ARM"
fi
ram="$(system_profiler SPHardwareDataType | sed -n '/Memory:/s/[^0-9]*//gp')"
msg_nc "Memory: " "${ram} GB"
if [[ "${ignore_vm}" != true && "$(system_profiler SPHardwareDataType | grep -c "Identifier.*VirtualMac")" -eq 1 ]]; then
vm=true
msg_br
warn_msg "Running inside virtual machine"
fi
msg_br
}
# set the repository, branch and destination folder
set_repo_and_dest_dir() {
if [[ "${fork}" == "a1111" ]]; then
repo="${a1111_repo}"
branch="master"
else
repo="${forge_repo}"
branch="main"
fi
# if destination folder is not set use the default location based on fork
if [[ -z "${dest_dir}" ]]; then
if [[ "${fork}" == "a1111" ]]; then
dest_dir="${a1111_dest_dir}"
else
dest_dir="${forge_dest_dir}"
fi
fi
# treat destination folder as subfolder of home directory, unless it starts with slash
if [[ "${dest_dir:0:1}" != '/' ]]; then
dest_dir="${HOME}/${dest_dir}"
fi
# remove trailing slash
dest_dir="${dest_dir%/}"
}
# install Homebrew
install_homebrew() {
msg_nc_nb "Checking for " "Homebrew"; msg "..."
if [[ -z "$(which brew)" ]]; then
msg_br
msg "Installing Homebrew..."
if [[ "${dry_run}" != true ]]; then
echo | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
dry_msg "echo | /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
fi
if cpu="arm"; then
# temporary add Homebrew to PATH if needed
if ! command -v brew > /dev/null; then
if [[ "${dry_run}" != true ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
dry_msg "eval \"\$(/opt/homebrew/bin/brew shellenv)\""
fi
fi
# permanently add Homebrew to PATH if not set in .zprofile
# shellcheck disable=SC2016
if ! grep -q 'eval "$(/opt/homebrew/bin/brew shellenv)"' ~/.zprofile; then
if [[ "${dry_run}" != true ]]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> "${HOME}/.zprofile"
else
dry_msg 'echo "eval \"\$(/opt/homebrew/bin/brew shellenv)\"" >> "${HOME}/.zprofile"'
fi
fi
fi
else
msg "Homebrew is already installed"
if [[ "${update_brew}" == true ]]; then
if [[ "${dry_run}" != true ]]; then
msg_br
brew update
brew upgrade
else
msg_br
dry_msg "brew update && brew upgrade"
fi
fi
fi
msg_br
}
# install Homebrew package
brew_install() {
msg_nc_nb "Installing " "$1"; msg "..."
if [[ "${dry_run}" != true ]]; then
if brew list "$1" &>/dev/null; then
msg "$1 is already installed"
else
brew install "$1" && msg "$1 is installed"
fi
else
dry_msg "brew install \"$1\""
fi
}
# install required packages
install_required_packages() {
brew_install cmake
brew_install protobuf
brew_install rust
brew_install [email protected]
brew_install git
brew_install wget
msg_br
}
# show list of modified files
show_modified() {
msg "List of modified files:"
git status | grep modified | sed 's/ modified: //'
}
# install A1111 or Forge
install_webui() {
# check if destination folder exists
if [[ ! -d "${dest_dir}" ]]; then
msg_nc_nb "Installing " "${fork}"; msg_nc_nb " into " "${dest_dir}"; msg "..."
# clone chosen repository to destination folder
if [[ "${dry_run}" != true ]]; then
if ! git clone "$repo" "$dest_dir"; then
err_msg "failed to clone repository ${repo}"
exit 1
else
# shellcheck disable=SC2164
cd "${dest_dir}"
fi
else
dry_msg "git clone \"$repo\" \"$dest_dir\""
fi
else
if [[ "$(ls -A "${dest_dir}")" ]]; then
msg_nc_nb "Updating " "${fork}"; msg_nc_nb " installation in " "${dest_dir}"; msg "..."
else
msg_nc_nb "Installing " "${fork}"; msg_nc_nb " into " "${dest_dir}"; msg "..."
fi
if [[ "${dry_run}" != true ]]; then
# shellcheck disable=SC2164
cd "${dest_dir}"
else
dry_msg "cd \"${dest_dir}\""
fi
# force webui upgrade
if [[ -d ".git" ]]; then
if [[ "${dry_run}" != true ]]; then
git reset --hard origin/"${branch}"
else
dry_msg "git reset --hard origin/${branch}"
fi
else
if [[ "${dry_run}" != true ]]; then
git init
git remote add origin "$repo"
git fetch --all
git reset --hard origin/"${branch}"
git branch --set-upstream-to=origin/"${branch}" "${branch}"
else
dry_msg "git init && git remote add origin \"$repo\" && git fetch --all && git reset --hard origin/${branch} && git branch --set-upstream-to=origin/${branch} ${branch}"
fi
fi
if [[ "${dry_run}" != true ]]; then
git pull
else
dry_msg "git pull"
fi
if [[ "${dry_run}" != true ]]; then
if [[ "$(git status | grep modified)" != "" ]]; then
err_msg "some webui files are still modified"
show_modified
exit 1
fi
else
dry_msg "git status | grep modified"
fi
# purge pip cache
if [[ -f "venv/bin/pip" ]]; then
msg "Purging pip cache..."
if [[ "${dry_run}" != true ]]; then
venv/bin/pip cache purge
else
dry_msg "venv/bin/pip cache purge"
fi
fi
# remove venv
if [[ -d "venv" ]]; then
msg_nc_nb "Trying to remove " "venv"; msg "..."
if [[ "${dry_run}" != true ]]; then
rm -rf venv 2> /dev/null
else
dry_msg "rm -rf venv"
fi
if [[ ! -d "venv" ]]; then
msg "Successfully removed venv"
else
warn "Could not remove venv"
msg "Trying to remove venv using admin privileges..."
if [[ "${dry_run}" != true ]]; then
sudo rm -rf venv 2> /dev/null
else
dry_msg "sudo rm -rf venv"
fi
if [[ ! -d "venv" ]]; then
msg "Successfully removed venv using admin privileges"
else
err_msg "could not remove venv even using admin privileges"
exit 1
fi
fi
fi
fi
msg_br
}
# show system info
show_sys_info () {
get_sys_info() {
local command="$1"
local result
if [[ "$command" == "sw_vers" ]]; then
result=$(sw_vers | sed -e "s/^/\\${!color}/; s/:/\\${nc}: /g; s/\t//g")
else
result=$(system_profiler "$command" | sed -n '5,10 {
s/^ *//
s/:/:'\\"${nc}"'/g
s/^/'\\"${!color}"'/
p
}')
fi
msg "$result"
}
dbg_hdr "SYSTEM INFORMATION"
get_sys_info "SPHardwareDataType"
msg_br
dbg_hdr "GRAPHICS INFORMATION"
get_sys_info "SPDisplaysDataType"
msg_br
dbg_hdr "OS VERSION"
get_sys_info "sw_vers"
}
# show python version
show_python_versions() {
dbg_hdr "PYTHON VERSIONS"
for v in {10..12}; do
if command -v python3."${v}" &> /dev/null; then
python_version="$(python3."${v}" --version)"
python_path="$(which python3."${v}")"
msg_cn "${python_version#*[[:space:]]}:" " ${python_path}"
fi
done
if command -v python3 &> /dev/null; then
p3="$(python3 --version)";
msg_cn "Default:" " ${p3#*[[:space:]]}"
fi
}
# display debug info
debug_info() {
dbg_hdr "SCRIPT"
dbg_msg "script" "${BASH_SOURCE[0]}"
dbg_msg "version" "${VERSION}"
dbg_msg "year" "${YEAR}"
msg_br
dbg_hdr "CPU AND VM"
dbg_msg "cpu" "${cpu}"
dbg_msg "vm" "${vm}"
msg_br
dbg_hdr "INSTALLATION"
dbg_msg "fork" "${fork}"
dbg_msg "repo" "${repo}"
dbg_msg "master" "${branch}"
dbg_msg "destination_dir" "${dest_dir}"
msg_br
dbg_hdr "TORCH VERSION"
dbg_msg "torch" "${torch_version}"
msg_br
dbg_hdr "FIXES"
dbg_msg "fix" "${fix}"
msg_br
dbg_hdr "ADDITIONAL INFO"
dbg_msg "update_brew" "${update_brew}"
dbg_msg "color" "${color}"
msg_br
}
# download patch file from URL and patch files
patch_file () {
local sha256
local curl_opts=""
local git_opts="-v --index"
sha256=$(curl -s "$1" | shasum -a 256 - | cut -d " " -f1)
if [[ "${sha256}" == "$2" ]]; then
if [[ "${dry_run}" != true ]]; then
if [[ "${debug}" != true ]]; then
curl_opts="-s"
git_opts="-q --index"
fi
if curl $curl_opts "$1" | git apply $git_opts; then
msg "Successfully applied patch"
else
err_msg "Could not apply patch"
exit 1
fi
else
dry_msg "curl \"$1\" | git apply $git_opts"
fi
else
err_msg "SHA256 mismatch"
msg_nc "Expected: " "$2"
msg_nc "Found: " "${sha256}"
exit 1
fi
}
# apply patches
apply_patches() {
# use develop version of PyTorch if requested
if [[ "${torch_version}" == "develop" ]]; then
if [[ "${cpu}" == "arm" && "${vm}" == false ]]; then
msg_cn "Applying patch: " "Use development version of torch"
msg "https://github.com/viking1304/stable-diffusion-webui/commit/36604c3d54fb9377b6070b08f525a011c0373ea6"
patch_file "https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/36604c3d54fb9377b6070b08f525a011c0373ea6.patch?full_index=1" "1b9c89c7462ad4f4e3876f56c7217aa5976bf9f19e1c18db85165d8ce20776fe"
else
if [[ "${vm}" == false ]]; then
warn_msg "You cannot use development version of PyTorch, because PyTorch dropped support for Intel Macs"
else
warn_msg "You cannot use development version of PyTorch inside virtual machine"
fi
fi
msg_br
fi
# check if user specifically requested not to apply any fixes
if [[ "${fix}" == "none" ]]; then
return
fi
msg "FIXES" "${warn_color}"; msg_br
# set recommended command line args
if [[ "${vm}" != true ]]; then
if [[ "${cpu}" == "arm" ]]; then
msg_cn_nb "Applying patch: " "Set recommended command line args"
if (( "${ram}" >= 16 )); then
msg " for Macs with 16 GB or more of RAM"
if [[ "${fork}" == "a1111" ]]; then
msg "COMMANDLINE_ARGS=\"--skip-torch-cuda-test --opt-sub-quad-attention --upcast-sampling --no-half-vae --use-cpu interrogate\""
patch_file "https://raw.githubusercontent.com/viking1304/a1111-setup/main/patches/lineargs-arm.patch" "23f4ef196c3e6dc868de6b664c0feca5da08c91db4d9b2829587c62a37433747"
fi
if [[ "${fork}" == "forge" ]]; then
msg "COMMANDLINE_ARGS=\"--skip-torch-cuda-test --attention-pytorch --all-in-fp16 --always-high-vram --use-cpu interrogate\""
patch_file "https://raw.githubusercontent.com/viking1304/a1111-setup/main/patches/lineargs-arm-f.patch" "75b2bf86ba0c7b73658ad9d22d62444affc7af61c904364bff0e88975e8af905"
fi
else
msg " for Macs with less than 16 GB of RAM"
if [[ "${fork}" == "a1111" ]]; then
msg "COMMANDLINE_ARGS=\"--skip-torch-cuda-test --opt-sub-quad-attention --upcast-sampling --no-half-vae --lowvram --use-cpu interrogate\""
patch_file "https://raw.githubusercontent.com/viking1304/a1111-setup/main/patches/lineargs-lowvram.patch" "fa102780cc830eefd576cbec43f6b416c02f27e4347851f82d143065ea686bd4"
fi
if [[ "${fork}" == "forge" ]]; then
msg "COMMANDLINE_ARGS=\"--skip-torch-cuda-test --attention-pytorch --all-in-fp16 --use-cpu interrogate\""
patch_file "https://raw.githubusercontent.com/viking1304/a1111-setup/main/patches/lineargs-lowvram-f.patch" "2b06015a393804db584a2a91ef56f1a0727f63fc93e44821471f7b4b8cca6550"
fi
fi
else
msg_cn "Applying patch: " "Set recommended command line args for Intel"
msg "COMMANDLINE_ARGS=\"--skip-torch-cuda-test --opt-sub-quad-attention --upcast-sampling --no-half --lowvram --use-cpu interrogate\""
patch_file "https://raw.githubusercontent.com/viking1304/a1111-setup/main/patches/lineargs-intel.patch" "62ba57613211b41ae4c505d896f88be590348f759b746bf469a8df4cdaf314aa"
fi
msg_br
fi
# set command line args for VM
if [[ "${vm}" == true ]]; then
msg_cn "Applying patch: " "Set working command line args for VM"
msg "COMMANDLINE_ARGS=\"--skip-torch-cuda-test --opt-sub-quad-attention --upcast-sampling --no-half --lowvram --use-cpu all\""
patch_file "https://raw.githubusercontent.com/viking1304/a1111-setup/main/patches/lineargs-vm.patch" "c48fdeedfa8c370b789bcc21bdac73b34b3bd603559d0bead9d30d37f791d0d8"
msg_br
fi
# non-essential patches
if [[ "${fix}" == "all" ]]; then
msg_cn "Applying patch: " "Fix cannot convert a MPS Tensor to float64 dtype error"
msg "https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/13099"
patch_file "https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/ac4bfdb6434054a949384fe2b4b52e36e0be8db0.patch?full_index=1" "cc552f22e189f0446182f2ea67b84d3f496e255d879564c08f32830b008a5e93"
msg_br
fi
}
cleanup() {
if [[ -n "$SUDO_KEEP_ALIVE_PID" ]]; then
if [[ "${debug}" == true ]]; then
msg_nc "Stopping keep_sudo_alive process with PID: " "$SUDO_KEEP_ALIVE_PID"
fi
kill "$SUDO_KEEP_ALIVE_PID" 2>/dev/null
fi
}
main() {
# execute cleanup function on EXIT
trap cleanup EXIT
# display blank line
msg_br
# exit script if not run on macOS
if [[ "$(uname -s)" != "Darwin" ]]; then
err_msg "This script can only be used on macOS!"
exit 1
fi
# parse command line arguments
parase_command_line_arguments "$@"
# show welcome message
welcome_message
# get basic system info
if [[ "${show_info}" != true ]]; then
get_basic_system_info
fi
# set the repository, branch and destination folder
set_repo_and_dest_dir
# show debug info
if [[ "${debug}" == true ]]; then
debug_info
fi
# show system info and python versions
if [[ "${show_info}" == true || "${debug}" == true ]]; then
show_sys_info
msg_br
show_python_versions
msg_br
fi
# exit after showing info
if [[ "${show_info}" == true ]]; then
exit 0
fi
# do not ask for password upfront, because of recent Homebrew changes
# https://github.com/orgs/Homebrew/discussions/5528
# check if sudo requires a password and ask user to enter it if necessary
# is_password_required
# keep-alive by updating existing 'sudo' time stamp until script has finished
# keep_sudo_alive
# install Homebrew
install_homebrew
# install required packages
install_required_packages
# (re)install A1111 or Forge
install_webui
# apply patches
apply_patches
# run webui
msg_nc "Starting " "${fork}"
if [[ "${dry_run}" != true ]]; then
./webui.sh
else
dry_msg "./webui.sh"
fi
}
# set debug mode
# debug=true
# ignore_vm=true
main "$@"