create_dev_conda_env.sh 2.35 KB
Newer Older
1
2
#!/bin/bash

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

usage() {
cat << EOF
usage: bash $0 OPTIONS
examples:
  bash $0 -c
  bash $0 -g 11.7

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

OPTIONS:
  -h           Show this message.
  -c           Create dev environment in CPU mode.
  -g           Create dev environment in GPU mode with specified CUDA version,
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
19
               supported: ${CUDA_VERSIONS}.
20
21
22
23
24
EOF
}

validate() {
  values=$(echo "$1" | tr "," "\n")
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
25
  for value in ${values}
26
  do
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
27
    if [[ "${value}" == $2 ]]; then
28
29
30
31
32
33
34
35
36
      return 0
    fi
  done
  return 1
}

confirm() {
  echo "Continue? [yes/no]:"
  read confirm
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
37
  if [[ ! ${confirm} == "yes" ]]; then
38
39
40
41
    exit 0
  fi
}

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
42
# Parse flags.
43
while getopts "cg:h" flag; do
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
44
  if [[ ${flag} == "c" ]]; then
45
    cpu=1
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
46
47
48
  elif [[ ${flag} == "g" ]]; then
    gpu=${OPTARG}
  elif [[ ${flag} == "h" ]]; then
49
50
51
52
53
54
55
56
    usage
    exit 0
  else
    usage
    exit 1
  fi
done

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
57
if [[ -n ${gpu} && ${cpu} -eq 1 ]]; then
58
59
60
61
  echo "Only one mode can be specified."
  exit 1
fi

Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
62
if [[ -z ${gpu} && -z ${cpu} ]]; then
63
64
65
66
67
  usage
  exit 1
fi

# Set up CPU mode.
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
68
if [[ ${cpu} -eq 1 ]]; then
69
70
71
72
73
  torchversion=${TORCH_VERSION}"+cpu"
  name="dgl-dev-cpu"
fi

# Set up GPU mode.
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
74
if [[ -n ${gpu} ]]; then
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  if ! validate ${CUDA_VERSIONS} ${gpu}; then
    echo "Error: Invalid CUDA version."
    usage
    exit 1
  fi

  echo "Confirm the installed CUDA version matches the specified one."
  confirm

  torchversion=${TORCH_VERSION}"+cu"${gpu//[-._]/}
  name="dgl-dev-gpu"
fi

echo "Confirm you are excuting the script from your DGL root directory."
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
89
echo "Current working directory: ${PWD}"
90
91
92
confirm

# Prepare the conda environment yaml file.
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
93
94
95
96
97
98
rand=$(echo "${RANDOM}" | md5sum | head -c 20)
mkdir -p /tmp/${rand}
cp script/dgl_dev.yml.template /tmp/${rand}/dgl_dev.yml
sed -i "s|__NAME__|${name}|g" /tmp/${rand}/dgl_dev.yml
sed -i "s|__TORCH_VERSION__|${torchversion}|g" /tmp/${rand}/dgl_dev.yml
sed -i "s|__DGL_HOME__|${PWD}|g" /tmp/${rand}/dgl_dev.yml
99
100
101

# Ask for final confirmation.
echo "--------------------------------------------------"
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
102
cat /tmp/${rand}/dgl_dev.yml
103
104
105
106
107
echo "--------------------------------------------------"
echo "Create a conda enviroment with the config?"
confirm

# Create conda environment.
Hongzhi (Steve), Chen's avatar
Hongzhi (Steve), Chen committed
108
conda env create -f /tmp/${rand}/dgl_dev.yml
109
110

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