Skip to content

Instantly share code, notes, and snippets.

Last active Jul 6, 2019
What would you like to do?
Initialization script for jupyter(and lightgbm, catboost) with gpu on gce.
# First: Install nvidia-driver and cuda
# Install nvidia-driver
sudo apt-get update
sudo apt-get install --no-install-recommends nvidia-375
sudo apt-get install --no-install-recommends nvidia-opencl-icd-375 nvidia-opencl-dev opencl-headers
# Cuda and cudnn installation
echo "deb /" | sudo tee /etc/apt/sources.list.d/nvidia-ml.list
wget -qO - | sudo apt-key add -
sudo apt update
sudo apt install libcudnn7-dev nvidia-cuda-toolkit libc6-dev gcc-multilib g++-multilib
# Change runlevel and restart the system.
sudo init 6
# Second: Install and setup jupyter environments.
set -eu
sudo apt install -y emacs
git clone ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
exec "$SHELL"
pyenv install anaconda3-5.2.0
pyenv global anaconda3-5.2.0
jupyter notebook --generate-config && cd ~/.jupyter && openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem
echo "Set a Jupyter password"
hashed_passwd=$(python -c "from notebook.auth import passwd;print(passwd())")
if [ ! -e ~/.jupyter/ ]; then
cp ~/.jupyter/ ~/.jupyter/
sed -i -e "s/#c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '*'/g" \
-e "s|#c.NotebookApp.certfile = ''|c.NotebookApp.certfile = '$HOME/.jupyter/mycert.pem'|g" \
-e "s|#c.NotebookApp.keyfile = ''|c.NotebookApp.keyfile = '$HOME/.jupyter/mykey.key'|g" \
-e "s|#c.NotebookApp.open_browser = True|c.NotebookApp.open_browser = False" \
-e "s/#c.NotebookApp.password = ''/c.NotebookApp.password = '$hashed_passwd'/g" \
pip install jupyter_contrib_nbextensions jupyterthemes
jupyter contrib nbextension install --user
echo "After setup firewall( should be opened), Jupyter Notebook is availabel on https://ip:8888."
# Third: Install LightGBM and Catboost that enable GPU mode.
# Build directory
mkdir -p ~/src
cd ~/src
# Dependency for LightGBM
sudo apt-get install --no-install-recommends git cmake build-essential libboost-dev libboost-system-dev libboost-filesystem-dev
# Build LightGBM
git clone --recursive
cd LightGBM
mkdir build ; cd build
cmake -DUSE_GPU=1 ..
make -j$(nproc)
cd ..
# Install a LightGBM Python binding
cd python-package/
python install --precompile
# Install catboost
cd ~/src
tar zxf catboost-python-0.8.1-cuda-91.tar.gz
cd linux-cuda9
pip install catboost-0.8.1-cp36-none-manylinux1_x86_64.whl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment