Setting up Jupyter Notebook environment on GPU
This document covers setting up Jupyter Notebook using KakaoCloud's GPU.
- Estimated time: 20 minutes
- Recommended Operating system: MacOS, Ubuntu
- Region: kr-central-2
- Related documentation
About this scenario
This document explains the process of setting up Jupyter Notebook in combination with KakaoCloud GPU service, which is useful for data analysis and visualization. Jupyter Notebook is a web-based open-source application created by Jupyter that serves as one of the integrated development environments (IDEs) for Python. It allows you to easily use code, explanations, formulas, and graphs, making it widely used in data analysis.
By setting up Jupyter Notebook in KakaoCloud's GPU environment, you can perform data processing and model training more quickly and improve the speed of research and development more efficiently.
Step-by-step process
Step 1. Set up NVIDIA GPU environment
Install NVIDIA GPU drivers and libraries on the KakaoCloud GPU instance. This is the basic setup required to configure the Jupyter Notebook environment.
-
Refer to the Setting up NVIDIA GPU environment document to install the necessary drivers and libraries.
-
Configure the inbound policy of the security group to allow access to port 8080 of the GPU instance host. This step is essential for remote access to Jupyter Notebook.
-
Go to the KakaoCloud Console > VPC > Security Group, then click the [Manage inbound rules] button.
-
In the Inbound policy tab, add the following inbound policy.
Protocol Source IP Port number Policy description (Optional) TCP {Your Public IP}/32
8080 Jupyter Notebook
-
-
Navigate to the directory where the private key file is located.
-
Execute the following command to connect to the created instance.
ssh ubuntu@${GPU_PUBLIC_IP} -i ${PRIVATE_KEY_FILE}
# For convenience, access with root privileges.
sudo -iParameter Type Required Description GPU_PUBLIC_IP String Required Public IP address of the instance in the GPU environment PRIVATE_KEY_FILE String Required Private key file -
Run the following command to verify the installation of the NVIDIA driver and environment.
nvcc -V
# nvcc: NVIDIA (R) Cuda compiler driver ...
Step 2. Set up Jupyter Notebook environment
-
Install Python 3.8 and verify the installed version using the following command.
# Install Python 3.8
apt-get update -y
apt-get install python3.8 -y
python3 --version -
Use Anaconda to install and manage the Jupyter Notebook environment. First, download the Anaconda installation file.
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
-
Run the downloaded file to install Anaconda on your VM.
sh Anaconda3-2022.05-Linux-x86_64.sh
-
Press Enter to continue with the installation.
# In order to continue the installation process, please review the license
# agreement.
# Please, press ENTER to continue
# >>> ## Press 'Enter' ## -
Agree to the EULA and other licenses to proceed with the Anaconda installation. After reviewing the screen content, press the
q
key to move to the next step.# ==================================================
# End User License Agreement - Anaconda Distribution
# ==================================================
#
# Copyright 2015-2022, Anaconda, Inc.
# ...
# --More--
# >>> ## Press 'q' ## -
If you accept the EULA license, type
yes
.# Do you accept the license terms? [yes|no]
# [no] >>> ## Type 'yes' ## -
Press Enter to start the installation.
# - Press ENTER to confirm the location
# - Press CTRL-C to abort the installation
# - Or specify a different location below
#
# [/root/anaconda3] >>> ## Press 'Enter' ## -
Once the installation is complete, set the environment variables as shown below. Verify the installation by using the
conda
command.export PATH=~/anaconda3/bin:$PATH
# Verify installation
conda help
Step 3. Install and run Jupyter Notebook
-
Install Jupyter Notebook and generate the configuration file.
conda install jupyter-notebook
jupyter-notebook --generate-config -
Use the
printf
command to encrypt the password that will be used to access Jupyter Notebook.printf "from notebook.auth import security\nsecurity.passwd()\n" | ipython
# Enter password: ${Enter your desired password}
# Verify password: ${Re-enter your password}For example, if you set the password to "test," an encrypted password string will be displayed after Out[2]:. Copy and save this value separately.
In [2]: Enter password: test
Verify password: test
Out[2]: 'argon2:$argon2id$v=19$m=10240,t=10,p=8$oBt2YGaflk+sL3Lq60urcg$4Vc/yVxAR1x43bzlEDNy/Viu+U0kfOBDXbnsIdquEeI' -
Edit the Jupyter Notebook configuration file to specify the access IP and port. This can be done using the
sed
command below.sed -i "s/$(cat ~/.jupyter/jupyter_notebook_config.py \
| grep c.NotebookApp.ip)/c.NotebookApp.ip = '0.0.0.0'/g" \
~/.jupyter/jupyter_notebook_config.py
sed -i "s/$(cat ~/.jupyter/jupyter_notebook_config.py \
| grep "c.NotebookApp.port =")/c.NotebookApp.port = 8080/g" \
~/.jupyter/jupyter_notebook_config.py -
Use the previously copied and saved encrypted string to set the password in the Jupyter Notebook configuration file.
sed -i "s|^c\.NotebookApp\.password =.*$|c.NotebookApp.password = '${ENCRYPTED_PW}'|g" ~/.jupyter/jupyter_notebook_config.py
Parameter Type Required Description ENCRYPTED_PW String Required Encrypted password for accessing Jupyter Notebook
- The value followingOut[2]
-
Verify that the encrypted password was entered correctly.
# Verify that the previously set string is displayed.
cat ~/.jupyter/jupyter_notebook_config.py | grep "c.NotebookApp.password ="
# Example result
c.NotebookApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$oBt2YGaflk+sL3Lq60urcgs4Vc/yVxAR1x43bzlEDNy/Viu+U0kfOBDXbnsIdquEeI' -
After completing the configuration, run Jupyter Notebook on port
8080
.mkdir -p ~/jupyter
nohup jupyter notebook --allow-root > ~/jupyter/jupyter.out 2>&1 & echo $! > ~/jupyter/jupyter.pid
# Check if jupyter notebook is running.
sleep 3
curl http://localhost:8080/login -
Install the necessary libraries.
pip3 install numpy
pip3 install pandas
pip3 install matplotlib
pip3 install seaborn
pip3 install scikit-learn
pip3 install tensorflow==2.5.0 --use-deprecated=legacy-resolver
pip3 install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 \
--extra-index-url https://download.pytorch.org/whl/cu113 -
Download the example files.
git clone -b jupyter-notebook https://github.com/kakaoenterprise/kc-handson-config.git
mv ./kc-handson-config/hands-on-test.ipynb ./hands-on-test.ipynb
Step 4. Access to Jupyter Notebook
-
Verify that the Jupyter Notebook process is running, then access it in your browser at
${GPU_PUBLIC_IP}:8080/login
. -
Enter the password you set to log in.
-
After entering the password, you will be directed to the Jupyter Notebook working directory page. Access the downloaded
handson-on-test.ipynb
file. -
Run the example code to verify that it prints “Hello kakaocloud!”.