"src/vscode:/vscode.git/clone" did not exist on "0902449ef82d8f1700643ae65b20316519ac20ec"
create_dev_conda_env.sh 3.98 KB
Newer Older
1
2
#!/bin/bash

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
3
readonly CUDA_VERSIONS="10.2,11.3,11.6,11.7"
4
readonly TORCH_VERSION="1.12.0"
5
readonly PYTHON_VERSION="3.7"
6
7
8
9
10
11
12

usage() {
cat << EOF
usage: bash $0 OPTIONS
examples:
  bash $0 -c
  bash $0 -g 11.7
13
  bash $0 -g 11.7 -p 3.8
14
  bash $0 -g 11.7 -p 3.8 -t 1.13.0
15

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
16
Create a developement environment for DGL developers.
17
18
19
20

OPTIONS:
  -h           Show this message.
  -c           Create dev environment in CPU mode.
21
22
23
  -d           Only display environment YAML file instead of creating it.
  -f           Force creation of environment (removing a previously existing 
               environment of the same name).
24
  -g           Create dev environment in GPU mode with specified CUDA version,
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
25
               supported: ${CUDA_VERSIONS}.
26
27
  -o           Save environment YAML file to specified path.
  -p           Create dev environment based on specified python version.
28
  -s           Run silently which indicates always 'yes' for any confirmation.
29
30
  -t           Create dev environment based on specified PyTorch version such
               as '1.13.0'.
31
32
33
34
35
EOF
}

validate() {
  values=$(echo "$1" | tr "," "\n")
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
36
  for value in ${values}
37
  do
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
38
    if [[ "${value}" == $2 ]]; then
39
40
41
42
43
44
45
46
47
      return 0
    fi
  done
  return 1
}

confirm() {
  echo "Continue? [yes/no]:"
  read confirm
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
48
  if [[ ! ${confirm} == "yes" ]]; then
49
50
51
52
    exit 0
  fi
}

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
53
# Parse flags.
54
while getopts "cdfg:ho:p:st:" flag; do
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
  case "${flag}" in
    c)
      cpu=1
      ;;
    d)
      dry_run=1
      ;;
    f)
      force_create=1
      ;;
    g)
      cuda_version=${OPTARG}
      ;;
    h)
      usage
      exit 0
      ;;
    o)
      output_path=${OPTARG}
      ;;
    p)
      python_version=${OPTARG}
      ;;
    s)
      always_yes=1
      ;;
81
82
83
    t)
      torch_version=${OPTARG}
      ;;
84
85
86
87
88
89
90
91
92
    :)
      echo "Error: -${OPTARG} requires an argument."
      exit 1
      ;;
    *)
      usage
      exit 1
      ;;
  esac
93
94
done

95
if [[ -n ${cuda_version} && ${cpu} -eq 1 ]]; then
96
97
98
99
  echo "Only one mode can be specified."
  exit 1
fi

100
if [[ -z ${cuda_version} && -z ${cpu} ]]; then
101
102
103
104
  usage
  exit 1
fi

105
106
107
108
if [[ -z "${torch_version}" ]]; then
  torch_version=${TORCH_VERSION}
fi

109
# Set up CPU mode.
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
110
if [[ ${cpu} -eq 1 ]]; then
111
  torchversion=${torch_version}"+cpu"
112
113
114
115
  name="dgl-dev-cpu"
fi

# Set up GPU mode.
116
117
if [[ -n ${cuda_version} ]]; then
  if ! validate ${CUDA_VERSIONS} ${cuda_version}; then
118
119
120
121
122
123
    echo "Error: Invalid CUDA version."
    usage
    exit 1
  fi

  echo "Confirm the installed CUDA version matches the specified one."
124
  [[ -n "${always_yes}" ]] || confirm
125

126
  torchversion=${torch_version}"+cu"${cuda_version//[-._]/}
127
128
129
  name="dgl-dev-gpu"
fi

130
131
132
133
134
# Set python version.
if [[ -z "${python_version}" ]]; then
  python_version=${PYTHON_VERSION}
fi

135
echo "Confirm you are excuting the script from your DGL root directory."
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
136
echo "Current working directory: ${PWD}"
137
[[ -n "${always_yes}" ]] || confirm
138
139

# Prepare the conda environment yaml file.
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
140
141
rand=$(echo "${RANDOM}" | md5sum | head -c 20)
mkdir -p /tmp/${rand}
142
143
144
145
146
147
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}
148
149
150

# Ask for final confirmation.
echo "--------------------------------------------------"
151
cat ${yaml_path}
152
153
echo "--------------------------------------------------"
echo "Create a conda enviroment with the config?"
154
[[ -n "${always_yes}" ]] || confirm
155

156
157
158
159
160
161
# 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

162
# Create conda environment.
163
164
165
166
167
168
169
170
171
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
172
173

# Clean up created tmp conda environment yaml file.
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
174
rm -rf /tmp/${rand}
175
exit 0