Unverified Commit 2238386a authored by Rhett Ying's avatar Rhett Ying Committed by GitHub
Browse files

[CI] enable more options for conda env creation (#5386)

* [CI] enable more options for conda env creation

* update
parent c396942d
#!/bin/bash #!/bin/bash
readonly CUDA_VERSIONS="10.2,11.3,11.6,11.7" readonly CUDA_VERSIONS="10.2,11.3,11.6,11.7"
readonly TORCH_VERSION="1.12.0" readonly TORCH_VERSION="1.12"
readonly PYTHON_VERSION="3.7"
usage() { usage() {
cat << EOF cat << EOF
...@@ -9,14 +10,20 @@ usage: bash $0 OPTIONS ...@@ -9,14 +10,20 @@ usage: bash $0 OPTIONS
examples: examples:
bash $0 -c bash $0 -c
bash $0 -g 11.7 bash $0 -g 11.7
bash $0 -g 11.7 -p 3.8
Create a developement environment for DGL developers. Create a developement environment for DGL developers.
OPTIONS: OPTIONS:
-h Show this message. -h Show this message.
-c Create dev environment in CPU mode. -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, -g Create dev environment in GPU mode with specified CUDA version,
supported: ${CUDA_VERSIONS}. supported: ${CUDA_VERSIONS}.
-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. -s Run silently which indicates always 'yes' for any confirmation.
EOF EOF
} }
...@@ -41,28 +48,50 @@ confirm() { ...@@ -41,28 +48,50 @@ confirm() {
} }
# Parse flags. # Parse flags.
while getopts "cg:hs" flag; do while getopts "cdfg:ho:p:s" flag; do
if [[ ${flag} == "c" ]]; then case "${flag}" in
c)
cpu=1 cpu=1
elif [[ ${flag} == "g" ]]; then ;;
gpu=${OPTARG} d)
elif [[ ${flag} == "h" ]]; then dry_run=1
;;
f)
force_create=1
;;
g)
cuda_version=${OPTARG}
;;
h)
usage usage
exit 0 exit 0
elif [[ ${flag} == "s" ]]; then ;;
o)
output_path=${OPTARG}
;;
p)
python_version=${OPTARG}
;;
s)
always_yes=1 always_yes=1
else ;;
:)
echo "Error: -${OPTARG} requires an argument."
exit 1
;;
*)
usage usage
exit 1 exit 1
fi ;;
esac
done done
if [[ -n ${gpu} && ${cpu} -eq 1 ]]; then if [[ -n ${cuda_version} && ${cpu} -eq 1 ]]; then
echo "Only one mode can be specified." echo "Only one mode can be specified."
exit 1 exit 1
fi fi
if [[ -z ${gpu} && -z ${cpu} ]]; then if [[ -z ${cuda_version} && -z ${cpu} ]]; then
usage usage
exit 1 exit 1
fi fi
...@@ -74,8 +103,8 @@ if [[ ${cpu} -eq 1 ]]; then ...@@ -74,8 +103,8 @@ if [[ ${cpu} -eq 1 ]]; then
fi fi
# Set up GPU mode. # Set up GPU mode.
if [[ -n ${gpu} ]]; then if [[ -n ${cuda_version} ]]; then
if ! validate ${CUDA_VERSIONS} ${gpu}; then if ! validate ${CUDA_VERSIONS} ${cuda_version}; then
echo "Error: Invalid CUDA version." echo "Error: Invalid CUDA version."
usage usage
exit 1 exit 1
...@@ -84,10 +113,15 @@ if [[ -n ${gpu} ]]; then ...@@ -84,10 +113,15 @@ if [[ -n ${gpu} ]]; then
echo "Confirm the installed CUDA version matches the specified one." echo "Confirm the installed CUDA version matches the specified one."
[[ -n "${always_yes}" ]] || confirm [[ -n "${always_yes}" ]] || confirm
torchversion=${TORCH_VERSION}"+cu"${gpu//[-._]/} torchversion=${TORCH_VERSION}"+cu"${cuda_version//[-._]/}
name="dgl-dev-gpu" name="dgl-dev-gpu"
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 "Confirm you are excuting the script from your DGL root directory."
echo "Current working directory: ${PWD}" echo "Current working directory: ${PWD}"
[[ -n "${always_yes}" ]] || confirm [[ -n "${always_yes}" ]] || confirm
...@@ -95,20 +129,36 @@ echo "Current working directory: ${PWD}" ...@@ -95,20 +129,36 @@ echo "Current working directory: ${PWD}"
# Prepare the conda environment yaml file. # Prepare the conda environment yaml file.
rand=$(echo "${RANDOM}" | md5sum | head -c 20) rand=$(echo "${RANDOM}" | md5sum | head -c 20)
mkdir -p /tmp/${rand} mkdir -p /tmp/${rand}
cp script/dgl_dev.yml.template /tmp/${rand}/dgl_dev.yml yaml_path="/tmp/${rand}/dgl_dev.yml"
sed -i "s|__NAME__|${name}|g" /tmp/${rand}/dgl_dev.yml cp script/dgl_dev.yml.template ${yaml_path}
sed -i "s|__TORCH_VERSION__|${torchversion}|g" /tmp/${rand}/dgl_dev.yml sed -i "s|__NAME__|${name}|g" ${yaml_path}
sed -i "s|__DGL_HOME__|${PWD}|g" /tmp/${rand}/dgl_dev.yml 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. # Ask for final confirmation.
echo "--------------------------------------------------" echo "--------------------------------------------------"
cat /tmp/${rand}/dgl_dev.yml cat ${yaml_path}
echo "--------------------------------------------------" echo "--------------------------------------------------"
echo "Create a conda enviroment with the config?" echo "Create a conda enviroment with the config?"
[[ -n "${always_yes}" ]] || confirm [[ -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. # Create conda environment.
conda env create -f /tmp/${rand}/dgl_dev.yml 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. # Clean up created tmp conda environment yaml file.
rm -rf /tmp/${rand} rm -rf /tmp/${rand}
......
name: __NAME__ name: __NAME__
dependencies: dependencies:
- python=3.7.0 - python=__PYTHON_VERSION__
- pip - pip
- pip: - pip:
- --find-links https://download.pytorch.org/whl/torch_stable.html - --find-links https://download.pytorch.org/whl/torch_stable.html
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment