Running Google Colab with VS code


September 14, 2020

Running VScode and the python extension is great for development. I get clean python files and can run my code interactively. It is the same setup we have at work and I then remotely connect to a server with more cpu and GPU. However, for my side gigs I havent really figured out a workflow, until now.

This morning I found colab-ssh. It enables you to remotely connect your google colab instance to your local VScode! And if you have a GPU runtime on google colab you get that as well, of course. Combining this with a small google drive mounting, and I get more or less my local working environment but with GPU acceleration.

A quick step-by-step (see colab-ssh for updates if this doesnt work): 1. Open a new google colab notebook. 2. In first cell: Mount your google drive using these commands (you need to follow link and authorize):

from google.colab import drive
  1. Go to this site and get an ngrok token.
  2. Second cell: Add your token and create a password. Then add+run this:
# Install colab_ssh on google colab
!pip install colab_ssh --upgrade
ngrokToken = 'XXX'
password = 'XXX'
from colab_ssh import launch_ssh, init_git
  1. You’ll now see something like this:
Collecting colab_ssh
Installing collected packages: colab-ssh
Successfully installed colab-ssh-0.2.63
Successfully running
[Optional] You can also connect with VSCode SSH Remote extension using this configuration:

    Host google_colab_ssh
        User root
        Port 12345
  1. Go to your local VScode and select Remote-SSH: Open Configuration File, and paste the config above:

  1. Select Remote-SSH: Connect to Host and select the google colab ssh connection.

Voila! Up and running with gpu and your google drive attached.

Unfortunately, the hostname and port changes each time, and you still have to manually open the google colab.

Still, really great work by Wassim Benzarti.