Last active
July 6, 2019 03:14
-
-
Save kanjirz50/4a43e5b9c0b74f29837e54d01736dba0 to your computer and use it in GitHub Desktop.
Initialization script for jupyter(and lightgbm, catboost) with gpu on gce.
This file contains hidden or 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
#!/bin/bash | |
# 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 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 /" | sudo tee /etc/apt/sources.list.d/nvidia-ml.list | |
wget -qO - http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/7fa2af80.pub | 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 |
This file contains hidden or 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
#!/bin/bash | |
# Second: Install and setup jupyter environments. | |
set -eu | |
sudo apt install -y emacs | |
git clone https://github.com/pyenv/pyenv.git ~/.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/jupyter_notebook_config.py.bak ]; then | |
cp ~/.jupyter/jupyter_notebook_config.py ~/.jupyter/jupyter_notebook_config.py.bak | |
fi | |
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" \ | |
~/.jupyter/jupyter_notebook_config.py | |
pip install jupyter_contrib_nbextensions jupyterthemes | |
jupyter contrib nbextension install --user | |
echo "After setup firewall(0.0.0.0:8888 should be opened), Jupyter Notebook is availabel on https://ip:8888." |
This file contains hidden or 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
#!/bin/bash | |
# 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 https://github.com/Microsoft/LightGBM | |
cd LightGBM | |
mkdir build ; cd build | |
cmake -DUSE_GPU=1 .. | |
make -j$(nproc) | |
cd .. | |
# Install a LightGBM Python binding | |
cd python-package/ | |
python setup.py install --precompile | |
# Install catboost | |
cd ~/src | |
wget https://github.com/catboost/catboost/releases/download/v0.8.1/catboost-python-0.8.1-cuda-91.tar.gz | |
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