Julia on Google Colab: Free GPU-Accelerated Shareable Notebooks

announcement

#1

(Disclosure: While I work for Google, this is not an official Google product or announcement.)

tl;dr: For Julia on Colab with GPUs, first open this notebook and run the cell (takes ~15-20 minutes), then open this one to start using Julia.

Screenshot%20from%202018-09-21%2015-57-02

Recently, @denizyuret brought up on Slack that it would be nice if Google Colab supported Julia, especially for GPUs. I can’t promise anything about official or built-in support, but it turns out it’s possible to get this working entirely from the outside.

First, install CUDA 9.0 (the most recent version supported by the NVIDIA driver in the Colab GPU container) and Julia 1.0 using IPython line magic. This can be done by running the contents of this Colab notebook or by executing this code in a cell of a new notebook with the GPU runtime (either way, it takes 15-20 minutes):

!wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
!apt update -q
!apt install cuda gcc-6 g++-6 -y -q
!ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gcc
!ln -s /usr/bin/g++-6 /usr/local/cuda/bin/g++

!curl -sSL "https://julialang-s3.julialang.org/bin/linux/x64/1.0/julia-1.0.0-linux-x86_64.tar.gz" -o julia.tar.gz
!tar -xzf julia.tar.gz -C /usr --strip-components 1
!rm -rf julia.tar.gz*
!julia -e 'using Pkg; pkg"add IJulia; add CuArrays; add Flux; precompile"'

Feel free to add additional packages; you’ll also still be able to install them normally later.

Then open a new notebook in the same container (i.e., the same session) that declares julia-1.0 as its kernel. Unfortunately you can’t do this purely using the web UI; you must either use File -> Upload notebook and provide the following JSON as a .ipynb:

{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Julia on Colab.ipynb",
      "version": "0.3.2",
      "provenance": []
    },
    "kernelspec": {
      "name": "julia-1.0",
      "display_name": "Julia 1.0"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "metadata": {
        "id": "oMSuTc3pDlHv",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}

or you can simply open this notebook. If a saved notebook stops working with Julia (i.e., starts trying to run things in Python) you’ll have to run the installation notebook again.

Credits go to the intrepid folks who managed to get something similar working with node.js and R in this thread.


Juliabox notebook sharing
#2

This is excellent news, thanks James! Does this install CUDA and Julia in your personal workspace? If you shared a Julia colab notebook, would the recipient need to go through the same process?


#3

wow, it works quite well with Julia.
drop here my playground notebook.
thanks James!


#4

I ported the Julia/Knet deep learning tutorial using @jekbradbury’s hack, so anyone can run them on a gpu using colab if they first initialize with the installation notebook. Here is the Google Drive link. You can also run directly from github adding the right prefix as @ekinakyurek mentioned on slack, for example: https://colab.research.google.com/github/denizyuret/Knet.jl/blob/6b114cb771c8ec779612730feafc8c5fba552664/tutorial/03.lin.ipynb


#5

Is it possible to run Julia with TPU acceleration on Google Colab?


#6

I tried running the first notebook and I managed to install Julia correctly and I can run it using “julia”. But, I can not start a new notebook with Julia preinstalled on it.

Can you tell me if this option still works or not?


#7

see: