Google Colab

Also known as: Colaboratory

On this page 7

Google Colab, short for Colaboratory, is a hosted Jupyter notebook service that runs Python code in a browser on Google-managed virtual machines, with optional GPU and TPU accelerators and no local installation. Among AI frameworks & tools in artificial intelligence, it serves as an execution environment rather than a library: it hosts PyTorch, TensorFlow, JAX and similar frameworks instead of replacing them.

Colab is widely used for prototyping models, teaching machine learning and sharing reproducible experiments. Its central trade-off is simple: free or low-cost compute in exchange for ephemeral, non-guaranteed resources, which shapes how serious practitioners structure their notebooks.

How Google Colab runs a notebook

A Colab notebook is a standard .ipynb file stored in Google Drive, while the code executes on a separate runtime, a temporary Linux virtual machine allocated when the user connects. The browser only renders cells and sends them to the IPython kernel on that machine, so closing the tab does not immediately stop the work, but an expired runtime does.

Each runtime starts from a preconfigured image with Python, CUDA drivers and common libraries already installed. Additional packages are installed per session with pip install, and they disappear when the runtime is recycled, because the local disk is ephemeral. Persistent data must live in Google Drive, Cloud Storage or an external repository.

The table below lists the main components involved in a Colab session and what each one is responsible for.

ComponentRolePersistence
Notebook fileHolds code, text cells and saved outputsPersistent in Google Drive
Runtime virtual machineExecutes code on CPU, GPU or TPUTemporary, recycled after limits
Local diskStores downloaded data and checkpointsLost when the runtime ends
Mounted DriveGives the runtime access to user filesPersistent, but slower input and output
Secrets panelStores API keys outside the notebook textPersistent per user account
Components of a Colab session

Runtime types and service tiers

Colab offers CPU, GPU and TPU runtimes, and the hardware actually assigned depends on the tier and on current demand. The free tier typically provides an entry-level data center GPU such as an NVIDIA T4 when capacity allows, while paid tiers expose faster accelerators with more memory.

Paid access is metered in compute units, which are consumed at a rate that depends on the accelerator type. This means a high-end GPU drains the allowance much faster than a CPU runtime, so budgeting is done per hour of accelerator use rather than per month of subscription.

OfferingResource modelTypical fit
Free tierShared, best-effort accelerators with usage limitsLearning, small experiments
Pay as you goPurchased compute units without subscriptionOccasional heavier jobs
Colab Pro and Pro+Monthly compute units, priority access, longer sessionsRegular research and fine-tuning
Colab EnterpriseRuntimes inside a Google Cloud projectTeams needing governance and billing control
Local runtimeNotebook interface connected to the user machinePrivate data or owned hardware
Typical Colab offerings and their intended use

Session lifetimes are not guaranteed on any consumer tier. Free sessions are commonly limited to several hours of continuous use and are disconnected after a period of inactivity, and both limits change with demand and are deliberately not published as fixed values.

Colab occupies the space between a local Jupyter installation and a fully managed machine learning platform. Kaggle notebooks, which are close neighbors in the same Topic, offer a similar free hosted experience but are tightly linked to Kaggle datasets and competitions.

EnvironmentSetup effortCompute controlMain limitation
Google ColabNone, browser onlyLow, assigned by the serviceEphemeral sessions and quotas
Local JupyterInstall Python and driversFull, limited by own hardwareNo free accelerators
Kaggle notebooksNone, browser onlyLow, weekly accelerator quotaOriented to Kaggle data
Managed cloud notebooksProject and permissions setupHigh, chosen machine typesCost and administrative overhead
How Colab differs from comparable notebook environments

Colab is not a training framework, an experiment tracker or a deployment platform. Teams typically pair it with tools such as Weights & Biases or MLflow for tracking and the Hugging Face Hub for storing model weights, because nothing produced inside the runtime survives on its own.

Working effectively in Colab

Productive Colab use depends on designing notebooks for interruption. The guiding principle is that any cell sequence should be able to resume from the last saved checkpoint after a disconnect, with data and model state written to persistent storage at regular intervals.

The decision table below summarizes common situations and the recommended approach in each.

SituationRecommended approachReason
Long training runCheckpoint every epoch to Drive or Cloud StorageSessions can end without warning
Large datasetCopy archives to local disk, then extractMany small Drive reads are slow
API keys neededUse the Secrets panel, never inline textShared notebooks expose cell contents
Exact reproducibilityPin library versions in the first cellPreinstalled versions change over time
Out-of-memory errorsReduce batch size or use mixed precisionAssigned GPU memory varies by tier
Practical decisions when using Colab

The integrated AI coding assistant can generate and explain cells, but its output should be reviewed like any other code, especially commands that install packages or modify files.

Limitations and common mistakes

The most frequent problems with Colab come from treating a temporary runtime as a permanent server. The service is designed for interactive work, and its terms of use restrict activities such as unattended long-running services or cryptocurrency mining on free resources.

  • Assuming the same GPU every time: the assigned accelerator varies, so benchmarks across sessions are not directly comparable.
  • Keeping results only on local disk: outputs, checkpoints and downloaded models vanish when the runtime is recycled.
  • Running cells out of order: hidden kernel state makes a notebook appear to work until someone runs it from the top.
  • Uploading sensitive data casually: confidential or regulated data requires an approved environment such as Colab Enterprise or a local runtime.
  • Ignoring version drift: a notebook that worked months ago may fail because the base image now ships newer libraries.

A plain-language summary

Google Colab is like borrowing a powerful computer through a web page. You write Python code in a notebook, press run, and the code executes on a machine in a Google data center, which may include a graphics card built for AI work.

The catch is that the borrowed computer is temporary. When the session ends, everything not saved to Google Drive or another lasting location is wiped, much like a library computer that resets after each visitor.

An example from practice

A graduate student needs to fine-tune a small image classification model on about 20,000 labeled photos but has only a laptop without a suitable GPU. She opens a Colab notebook, selects a GPU runtime, mounts Google Drive and copies a compressed dataset archive to the local disk of the runtime before extracting it.

Training with PyTorch takes roughly three hours, so she writes a checkpoint to Drive after every epoch. When the free session disconnects partway through, she reconnects, reloads the latest checkpoint and finishes the remaining epochs. The final model weights and an evaluation report end up in Drive, and the notebook link lets her supervisor rerun the whole experiment from the first cell.