Choosing a Colab Runtime Accelerator: CPU, GPU, or TPU
Match your Colab runtime to your workload, verify the accelerator in the first cell, and checkpoint to Google Drive because local storage is wiped when the runtime recycles.
09 Nov 2025, 01:24 UTC

The problem: your accelerator is not reserved
You open a Colab notebook, launch a training cell, and find it runs slower than your laptop—or the accelerator disappears halfway through. The cause is usually the runtime type you selected, not the code. Colab does not reserve a GPU for free users, and every Colab runtime is temporary.
Use this guide to pick an accelerator before you start, verify it in the first cell, and save checkpoints where they survive a restart. If you need a fixed wall-clock schedule or multi-day uptime, Colab is not the right tool.
The decision and its constraints
The decision is which runtime type to select when creating or editing a notebook: CPU, GPU, or TPU. The constraints are:
- The free tier offers CPU, GPU (commonly an NVIDIA T4), and TPU, but accelerator assignment is not guaranteed.
- Idle disconnects often happen near 90 minutes, and absolute runtime is roughly 12 hours. Colab Pro and Pro+ add priority GPU access and longer maximum runtimes, but still provide no persistent VM or uptime SLA.
- The
/contentfilesystem is wiped when the runtime is recycled. Only mounted Google Drive, external Git checkouts, and Colab secrets persist across sessions.
Supported accelerator options
| Accelerator | Typical hardware | Best suited for | Code changes required | Session risk |
|---|---|---|---|---|
| CPU | General-purpose virtual machine | Data preparation, small scikit-learn or pandas work, debugging | None | /content wiped on recycle |
| GPU | Commonly NVIDIA T4 on free tier; priority access on paid tiers | PyTorch or TensorFlow training and inference | Move tensors and models to CUDA device | GPU may be unavailable or downgraded |
| TPU | Cloud TPU attached to the Colab VM | JAX, TensorFlow TPU workflows, PyTorch with torch_xla | XLA-compatible framework; not a CUDA drop-in | Same idle and absolute time limits |
Trade-offs
A GPU is the fastest choice for CUDA code, but it can be downgraded or refused at startup, so verify before launching a long training run. A TPU is not interchangeable with a GPU: existing CUDA code usually needs rewriting for an XLA-compatible framework such as JAX or PyTorch with torch_xla. A CPU carries no accelerator risk and is fine for exploration, but it is slow for matrix-heavy deep learning.
Verify the accelerator at startup
Run this diagnostic in the first code cell of the notebook:
import torch
print("CUDA available:", torch.cuda.is_available())
print("Visible devices:", torch.cuda.device_count())
You can also run the shell command:
!nvidia-smi
Where to run: any Colab code cell. Required permissions: none beyond edit access to the notebook. Meaningful placeholder: none; the command inspects the live session. Expected check: !nvidia-smi prints a GPU table, and torch.cuda.is_available() returns True with a device count of at least 1. Risk: empty output means the session has no GPU; do not start a long training run expecting one. Change the runtime type and retry, or continue on CPU.
Make work survive a runtime recycle
Mount Google Drive so checkpoints outlive the session:
from google.colab import drive
drive.mount("/content/drive")
Then save checkpoints to a placeholder path such as:
/content/drive/MyDrive/colab_checkpoints/model_epoch.pt
Validation procedure: save one test file to /content and another to mounted Drive, restart the runtime, and confirm that only the Drive file remains. Never keep the only copy of source code or secrets in /content; use GitHub and Colab secrets instead.
Rollback when accelerator assignment fails
Changing the runtime type changes session state. If verification shows no GPU, open Runtime > Change runtime type, switch back to CPU, and rerun the verification cell. You can retry a GPU later, but do not build a workflow that assumes the accelerator will remain allocated for the full notebook run.
Limitations and final check
Colab suits experiments, not production jobs requiring service-level agreements. Free-tier GPU models, session limits, and pricing change without notice, so check Colab’s current help documentation before relying on a specific configuration. Practical check: after selecting a runtime, run the verification cell above and confirm the accelerator appears before committing compute time to the notebook.