forked from bmaltais/kohya_ss
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui.sh
More file actions
executable file
·137 lines (123 loc) · 4.76 KB
/
Copy pathgui.sh
File metadata and controls
executable file
·137 lines (123 loc) · 4.76 KB
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
#!/usr/bin/env bash
# Checks to see if variable is set and non-empty.
# This is defined first, so we can use the function for some default variable values
env_var_exists() {
if [[ -n "${!1}" ]]; then
return 0
else
return 1
fi
}
# Define the directory path for WSL2
lib_path="/usr/lib/wsl/lib/"
# Check if the directory exists
if [ -d "$lib_path" ]; then
# Check if LD_LIBRARY_PATH is already set
if [ -z "${LD_LIBRARY_PATH}" ]; then
# LD_LIBRARY_PATH is not set, set it to the lib_path
export LD_LIBRARY_PATH="$lib_path"
# echo "LD_LIBRARY_PATH set to: $LD_LIBRARY_PATH"
fi
fi
# Need RUNPOD to have a default value before first access
RUNPOD=false
if env_var_exists RUNPOD_POD_ID || env_var_exists RUNPOD_API_KEY; then
RUNPOD=true
fi
# If it is run with the sudo command, get the complete LD_LIBRARY_PATH environment variable of the system and assign it to the current environment,
# because it will be used later.
if [ -n "$SUDO_USER" ] || [ -n "$SUDO_COMMAND" ]; then
echo "The sudo command resets the non-essential environment variables, we keep the LD_LIBRARY_PATH variable."
export LD_LIBRARY_PATH=$(sudo -i printenv LD_LIBRARY_PATH)
fi
# This gets the directory the script is run from so pathing can work relative to the script where needed.
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
# Step into GUI local directory
cd "$SCRIPT_DIR" || exit 1
# Check if conda environment is already activated
if [ -n "$CONDA_PREFIX" ]; then
echo "Using existing conda environment: $CONDA_DEFAULT_ENV"
echo "Conda environment path: $CONDA_PREFIX"
elif [ -d "$SCRIPT_DIR/venv" ]; then
echo "Activating venv..."
source "$SCRIPT_DIR/venv/bin/activate" || exit 1
else
echo "No conda environment active and venv folder does not exist."
echo "Please run setup.sh first or activate a conda environment."
exit 1
fi
# Check if LD_LIBRARY_PATH environment variable exists
if [[ -z "${LD_LIBRARY_PATH}" ]]; then
# Set the ANSI escape sequence for yellow text
YELLOW='\033[0;33m'
# Set the ANSI escape sequence to reset text color
RESET='\033[0m'
echo -e "${YELLOW}Warning: LD_LIBRARY_PATH environment variable is not set.${RESET}"
echo -e "${YELLOW}Certain functionalities may not work correctly.${RESET}"
echo -e "${YELLOW}Please ensure that the required libraries are properly configured.${RESET}"
echo -e " "
echo -e "${YELLOW}If you use WSL2 you may want to: export LD_LIBRARY_PATH=/usr/lib/wsl/lib/${RESET}"
echo -e " "
fi
# Determine the requirements file based on the system
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ "$(uname -m)" == "arm64" ]]; then
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_macos_arm64.txt"
else
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_macos_amd64.txt"
fi
else
if [ "$RUNPOD" = false ]; then
if [[ "$@" == *"--use-ipex"* ]]; then
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_linux_ipex.txt"
elif [ -x "$(command -v nvidia-smi)" ]; then
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_linux.txt"
elif [[ "$@" == *"--use-rocm"* ]] || [ -x "$(command -v rocminfo)" ] || [ -f "/opt/rocm/bin/rocminfo" ]; then
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_linux_rocm.txt"
else
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_linux.txt"
fi
else
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_runpod.txt"
fi
fi
#Set OneAPI if it's not set by the user
if [[ "$@" == *"--use-ipex"* ]]
then
if [[ -z "${DISABLE_VENV_LIBS}" ]]; then
if [ -n "$CONDA_PREFIX" ]; then
export LD_LIBRARY_PATH=$(realpath "$CONDA_PREFIX")/lib/:$LD_LIBRARY_PATH
elif [ -d "$SCRIPT_DIR/venv" ]; then
export LD_LIBRARY_PATH=$(realpath "$SCRIPT_DIR/venv")/lib/:$LD_LIBRARY_PATH
fi
fi
if [[ -z "${NEOReadDebugKeys}" ]]; then
export NEOReadDebugKeys=1
fi
if [[ -z "${ClDeviceGlobalMemSizeAvailablePercent}" ]]; then
export ClDeviceGlobalMemSizeAvailablePercent=100
fi
if [[ -z "${SYCL_CACHE_PERSISTENT}" ]]; then
export SYCL_CACHE_PERSISTENT=1
fi
if [[ -z "${PYTORCH_ENABLE_XPU_FALLBACK}" ]]; then
export PYTORCH_ENABLE_XPU_FALLBACK=1
fi
if [[ ! -z "${IPEXRUN}" ]] && [ ${IPEXRUN}="True" ] && [ -x "$(command -v ipexrun)" ]
then
if [[ -z "$STARTUP_CMD" ]]
then
STARTUP_CMD=ipexrun
fi
if [[ -z "$STARTUP_CMD_ARGS" ]]
then
STARTUP_CMD_ARGS="--multi-task-manager taskset --memory-allocator tcmalloc"
fi
fi
fi
#Set STARTUP_CMD as normal python if not specified
if [[ -z "$STARTUP_CMD" ]]
then
STARTUP_CMD=python
fi
"${STARTUP_CMD}" $STARTUP_CMD_ARGS "$SCRIPT_DIR/kohya_gui.py" "--requirements=""$REQUIREMENTS_FILE" "$@"