Making remote deep learning tolerable with Jupyter

Source: Deep Learning on Medium

Image credits

TL;DR how to setup a basic deep learning environment with Jupyter and remote servers without going crazy.

I have recently started working in deep learning and almost went crazy opening up my 5000+ line code repository using vim every-time I wanted to change a hyper parameter. Having gotten used to Jupyter I wanted to be able to use jupyter with the files on the remote server.

If you are not familiar with jupyter, here is a great post to get you started. Once familiar you can now read on to configure Jupyter to run from your local browser and work on files on the server.

  1. SSH to the remote server
  2. Use a terminal manager which allows us to create multiple session within the terminal. It also prevents the the code from truncation if connection to the remote server gets lost. So, it is useful if we have code that takes a long running time and you might want to leave it running. I personally use byobu but you can go with tumx. With Ubuntu 18, these come preinstalled. If you are running an older version and don’t see byobu you can install it by simply using
sudo apt-get install byobu 

After that you can run byobu by


The main reason we use a terminal manager is that a terminal gets used up when we run a jupyter notebook. With byobu we can create a session just for jupyter and run testing/training on another tab.

3. Next we need to link the `localhost` on our browser to the one in the terminal for that we first start jupyter with

jupyter notebook -- no-browser -- port=8889

this will force jupyter to not open a browser and use the port 8889. We can change that as we like.

Next we link this port from out server to the `localhost` on our local machine. We do that by calling

ssh -N -f -L localhost:8888:localhost:8889 username@remote-server

Please replaces username with your username and remote-server with the server address. We should see the prompt like

The Jupyter Notebook is running at: http://localhost:8889/?token=57cba986153f10a08c0efafa91e91e3299358a287afefaafa

Now we can just run


and this will launch the jupyter session linked to the remote server in the browser.

P.S you might be prompted to enter a code or token when you launch local host. For that just copy paste the token id from the terminal ( the string after `/?token=`)

And you’re set!

Thanks for reading. If you think this was useful leave a clap and/or leave comment.