-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_conda.sh
318 lines (292 loc) · 9.96 KB
/
setup_conda.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
# Setup everything for this repository
# Modified setup_conda.sh from Anyloc/Anyloc repository: https://github.com/AnyLoc/AnyLoc/blob/main/setup_conda.sh
readonly ARGS="$@" # Reset using https://stackoverflow.com/a/4827707
readonly PROGNAME=$(basename $0)
readonly PROGPATH=$(realpath $(dirname $0))
export CUDA_HOME=/usr/local/cuda
echo $CUDA_HOME
# Internal variables
env_name="anyloc" # Name of the environment
exec_name="conda" # Executable
dry_run="false" # 'true' or 'false'
ask_prompts="true" # 'true' or 'false'
dev_tools="false" # 'true' or 'false'
warn_exit="true" # 'true' or 'false'
# Output formatting
debug_msg_fmt="\e[2;90m"
info_msg_fmt="\e[1;37m"
warn_msg_fmt="\e[1;35m"
fatal_msg_fmt="\e[2;31m"
command_msg_fmt="\e[0;36m"
# Wrapper printing functions
echo_debug () {
echo -ne $debug_msg_fmt
echo $@
echo -ne "\e[0m"
}
echo_info () {
echo -ne $info_msg_fmt
echo $@
echo -ne "\e[0m"
}
echo_warn () {
echo -ne $warn_msg_fmt
echo $@
echo -ne "\e[0m"
}
echo_fatal () {
echo -ne $fatal_msg_fmt
echo $@
echo -ne "\e[0m"
}
echo_command () {
echo -ne $command_msg_fmt
echo $@
echo -ne "\e[0m"
}
# Installer functions
function run_command() {
echo_command $@
if [ $dry_run == "true" ]; then
echo_debug "Dry run, not running command..."
else
$@
fi
}
function conda_install() {
run_command $exec_name install -y --freeze-installed --no-update-deps $@
ec=$?
if [[ $ec -gt 0 ]]; then
echo_warn "Could not install '$@', maybe try though conda_raw_install"
if [[ $warn_exit == "true" ]]; then
exit $ec
else
echo_debug "Exit on warning not set, continuing..."
fi
fi
}
function conda_raw_install() {
run_command $exec_name install -y $@
}
function pip_install() {
run_command pip install --upgrade $@
}
# Ensure installation can happen
if [ -x "$(command -v mamba)" ]; then # If mamba found
echo_debug "Found mamba"
exec_name="mamba"
elif [ -x "$(command -v conda)" ]; then # If conda found
echo_debug "Found conda (couldn't find mamba)"
exec_name="conda"
else
echo_fatal "Could not find mamba or conda! Install, source, and \
activate it."
exit 127
fi
function usage() {
cat <<-EOF
Environment setup for AnyLoc
Usage:
1. bash $PROGNAME [-OPTARG VAL ...]
2. bash $PROGNAME --help
3. bash $PROGNAME NAME [-OPTARG VAL ...]
All optional arguments:
-c | --conda INST Conda installation ('mamba' or 'conda'). By
default, 'mamba' is used (if installed), else
'conda'.
-d | --dev If passed, the documentation and packaging
tools are also installed (they aren't, by
default). These are only for developers.
--dry-run If passed, the commands are printed instead of
running them.
-e | --env-name NAME Name of the conda/mamba environment. This can
also be passed as the 1st positional argument.
-h | --help Show this message.
--no-exit-on-warn By default, a warning causes the script to
exit (with a suggestion modification). If this
option is passed, the script doesn't exit (it
continues).
-n | --no-prompt By default, a prompt is shown (asking to press
Enter to continue). If this is passed, the
prompt is not shown.
Exit codes
0 Script executed successfully
1 Argument error (some wrong argument was passed)
127 Could not find conda or mamba (executable)
- Some warning (if exit on warning)
EOF
}
function parse_options() {
# Set passed arguments
set -- $ARGS
pos=1
while (( "$#" )); do
arg=$1
shift
case "$arg" in
# Conda installation to use
"--conda" | "-c")
ci=$1
shift
echo_debug "Using $ci (for anaconda base)"
exec_name=$ci
;;
# Developer install options
"--dev" | "-d")
echo_debug "Installing documentation and packaging tools"
dev_tools="true"
;;
# Dry run
"--dry-run")
echo_debug "Dry run mode enabled"
dry_run="true"
;;
# Environment name
"--env-name" | "-e")
en=$1
shift
echo_debug "Using environment $en"
env_name=$en
;;
# Help options
"--help" | "-h")
usage
exit 0
;;
# No exit on warning
"--no-exit-on-warn")
echo_debug "No exit on warning set"
warn_exit="false"
;;
# No prompt
"--no-prompt" | "-n")
echo_debug "Not showing prompts (no Enter needed)"
ask_prompts="false"
;;
*)
if [ $pos -eq 1 ]; then # Environment name
echo_debug "Using environment $arg"
env_name=$arg
else
echo_fatal "Unrecognized option: $arg"
echo_debug "Run 'bash $PROGNAME --help' for usage"
exit 1
fi
esac
pos=$((pos + 1))
done
}
# ====== Main program entrypoint ======
parse_options
if [ -x "$(command -v $exec_name)" ]; then
echo_info "Using $exec_name (for base anaconda)"
else
echo_fatal "Could not find $exec_name! Install, source, and \
activate it."
exit 1
fi
# if [ "$CONDA_DEFAULT_ENV" != "$env_name" ]; then
# echo_fatal "Wrong environment activated. Activate $env_name"
# exit 1
# fi
# Confirm environment
echo_info "Using environment: $CONDA_DEFAULT_ENV"
echo_info "Python: $(which python)"
echo_debug "Python version: $(python --version)"
echo_info "Pip: $(which pip)"
echo_debug "Pip version: $(pip --version)"
if [ $ask_prompts == "true" ]; then
read -p "Continue? [Ctrl-C to exit, enter to continue] "
elif [ $ask_prompts == "false" ]; then
echo_info "Continuing..."
fi
# Install packages
start_time=$(date)
start_time_secs=$SECONDS
echo_debug "---- Start time: $start_time ----"
# Core packages using conda_install and conda_raw_install
echo_info "------ Installing core packages ------"
conda_raw_install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
conda_raw_install -c conda-forge matplotlib==3.6.2
pip_install fast-pytorch-kmeans==0.1.6
conda_raw_install -c conda-forge einops==0.6.0
conda_raw_install -c conda-forge tqdm==4.64.1
conda_raw_install -c conda-forge joblib==1.2.0
conda_raw_install -c conda-forge wandb==0.13.9
conda_raw_install -c conda-forge natsort==8.2.0
conda_raw_install -c conda-forge pandas==2.0.0
conda_raw_install -c conda-forge opencv=4.7
conda_raw_install -c conda-forge tyro
conda_raw_install -c conda-forge scipy==1.11.4
conda_raw_install -c conda-forge scikit-learn==1.4.0
conda_raw_install -c conda-forge imageio==2.25.0
conda_raw_install -c conda-forge seaborn==0.12.1
pip_install pytorchvideo==0.1.5
pip install kornia==0.7.0
conda_raw_install -c conda-forge transformers==4.28.0
# conda_raw_install -c conda-forge googledrivedownloader==0.4
conda_raw_install -c conda-forge distinctipy==1.2.2
echo_info "------ Installing CLIP ------"
pip_install git+https://github.com/openai/CLIP.git
# pip install git+https://github.com/openai/CLIP.git
pip_install open-clip-torch==2.16.0
echo_info "------ Installing additional packages ------"
conda_raw_install -c conda-forge scikit-image==0.19.3
conda_raw_install -c conda-forge torchinfo==1.7.2
conda_raw_install -c conda-forge graphviz
conda_raw_install -c conda-forge gradio
conda_raw_install -c conda-forge pyrsistent
pip_install torchviz=='0.0.2'
# pip_install torchscan
pip_install onedrivedownloader
pip_install utm
pip_install bcrypt
pip_install streamlit==1.33.0
pip_install streamlit-extras
pip_install streamlit-elements==0.1.*
pip_install streamlit-tags
pip_install stqdm
echo_info "----- Installing streamlit-float packages -----"
cd quetzal_app/external/streamlit-float
pip install -e .
cd ../../..
# pip_install kornia==0.1.4.post2
conda_raw_install -c conda-forge kornia==0.7.0
echo_info "----- Installing Grounding Dino -----"
pip install --upgrade protobuf==4.21.12
cd quetzal/external/GroundingDINO
pip install -q -e .
cd ../../..
echo_info "----- Installing Segment-Anything -----"
pip install git+https://github.com/facebookresearch/segment-anything.git
conda_raw_install -c conda-forge jupyter
pip_install supervision==0.6.0
echo_info "----- Installing Quetzal -----"
pip install -e .
conda install -y -c pytorch faiss-gpu==1.7.4
conda install -7 -c pytorch::faiss-cpu==1.7.4
# # conda_raw_install -c pytorch faiss-gpu==1.7.2
# Core packages using pip_install
if [ $dev_tools == "true" ]; then
echo_info "------ Installing documentation and packaging tools ------"
# conda_raw_install -c conda-forge jupyter
conda_raw_install -c conda-forge nvitop
conda_raw_install -c conda-forge gpustat
pip_install webm
pip_install "imageio[ffmpeg]"
# Other packages (only for development)
elif [ $dev_tools == "false" ]; then
echo_info "Skipping documentation and packaging tools"
fi
# Installation ended
end_time=$(date)
end_time_secs=$SECONDS
echo_debug "---- End time: $end_time ----"
# dur=$(echo $(date -d "$end_time" +%s) - $(date -d "$start_time" +%s) | bc -l)
dur=$(( $end_time_secs - $start_time_secs ))
_d=$(( dur/3600/24 )) # Days!
echo_info "---- Environment setup took (d-HH:MM:SS): \
$_d-`date -d@$dur -u +%H:%M:%S` ----"
echo_info "----- Environment $CONDA_DEFAULT_ENV has been setup -----"
echo_debug "Starting time: $start_time"
echo_debug "Ending time: $end_time"