Julia on Google Colab: Free GPU-Accelerated Shareable Notebooks

This worked for me. Thanks, that’s very nice.

Probably best to put our acts together in this product feature request.

2 Likes

Now I just get error

  File "<ipython-input-1-93593d386988>", line 1
    using Pkg
            ^
SyntaxError: invalid syntax
2 Likes

I’m trying this out, installing Julia seems to work fine and from the install notebook I see e.g.

But I can’t get a second notebook started “in this same runtime” such that it sees the julia-1.2 kernel. I’ve tried the hyperlink suggestion from above which doesn’t work (maybe I got the URL wrong?) and I’ve tried uploading into the install session (but then how do I load the new notebook?). In all cases it gives me the Unrecognized runtime "julia-1.2"; defaulting to "python3" error. Any tips?

3 Likes

I have elaborately written about my issue in this link https://stackoverflow.com/questions/58270424/julia-in-google-colab. I hope some help will come my way?

1 Like

When you insert a hyperlink, is there a preceding command like - !wget or something else - to be able to run the script in the link?

Based on conversations in #gpu, it seems that the original hack broke last month due to changes in how Colaboratory handles associating “runtimes” (VMs) and notebooks. The best solution I managed to come up with was to craft a notebook that claims to be a Julia notebook, just like @jekbradbury’s original hack, and then have a cell at the top of each notebook that installs Julia and IJulia. One you run that cell, you can simply reload the page and things mostly work as expected as Colaboratory picks up on your IJulia installation. Here is a link to the notebook I am currently providing to my students for a class. While it may sound awful to have to install Julia and IJulia each time the runtime disconnects, it happens only after an hour or so in practice and it also seems that a complete CUDA stack is installed by default, so there is no need to install CUDA anymore which cuts down the installation time to just over a minute.

Known issues are code completion and syntax highlighting, I lack to expertise/time to look into this so any and all help is more than helpful.

4 Likes

Thanks a lot! It works also for Julia 1.2 for me (changing the URL for download and the kernelspec section locally in the ipynb file):

{
  "nbformat": 4,
  "nbformat_minor": 0,
 "metadata": {
    "kernelspec": {
      "name": "julia-1.2",
      "display_name": "Julia 1.2"
    },
[...]
2 Likes

@ninjin Two suggestions for the notebook template: maybe use Julia 1.1 or 1.2, since 1.0 has a bug that displays a nasty (but harmless) stacktrace when importing CuArrays. You also should do @benchmark CuArrays.@sync ... or you’re just measuring kernel launch time.

3 Likes

@maleadt Duly noted, I had wondered for some time why that scary stacktrace showed up from time to time, yet had no effect on the actual usage of CuArrays. While I have updated the benchmarking code, I will stick to 1.0 for now as the class is in full swing.

Works for me!

1 Like

I saw that many people in this discourse were getting confused on how to upload the notebook to enable Julia, here is a blog(attached with video) I made. Blog also contains link to the Youtube video on Walkthrough.

2 Likes

I posted over in the flux forum but since this has to do with Colab, I’ll ref that post here: [ANN] Flux v0.10 - #38 by GdMacmillan

Your code works really fine … CUDA gets precompiled without any problems

I tried solving the problem the problem for the Julia in Google Collab.The Julia 1.3.1 notebook works completely fine with GPU functionality.The notebook contains step by step information for the execution of code.
visit this repository:

I tried what you mentioned in the repository, and got stuck after the first step. I am not able to find any options which can change the runtime type (Initially, I used to see Python 2 and Python 3 as options). The option for Julia 1.x is not shown in Notebook settings (I remember the option existing before). I only see the option which lets me change the accelerator (None, GPU, TPU). Can you tell if there is any other method to shift to Julia in this step? I think Colab has stopped giving us options to change runtime type, and has started using Python 3 by default.
image

1 Like

This kind of error can occurr when you try to just copy the contents of the first cell into another notebook and run it.This notebook is a template to work on.
Try using the notebook in the repository directly.

2 Likes

Hello,

It works for me, but I’m curious on why that kind of error happens?

Hi Julians,

I created a Colab notebook template, inspired by the notebooks above, but which supports easily setting the version of Julia (any version since 0.7.0 up to the latest version), and changing the list of Julia packages to be installed.

I hope this helps!

13 Likes

Hi ageron,

Some feedback for you regarding your post above

  1. Please add the package Plots to your colab notebook template by default
  2. Please make it clear to the user that “Reload this page and continue to the next section.” means press the RELOAD button on your webbrowser. I spent too much time looking for the option to reload the page on the google website
  3. Inform your user that to write new julia code on colab notebook, they first need to click on the “+ Code” button on the top of the page and then look for the new code section to add in the julia code. Not every newbie is familiar with Google colab notebook
  4. Inform the user, that they need to have a google account, to use google drive. The easiest way is to set up a gmail account even if they do not use gmail.

By the way, I appreciate the work you have done to get julia to work with colab

1 Like