Skip to content

Instantly share code, notes, and snippets.

@roebius
Last active March 27, 2018 15:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roebius/991203e11687944f7ffcaec68f5526d4 to your computer and use it in GitHub Desktop.
Save roebius/991203e11687944f7ffcaec68f5526d4 to your computer and use it in GitHub Desktop.
fastai v2 - bash files for installing the fastai environment on fresh Ubuntu 16.04
source ./1.install-utils.sh
source ./2.install-cuda_8.sh
source ./3.install-repos.sh
source ./4.install-anaconda-env.sh
# set LC_ALL in /etc/default/locale
cp /etc/default/locale .
echo "LC_ALL=\"en_US.UTF-8\"" >> locale
sudo cp locale /etc/default/locale
rm locale
# insert here the installation of any optional utility libraries
sudo apt --assume-yes install tmux
sudo apt --assume-yes install unzip
sudo apt --assume-yes install ffmpeg
# This script assumes that the file cudnn-8.0-linux-x64-v7.tgz is already present in the same directory,
# the file can be found at https://developer.nvidia.com/rdp/cudnn-download after registering with Nvidia.
# Also it is assumed that the requirements for CUDA 8 installations are already met.
# ensure system is updated and has basic build tools
sudo apt update
sudo apt --assume-yes upgrade
sudo apt --assume-yes install build-essential gcc g++ make binutils
sudo apt --assume-yes install software-properties-common git
# last release of cuda 8 with update
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb" -O "cuda-repo-ubuntu1604_8.0.61-1_amd64.deb"
sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt update
sudo apt -y install cuda
wget "https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64-deb" -O "cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64-deb"
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64-deb
sudo apt update
#sudo modprobe nvidia
nvidia-smi
#rm cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
#rm cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64-deb
# cudnn
echo "installing cudnn ..."
tar -zxf cudnn-8.0-linux-x64-v7.tgz
sudo cp cuda/lib64/* /usr/local/cuda/lib64/
sudo cp cuda/include/* /usr/local/cuda/include/
#rm cudnn-8.0-linux-x64-v7.tgz
# clone the latest fast.ai course repo
git clone https://github.com/fastai/fastai.git ~/fastai
# download also the pretrained weights files
wget http://files.fast.ai/models/weights.tgz
tar -xzvf weights.tgz -C ~/fastai/fastai/
#rm weights.tgz
# download dogscats for lesson 1
mkdir -p ~/fastai/courses/dl1/data
wget http://files.fast.ai/data/dogscats.zip
unzip dogscats.zip -d ~/fastai/courses/dl1/data
#rm dogscats.zip
# This script installs Anaconda for current user,
# creates a conda virtual environment named "fast" using the environment.yml file from the fastai repo,
# adds the new environment to jupyter notebook kernel list,
# adds the nbextensions (optional),
# configures jupyter for prompting for password
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh -O ~/anaconda.sh
bash ~/anaconda.sh -b -p $HOME/anaconda
export PATH="$HOME/anaconda/bin:$PATH"
echo "export PATH=\"$HOME/anaconda/bin:\$PATH\"" >> ~/.bashrc
# create Anaconda env named "fast" using environment.yml fron fastai repo
conda env create --name fast -f ~/fastai/environment.yml
source activate fast
# add environment to jupyter notebook kernel list
python -m ipykernel install --user --name fast --display-name "fast"
# add nbextensions
conda install -c conda-forge jupyter_contrib_nbextensions
# configure jupyter for prompting for password
jupyter notebook --generate-config
jupass=`python -c "from notebook.auth import passwd; print(passwd())"`
echo "c.NotebookApp.password = u'"$jupass"'" >> $HOME/.jupyter/jupyter_notebook_config.py
echo "c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False" >> $HOME/.jupyter/jupyter_notebook_config.py
@roebius
Copy link
Author

roebius commented Nov 5, 2017

Bash scripts for installing a fastai v2 work environment on a fresh Ubuntu 16.04 machine

This is a sequence of bash scripts that I have used for installing the fastai environment and fastai v2 repo on a fresh Ubuntu 16.04 machine.
I tested the scripts on both a local machine and on a cloud-based server (an AWS p2.xlarge instance created using the base Ubuntu 16.04 AMI).

The scripts install Nvidia CUDA and CuDNN, download the fastai v2 repo and create an Anaconda environment named "fast" for use with Jupyter Notebook. The optional Jupyter Nbextensions are also installed.

In order to install CuDNN it is assumed that the cudnn file is already available on the target machine in the same folder as the install scripts: direct download of the cudnn files is restricted to registered Nvidia website users.

HOW TO INSTALL AND USE THE ENVIRONMENT

INSTALLATION

  1. download and extract the scripts to a folder of your choice on the target machine, then make them executable (chmod +x *.sh)
  2. run the 0.fastai-env-install.sh script which in turn will run all the other scripts; when prompted pick always the default choices
  3. at the end of the install sequence there will be a prompt for a password: enter one of your choice
  4. on the target machine, log out and in again, or do source ~/.bashrc: this will set the required path variables

USAGE

  1. on the target machine do the following: cd ~/fastai/courses/dl1
  2. source activate fast
  3. jupyter notebook
  4. on your local machine launch your browser
  5. if your local machine and the target machine are the same go to localhost:8888 (if your target machine is a cloud/remote server the URL might be different)
  6. in the jupyter home page you can optionally select the Nbextensions tab for activating some extra features (like Execute Time, Comment/Uncomment Hotkey, Collapsible Headings)
  7. in your jupyter notebook don't forget to select the "fast" kernel from the kernel menu before running the cells!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment