Google Colab not using GPU? Fix slow training

Google Colab · Performance · Approx. 9 min read

Colab says “GPU” is selected, but your training is still slow or your CPU is at 100% and GPU at 0%. This usually means your code never moved the model or tensors to the GPU. Let’s fix that.

1. Make sure GPU is actually enabled

  1. Runtime → Change runtime type → Hardware accelerator: GPU → Save.
  2. In a cell, run:
import torch
print(torch.cuda.is_available())

You should see True. For TensorFlow:

import tensorflow as tf
print(tf.config.list_physical_devices("GPU"))

2. Move model and data to GPU (PyTorch)

device = "cuda" if torch.cuda.is_available() else "cpu"

model = MyModel().to(device)

for inputs, labels in train_loader:
    inputs = inputs.to(device)
    labels = labels.to(device)
    outputs = model(inputs)
    loss   = criterion(outputs, labels)
    # backward, step, etc.

If you forget .to(device), your training will silently run on CPU.

3. Move model and data to GPU (TensorFlow / Keras)

import tensorflow as tf

print(tf.config.list_logical_devices("GPU"))

with tf.device("/GPU:0"):
    model = create_model()
    model.compile(optimizer="adam", loss="categorical_crossentropy")

model.fit(train_dataset, epochs=10)

In many simple cases, Keras will automatically use the GPU when available, but putting the model under with tf.device makes intent explicit.

4. Check whether data pipeline is the real bottleneck

5. Snapshot a working GPU setup with NoteCapsule

Once your notebook definitely uses GPU and runs at a reasonable speed, capture a Capsule so you can reuse the same setup (and show your professor/teammates).

from notebookcapsule import create_capsule

create_capsule(
    name="gpu-training-ok",
    notebook_path="notebooks/train_on_gpu.ipynb",
    data_dirs=["./data"],
    base_dir=".",  # project root
)

Lock in the moment when your GPU finally works

NoteCapsule keeps a reproducible snapshot of your Colab GPU setup – code, data layout, and environment – so you don’t have to fight the same slow-training issues again later.

Join NoteCapsule early access