Selecting and Verifying a GPU Runtime in Google Colab for Deep Learning
Learn how to switch Colab’s runtime to GPU, confirm it with nvidia-smi, and protect your work from session limits by checkpointing to Google Drive.
29 Apr 2026, 09:36 UTC

Problem: Slow CPU-only training in Colab
When you open a new notebook the default runtime runs on CPU, which can make even modest deep-learning workloads take minutes or hours.
Thesis: Pick a GPU runtime, verify it works, and guard against session limits
1. Selecting the GPU runtime
From the menu choose Runtime → Change runtime type. In the dialog set Hardware accelerator to GPU and click Save. Colab will provision a shared GPU, usually a Tesla T4 or P100, for the notebook.
2. Verifying that the GPU is visible
Run the following command in a code cell:
!nvidia-smiThe output should list a GPU name, driver version, and memory usage. If you see a line like Tesla T4 with non-zero memory, the accelerator is attached.
You can also ask TensorFlow or PyTorch directly:
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))or
import torch
print(torch.cuda.is_available(), torch.cuda.get_device_name(0))These calls should return a non-empty list or True and a device name.
3. Managing session limits and persisting work
Colab recycles the runtime after about 90 minutes of inactivity or after a maximum of 12 hours of continuous use. When that happens the GPU is released and any in-memory state is lost.
To avoid losing progress:
- Periodically save model checkpoints to Google Drive.
- Mount your Drive once per session:
# Create a mount point, run once
!mkdir -p drive
# Mount Drive, you will be prompted to authorize
!google-drive-ocamlfuse driveAfter mounting, you can copy files:
# Example: save a PyTorch checkpoint
import torch
torch.save(model.state_dict(), 'drive/checkpoints/model_epoch_5.pt')When the session timer in the top-right bar approaches the 90-minute idle warning, execute the copy step and then reload the notebook if needed.
Trade-off and limitation
Free Colab GPUs are shared resources. During peak demand the runtime selector may show a warning and fall back to CPU, or the selected GPU may have less memory than expected, about 15 GB. Models that exceed this limit will trigger out-of-memory errors; you must reduce batch size, use gradient checkpointing, or switch to a paid tier.
Actionable closing
Before starting a deep-learning experiment:
- Open Runtime → Change runtime type and set GPU.
- Run !nvidia-smi to confirm the accelerator.
- Run a quick TensorFlow/PyTorch device check.
- Mount Google Drive with the two-line snippet above.
- Set up a checkpoint callback that writes to drive/checkpoints/ every N epochs or minutes.
- Watch the session timer; when you see the idle warning, save your work and be ready for a possible recycle.
Following these steps lets you reap the speed-up of a GPU while protecting your work against Colab’s automatic recycling.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.