@@ -13,15 +13,16 @@ Usage:
13
13
# Same as example 1, but uses long options
14
14
setup.sh --branch=dev --dir=/workspace/kohya_ss --git-repo=https://mycustom.repo.tld/custom_fork.git
15
15
16
- # Maximum verbosity, fully automated install in a runpod environment skipping the runpod env checks
16
+ # Maximum verbosity, fully automated installation in a runpod environment skipping the runpod env checks
17
17
setup.sh -vvv --skip-space-check --runpod
18
18
19
19
Options:
20
- -b BRANCH, --branch=BRANCH Select which branch of kohya to checkout on new installs.
20
+ -b BRANCH, --branch=BRANCH Select which branch of kohya to check out on new installs.
21
21
-d DIR, --dir=DIR The full path you want kohya_ss installed to.
22
- -g, --git_repo You can optionally provide a git repo to checkout for runpod installation. Useful for custom forks.
22
+ -g, --git_repo You can optionally provide a git repo to check out for runpod installation. Useful for custom forks.
23
23
-h, --help Show this screen.
24
24
-i, --interactive Interactively configure accelerate instead of using default config file.
25
+ -n, --no-git-update Do not update kohya_ss repo. No git pull or clone operations.
25
26
-p, --public Expose public URL in runpod mode. Won't have an effect in other modes.
26
27
-r, --runpod Forces a runpod installation. Useful if detection fails for any reason.
27
28
-s, --skip-space-check Skip the 10Gb minimum storage space check.
@@ -45,11 +46,15 @@ if env_var_exists RUNPOD_POD_ID || env_var_exists RUNPOD_API_KEY; then
45
46
RUNPOD=true
46
47
fi
47
48
49
+ SCRIPT_DIR=" $( cd -- $( dirname -- " $0 " ) && pwd) "
50
+
48
51
# Variables defined before the getopts loop, so we have sane default values.
49
52
# Default installation locations based on OS and environment
50
53
if [[ " $OSTYPE " == " linux-gnu" * ]]; then
51
54
if [ " $RUNPOD " = true ]; then
52
55
DIR=" /workspace/kohya_ss"
56
+ elif [ -d " $SCRIPT_DIR /.git" ]; then
57
+ DIR=" $SCRIPT_DIR "
53
58
elif [ -w " /opt" ]; then
54
59
DIR=" /opt/kohya_ss"
55
60
elif env_var_exists HOME; then
@@ -59,7 +64,9 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
59
64
DIR=" $( PWD) "
60
65
fi
61
66
else
62
- if env_var_exists HOME; then
67
+ if [ -d " $SCRIPT_DIR /.git" ]; then
68
+ DIR=" $SCRIPT_DIR "
69
+ elif env_var_exists HOME; then
63
70
DIR=" $HOME /kohya_ss"
64
71
else
65
72
# The last fallback is simply PWD
@@ -75,8 +82,9 @@ GIT_REPO="https://github.com/bmaltais/kohya_ss.git"
75
82
INTERACTIVE=false
76
83
PUBLIC=false
77
84
SKIP_SPACE_CHECK=false
85
+ SKIP_GIT_UPDATE=false
78
86
79
- while getopts " :vb:d:g:iprs -:" opt; do
87
+ while getopts " :vb:d:g:inprs -:" opt; do
80
88
# support long options: https://stackoverflow.com/a/28466267/519360
81
89
if [ " $opt " = " -" ]; then # long option: reformulate OPT and OPTARG
82
90
opt=" ${OPTARG%% =* } " # extract long option name
@@ -88,6 +96,7 @@ while getopts ":vb:d:g:iprs-:" opt; do
88
96
d | dir) DIR=" $OPTARG " ;;
89
97
g | git-repo) GIT_REPO=" $OPTARG " ;;
90
98
i | interactive) INTERACTIVE=true ;;
99
+ n | no-git-update) SKIP_GIT_UPDATE=true ;;
91
100
p | public) PUBLIC=true ;;
92
101
r | runpod) RUNPOD=true ;;
93
102
s | skip-space-check) SKIP_SPACE_CHECK=true ;;
@@ -98,6 +107,15 @@ while getopts ":vb:d:g:iprs-:" opt; do
98
107
done
99
108
shift $(( OPTIND - 1 ))
100
109
110
+ # Just in case someone puts in a relative path into $DIR,
111
+ # we're going to get the absolute path of that.
112
+ if [[ " $DIR " != /* ]] && [[ " $DIR " != ~ * ]]; then
113
+ DIR=" $(
114
+ cd " $( dirname " $DIR " ) " || exit 1
115
+ pwd
116
+ ) /$( basename " $DIR " ) "
117
+ fi
118
+
101
119
for v in $( # Start counting from 3 since 1 and 2 are standards (stdout/stderr).
102
120
seq 3 $VERBOSITY
103
121
) ; do
@@ -123,7 +141,8 @@ INTERACTIVE: $INTERACTIVE
123
141
PUBLIC: $PUBLIC
124
142
RUNPOD: $RUNPOD
125
143
SKIP_SPACE_CHECK: $SKIP_SPACE_CHECK
126
- VERBOSITY: $VERBOSITY " >&5
144
+ VERBOSITY: $VERBOSITY
145
+ Script directory is ${SCRIPT_DIR} ." >&5
127
146
128
147
# This must be set after the getopts loop to account for $DIR changes.
129
148
PARENT_DIR=" $( dirname " ${DIR} " ) "
@@ -144,13 +163,15 @@ size_available() {
144
163
folder=' /'
145
164
fi
146
165
147
- local FREESPACEINKB=" $( df -Pk " $folder " | sed 1d | grep -v used | awk ' { print $4 "\t" }' ) "
166
+ local FREESPACEINKB
167
+ FREESPACEINKB=" $( df -Pk " $folder " | sed 1d | grep -v used | awk ' { print $4 "\t" }' ) "
148
168
echo " Detected available space in Kb: $FREESPACEINKB " >&5
149
- local FREESPACEINGB=$(( FREESPACEINKB / 1024 / 1024 ))
169
+ local FREESPACEINGB
170
+ FREESPACEINGB=$(( FREESPACEINKB / 1024 / 1024 ))
150
171
echo " $FREESPACEINGB "
151
172
}
152
173
153
- # The expected usage is create_symlinks $ symlink $ target_file
174
+ # The expected usage is create_symlinks symlink target_file
154
175
create_symlinks () {
155
176
echo " Checking symlinks now."
156
177
# Next line checks for valid symlink
@@ -173,6 +194,33 @@ create_symlinks() {
173
194
fi
174
195
}
175
196
197
+ install_pip_dependencies () {
198
+ # Updating pip if there is one
199
+ echo " Checking for pip updates before Python operations."
200
+ python3 -m pip install --upgrade pip >&3
201
+
202
+ echo " Installing python dependencies. This could take a few minutes as it downloads files."
203
+ echo " If this operation ever runs too long, you can rerun this script in verbose mode to check."
204
+ case " $OSTYPE " in
205
+ " linux-gnu" * ) pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 \
206
+ --extra-index-url https://download.pytorch.org/whl/cu116 >&3 &&
207
+ pip install -U -I --no-deps \
208
+ https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/downloadlinux/xformers-0.0.14.dev0-cp310-cp310-linux_x86_64.whl >&3 ;;
209
+ " darwin" * ) pip install torch==2.0.0 torchvision==0.15.1 \
210
+ -f https://download.pytorch.org/whl/cpu/torch_stable.html >&3 ;;
211
+ " cygwin" )
212
+ :
213
+ ;;
214
+ " msys" )
215
+ :
216
+ ;;
217
+ esac
218
+
219
+ # DEBUG ONLY (Update this version number to whatever PyCharm recommends)
220
+ # pip install pydevd-pycharm~=223.8836.43
221
+ python -m pip install --use-pep517 --upgrade -r requirements.txt >&3
222
+ }
223
+
176
224
# Attempt to non-interactively install a default accelerate config file unless specified otherwise.
177
225
# Documentation for order of precedence locations for configuration file for automated installation:
178
226
# https://huggingface.co/docs/accelerate/basic_tutorials/launch#custom-configurations
@@ -218,14 +266,44 @@ check_storage_space() {
218
266
MSGTIMEOUT=10 # In seconds
219
267
MESSAGE=" Continuing in..."
220
268
echo " Press control-c to cancel the installation."
221
- for (( i = $ MSGTIMEOUT ; i >= 0 ; i-- )) ; do
269
+ for (( i = MSGTIMEOUT; i >= 0 ; i-- )) ; do
222
270
printf " \r${MESSAGE} %ss. " " ${i} "
223
271
sleep 1
224
272
done
225
273
fi
226
274
fi
227
275
}
228
276
277
+ update_kohya_ss () {
278
+ if [ " $SKIP_GIT_UPDATE " = false ]; then
279
+ if command -v git > /dev/null; then
280
+ # First, we make sure there are no changes that need to be made in git, so no work is lost.
281
+ if [ -z " $( git -c " $DIR " status --porcelain=v1 2> /dev/null) " ]; then
282
+ echo " There are changes that need to be committed."
283
+ echo " Commit those changes or run this script with -n to skip git operations entirely."
284
+ exit 1
285
+ fi
286
+
287
+ cd " $PARENT_DIR " || exit 1
288
+ echo " Attempting to clone $GIT_REPO ."
289
+ if [ ! -d " $DIR /.git" ]; then
290
+ git -c " $DIR " clone " $GIT_REPO " " $( basename " $DIR " ) " >&3
291
+ cd " $DIR " || exit 1
292
+ git -c " $DIR " checkout -b " $BRANCH " >&3
293
+ else
294
+ cd " $DIR " || exit 1
295
+ echo " git repo detected. Attempting to update repository instead."
296
+ echo " Updating: $GIT_REPO "
297
+ git pull " $GIT_REPO " >&3
298
+ git checkout -b " $BRANCH "
299
+ fi
300
+ else
301
+ echo " You need to install git."
302
+ echo " Rerun this after installing git or run this script with -n to skip the git operations."
303
+ fi
304
+ fi
305
+ }
306
+
229
307
# Start OS-specific detection and work
230
308
if [[ " $OSTYPE " == " linux-gnu" * ]]; then
231
309
# Check if root or sudo
@@ -296,23 +374,11 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
296
374
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH :" $VENV_DIR " /lib/python3.10/site-packages/tensorrt/
297
375
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH :" $VENV_DIR " /lib/python3.10/site-packages/nvidia/cuda_runtime/lib/
298
376
cd " $DIR " || exit 1
299
- else
300
- echo " Clean installation on a runpod detected."
301
- cd " $PARENT_DIR " || exit 1
302
- if [ ! -d " $DIR /.git" ]; then
303
- echo " Cloning $GIT_REPO ."
304
- git clone " $GIT_REPO " >&3
305
- cd " $DIR " || exit 1
306
- git checkout " $BRANCH " >&3
307
- else
308
- cd " $DIR " || exit 1
309
- echo " git repo detected. Attempting to update repository instead."
310
- echo " Updating: $GIT_REPO "
311
- git pull " $GIT_REPO " >&3
312
- fi
313
377
fi
314
378
fi
315
379
380
+ update_kohya_ss
381
+
316
382
distro=get_distro_name
317
383
family=get_distro_family
318
384
echo " Raw detected distro string: $distro " >&4
@@ -373,21 +439,12 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
373
439
374
440
python3 -m venv venv
375
441
source venv/bin/activate
376
-
377
- # Updating pip if there is one
378
- echo " Checking for pip updates before Python operations."
379
- python3 -m pip install --upgrade pip >&3
380
-
381
- echo " Installing python dependencies. This could take a few minutes as it downloads files."
382
- echo " If this operation ever runs too long, you can rerun this script in verbose mode to check."
383
- pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 >&3
384
- pip install --use-pep517 --upgrade -r requirements.txt >&3
385
- pip install -U -I --no-deps \
386
- https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/linux/xformers-0.0.14.dev0-cp310-cp310-linux_x86_64.whl >&3
442
+ install_pip_dependencies
387
443
388
444
# We need this extra package and setup if we are running in a runpod
389
445
if [ " $RUNPOD " = true ]; then
390
- pip install tensorrt
446
+ echo " Installing tenssort."
447
+ pip install tensorrt >&3
391
448
# Symlink paths
392
449
libnvinfer_plugin_symlink=" $VENV_DIR /lib/python3.10/site-packages/tensorrt/libnvinfer_plugin.so.7"
393
450
libnvinfer_symlink=" $VENV_DIR /lib/python3.10/site-packages/tensorrt/libnvinfer.so.7"
@@ -457,30 +514,12 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then
457
514
echo " Python Tkinter 3.10 found!"
458
515
fi
459
516
517
+ update_kohya_ss
518
+
460
519
if command -v python3.10 > /dev/null; then
461
520
python3.10 -m venv venv
462
521
source venv/bin/activate
463
-
464
- # DEBUG ONLY
465
- # pip install pydevd-pycharm~=223.8836.43
466
-
467
- # Updating pip if there is one
468
- echo " Checking for pip updates before Python operations."
469
- python3 -m pip install --upgrade pip >&3
470
-
471
- # Tensorflow installation
472
- echo " Downloading and installing macOS Tensorflow."
473
- if wget https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl /tmp & > 3; then
474
- python -m pip install tensorflow==0.1a3 \
475
- -f https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl >&3
476
- rm -f /tmp/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl
477
- fi
478
-
479
- echo " Installing python dependencies. This could take a few minutes as it downloads files."
480
- echo " If this operation ever runs too long, you can rerun this script in verbose mode to check."
481
- pip install torch==2.0.0 torchvision==0.15.1 \
482
- -f https://download.pytorch.org/whl/cpu/torch_stable.html >&3
483
- python -m pip install --use-pep517 --upgrade -r requirements.txt >&3
522
+ install_pip_dependencies
484
523
configure_accelerate
485
524
echo -e " Setup finished! Run ./gui.sh to start."
486
525
else
0 commit comments