Jupyter and tensorboard in tmux and ssh | by Fabio M. Graetz | Towards Data Science

In recent posts, I described how you can set up your personal deep learning workstation and how you can switch it on and access it remotely.
In this short article, I explain how I usually set up my remote working environment with tmux and check on my phone on the progress of my calculations.
tmux is a terminal multiplexer, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session.
First, add the following lines to your .ssh/config on your laptop. Look here if you want a slightly more detailed instruction on how to access your computer remotely.
Host workstation     HostName <hostname>     User <username>     Port <port>     LocalForward 8888 localhost:8888     LocalForward 6006 localhost:6006
Now you can log in by typing ssh workstation. Type tmux new -s <sessionname> to launch tmux. I usually split the screen vertically by typing Ctrl-b % and then horizontally by typing Ctrl-b ". With Ctrl-b o you can navigate to the next pane. I usually go to the top right pane, start my virtual environment with source active <name> and launch a jupyter notebook by typing jupyter-notebook. Copy the link into the browser on your laptop. Next, we start tensorboard. Type Ctrl-b o to move the cursor to the next pane in tmux. Activate the virtual environment and start tensorboard by typing tensorboard --logdir=<log directory>. Open a new tab in the browser on your laptop and go to http://localhost:6006. Now tensorboard should be running as well (in case it is not working, make sure that tensorboard really uses port 6006 as in my case).
Now comes the best part: When you stop working, simply type Ctrl-b d to detach from the tmux session and when you want to continue working, type tmux attach -t <sessionname> and you are back where you left off!
Unfortunately, I don’t think that there is a way to close a jupyter notebook, while it continues running in the background, and come back to it later. What I often do, when I want to leave something calculating overnight, is converting it to python by typing jupyter-nbconvert --to script <name>.ipynb. Now, simply run the .py, detach from the tmux session and come back the next day to look at the output. If someone knows a better way, please leave a comment, I’d be thrilled to know.
Here are some other very useful shortcuts for tmux:
# session managementtmux ls (or tmux list-sessions)tmux new -s session-nameCtrl-b d Detach from sessiontmux attach -t [session name]tmux kill-session -t session-nameCtrl-b c Create new windowCtrl-b d Detach current clientCtrl-b l Move to previously selected windowCtrl-b n Move to the next windowCtrl-b p Move to the previous windowCtrl-b & Kill the current windowCtrl-b , Rename the current windowCtrl-b q Show pane numbers (used to switch between panes)Ctrl-b o Switch to the next paneCtrl-b ? List all keybindings# moving between windowsCtrl-b n (Move to the next window)Ctrl-b p (Move to the previous window)Ctrl-b l (Move to the previously selected window)Ctrl-b w (List all windows / window numbers)Ctrl-b window number (Move to the specified window number, thedefault bindings are from 0 -- 9)# Tiling commandsCtrl-b % (Split the window vertically)CTRL-b " (Split window horizontally)Ctrl-b o (Goto next pane)Ctrl-b q (Show pane numbers, when the numbers show up type the key to go to that pane)Ctrl-b { (Move the current pane left)Ctrl-b } (Move the current pane right)Ctrl-b x kill current pane# Make a pane its own windowCtrl-b : "break-pane"
Another useful hint: If you use hyperdash you can track on your phone how your model is doing without having to log in to your computer:
hyperdash run -n "DQN Breakout" python DQN.py
I hope this saves you a lot of time :) Have fun!