Last active
January 24, 2018 03:06
-
-
Save enewe101/d7de59dd31dbc2baa704cd75c3a0dfca to your computer and use it in GitHub Desktop.
Script to setup a virtualenv, ready for GPU programming using theano and lasagne, on the guillimin *or* helios clusters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# usage: $ bash setup-theano-lasagne.sh my-env-dir | |
# | |
# For use on helios.computecanada.ca OR guillimin.hpc.mcgill.ca. | |
# Creates a python virtual env at the directory specified by the first | |
# command line argument, then installs numpy, scipy, theano, and lasagne. | |
# Also prints handy instructions for using the virtualenv to submit | |
# jobs using the queing system, or get an interactive session. | |
# | |
# Collect install-path variables | |
install_dir=$(readlink -f $1) | |
# Notify user installation is starting | |
echo "preparing virtualenv installation at $install_dir" | |
# Install modules. These can be in different places depending on if | |
# we're on guillimin or helios clusters | |
# First, try for helios locations (note on helios we also load git) | |
module load apps/python/2.7.10 apps/git/1.8.5.3 &>/dev/null | |
# Did it work? | |
if [ $? -eq 0 ]; then | |
echo "module loaded successfuly; we seem to be on helios"; | |
cluster='helios'; | |
# If not, try loading modules from locations expected when on gillimin | |
else | |
module load Python/2.7.10 &>/dev/null; | |
# Did it work? | |
if [ $? -eq 0 ]; then | |
echo "module loaded successfuly; we seem to be on guillimin"; | |
cluster='guillimin'; | |
# If not, give up | |
else | |
echo "modules couldn't be loaded. Exiting." | |
exit 1; | |
fi | |
fi | |
# Try making a virtualenv | |
virtualenv $install_dir &>/dev/null; | |
# If it failed, try to install or add the binary path and retry | |
if [ $? -ne 0 ]; then | |
# If virtualenv is installed, ensure user-specific python binaries | |
# are on PATH and try again | |
if [ -a ~/.local/bin/virtualenv ]; then | |
PATH=~/.local/bin:$PATH; | |
virtualenv $install_dir &>/dev/null; | |
# If that doesn't work, give up | |
if [ $? -ne 0 ]; then | |
echo "Cannot find virtualenv binary. Install it and\ | |
making sure it's on your PATH, then retry this script."; | |
exit 1; | |
fi | |
# If virtualenv isn't installed, then install it, and try running | |
# it again. | |
else | |
pip install --user virtualenv; | |
PATH=~/.local/bin:PATH; | |
virtualenv $install_dir &>/dev/null | |
# If that doesn't work, give up | |
if [ $? -ne 0 ]; then | |
echo "Cannot find virtualenv binary. Install it and\ | |
making sure it's on your PATH, then retry this script."; | |
exit 1; | |
fi | |
fi | |
fi | |
source $install_dir/bin/activate | |
pip install numpy scipy | |
pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/v0.1/requirements.txt | |
pip install Lasagne==0.1 | |
# Give user a usage message | |
# First, figure out what modules they need to load (depends on the cluster) | |
# and figure out the queue submission command (these are both to be included | |
# in the user message to follow | |
if [ $cluster == 'guillimin' ]; then | |
modules_to_load="Python/2.7.10 CUDA/7.5.18 cuDNN/5.0-ga"; | |
interactive_sub="qsub -I -l nodes=1:ppn=1:gpus=1 -l walltime=3:00:00 "; | |
interactive_sub=$interactive_sub"-A xxx-###-xx"; | |
else | |
modules_to_load="apps/python/2.7.10 cuda/7.5.18 libs/cuDNN/4"; | |
interactive_sub="msub -I -l nodes=1:gpus=1 -l walltime=3:00:00 "; | |
interactive_sub=$interactive_sub"-A xxx-###-xx"; | |
fi | |
echo -e "\n" | |
echo -e "****\n" | |
echo -e "All done. Whenever you start working, type these commands to make numpy, scipy, theano, and lasagne available (also put them at the top of job scripts):\n\n\tmodule load $modules_to_load \n\tsource $install_dir/bin/activate\n\nRemember to set the device, e.g. by doing:\n\n\tTHEANO_FLAGS='floatX=float32,device=gpu' python myscript.py\n\nNote that you can only use gpus on jobs submitted through the queueing system. But you can request an 'interactive' job by doing\n\n\t$interactive_sub\n\nReplacing xxx-###-xx with your RAP ID. Your will then be taken to an interactive session on an actual copute node, and you can run code on gpus.\n" | |
echo "****" | |
echo -e "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment