Google Colab is great, Julia is great, we should have both.
Steps to run:
- Open
julia.ipynb
file on your colab. Here's the quick link for CPU runtime and GPU runtime - install the Julia kernel by running the first block
- refresh the page
- start coding Julia in colab 🎉
What's behind the scenes, a step by step explanation:
- jupyter notebook has predefined kernelspec information, this
julia.ipynb
file predefines"julia"
kernel. You can find this by checking in raw format - when you start a new runtime in colab, it tries to open the Julia kernel, because that's what
julia.ipynb
requires. But unfortunately this will fail, so colab falls back to using the Python kernel - install the Julia kernel by running the first block in python kernel (note the prefix
!
) - refresh the page, colab will then reload the notebook, again, it will try to load the
julia
kernel. But since we have it installed in the current runtime, this time it will succeed.
Because the julia
kernelspec is not available by default, you will need to install Julia kernel everytime when you start a new colab runtime.
For GPU runtimes, it seems that when you refresh the page via "Ctrl-R" colab will redirect you to the CPU runtimes and thus you lose the Julia kernel. I don't know the internal but this is perhaps a colab strategy to save GPU resource. To fix it, instead of manually refreshing page via "Ctrl-R", you can instead trigger kernel reloading by:
- go to "view resources" -> "change runtime type"
- ensure it is "Julia" and "GPU". Almost certainly you don't need to change anything here if you're already on GPU runtime.
- click "save" to trigger the kernel reload.
This trick works when I write it up, I hope this still works in the future.
It's also worth noting that you can force CUDA.jl to use system-installed CUDA library by setting
environment variable JULIA_CUDA_USE_BINARYBUILDER
to false
. This saves a lot of downloading time.