Google Colab is a free online coding environment that offers GPU acceleration for your data science and machine learning needs.

It runs on top of Jupyter Notebooks. That means that the interface is familiar to most data scientists that use Python.

If your local machine is too slow for some of the more intensive computations you need for machine learning, Colab can help you out.

When you use the remote runtime with the free GPU, the runtime disconnects after a while.

Colab has implemented a limit on the free usage, so that they can allocate the resources across all users and platforms.

Notebooks run by connecting to virtual machines that have maximum lifetimes that can be as much as 12 hours. Notebooks will also disconnect from VMs when left idle for too long. 1

You can increase your usage quota by paying for Colab Pro - but the paid tier is only available in the US.

That’s rather unfortunate because some functions take longer than the time it takes for Colab to disconnect.
To allow a long-running computation, you have to interact with the Colab notebook by interacting with it.

Script To Stop Google Colab From Disconnecting

Can’t we automate this?

See How to prevent Google Colab from disconnecting?:

Naturally, we want to automatically squeeze the maximum out of the instance, without having to manually interact with it constantly.

[…] such behavior does not violate Google Colab’s Terms of Use, although it is not encouraged according to their FAQ (in short: morally it is not okay to use up all of the GPUs if you don’t really need it).

You need to paste this script into the JavaScript console of the Colab browser window (Ctrl+Shift+i):

function ClickConnect() {
    .querySelector('#top-toolbar > colab-connect-button')

setInterval(ClickConnect, 60000)

Please use the script only if you need it. Google Colab doesn’t encourage you to hog resources.

Further Reading

  1. From the FAQ ↩︎