-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_dev_conda_env.sh
184 lines (163 loc) · 4.19 KB
/
create_dev_conda_env.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
#!/bin/bash
readonly CUDA_VERSIONS="11.6,11.7,11.8,12.1"
readonly TORCH_VERSION="1.13.0"
readonly PYTHON_VERSION="3.8"
usage() {
cat << EOF
usage: bash $0 OPTIONS
examples:
bash $0 -c
bash $0 -g 11.7
bash $0 -g 11.7 -p 3.8
bash $0 -g 11.7 -p 3.8 -t 1.13.0
bash $0 -c -n dgl-dev-cpu
Create a developement environment for DGL developers.
OPTIONS:
-h Show this message.
-c Create dev environment in CPU mode.
-d Only display environment YAML file instead of creating it.
-f Force creation of environment (removing a previously existing
environment of the same name).
-g Create dev environment in GPU mode with specified CUDA version,
supported: ${CUDA_VERSIONS}.
-n Specify the name of the environment.
-o Save environment YAML file to specified path.
-p Create dev environment based on specified python version.
-s Run silently which indicates always 'yes' for any confirmation.
-t Create dev environment based on specified PyTorch version such
as '1.13.0'.
EOF
}
validate() {
values=$(echo "$1" | tr "," "\n")
for value in ${values}
do
if [[ "${value}" == $2 ]]; then
return 0
fi
done
return 1
}
confirm() {
echo "Continue? [yes/no]:"
read confirm
if [[ ! ${confirm} == "yes" ]]; then
exit 0
fi
}
# Parse flags.
while getopts "cdfg:hn:o:p:st:" flag; do
case "${flag}" in
c)
cpu=1
;;
d)
dry_run=1
;;
f)
force_create=1
;;
g)
cuda_version=${OPTARG}
;;
h)
usage
exit 0
;;
n)
name=${OPTARG}
;;
o)
output_path=${OPTARG}
;;
p)
python_version=${OPTARG}
;;
s)
always_yes=1
;;
t)
torch_version=${OPTARG}
;;
:)
echo "Error: -${OPTARG} requires an argument."
exit 1
;;
*)
usage
exit 1
;;
esac
done
if [[ -n ${cuda_version} && ${cpu} -eq 1 ]]; then
echo "Only one mode can be specified."
exit 1
fi
if [[ -z ${cuda_version} && -z ${cpu} ]]; then
usage
exit 1
fi
if [[ -z "${torch_version}" ]]; then
torch_version=${TORCH_VERSION}
fi
# Set up CPU mode.
if [[ ${cpu} -eq 1 ]]; then
torchversion=${torch_version}"+cpu"
if [[ -z "${name}" ]]; then
name="dgl-dev-cpu"
fi
fi
# Set up GPU mode.
if [[ -n ${cuda_version} ]]; then
if ! validate ${CUDA_VERSIONS} ${cuda_version}; then
echo "Error: Invalid CUDA version."
usage
exit 1
fi
echo "Confirm the installed CUDA version matches the specified one."
[[ -n "${always_yes}" ]] || confirm
torchversion=${torch_version}"+cu"${cuda_version//[-._]/}
if [[ -z "${name}" ]]; then
name="dgl-dev-gpu-"${cuda_version//[-._]/}
fi
fi
# Set python version.
if [[ -z "${python_version}" ]]; then
python_version=${PYTHON_VERSION}
fi
echo "Confirm you are excuting the script from your DGL root directory."
echo "Current working directory: ${PWD}"
[[ -n "${always_yes}" ]] || confirm
# Prepare the conda environment yaml file.
rand=$(echo "${RANDOM}" | md5sum | head -c 20)
mkdir -p /tmp/${rand}
yaml_path="/tmp/${rand}/dgl_dev.yml"
cp script/dgl_dev.yml.template ${yaml_path}
sed -i "s|__NAME__|${name}|g" ${yaml_path}
sed -i "s|__PYTHON_VERSION__|${python_version}|g" ${yaml_path}
sed -i "s|__TORCH_VERSION__|${torchversion}|g" ${yaml_path}
sed -i "s|__DGL_HOME__|${PWD}|g" ${yaml_path}
# Ask for final confirmation.
echo "--------------------------------------------------"
cat ${yaml_path}
echo "--------------------------------------------------"
echo "Create a conda enviroment with the config?"
[[ -n "${always_yes}" ]] || confirm
# Save YAML file to specified path
if [[ -n "${output_path}" ]]; then
cp ${yaml_path} ${output_path}
echo "Environment YAML file has been saved to ${output_path}."
fi
# Create conda environment.
if [[ -z "${dry_run}" ]]; then
conda_args=""
if [[ -n "${force_create}" ]]; then
conda_args="${conda_args} --force "
fi
conda env create -f ${yaml_path} ${conda_args}
else
echo "Running in dry mode, so creation of conda environment is skipped."
fi
# Clean up created tmp conda environment yaml file.
rm -rf /tmp/${rand}
exit 0