Enable GPU in a Kaggle Notebook: Settings, Limits, and Pitfalls
Turn on GPU hardware acceleration in Kaggle Notebooks, verify CUDA with nvidia-smi, and manage session, storage, and weekly compute limits.
19 Jul 2025, 11:55 UTC

If your Kaggle Notebook is training a model on CPU and each epoch takes minutes instead of seconds, the fastest fix is usually hardware, not code. Kaggle Notebooks can attach an NVIDIA GPU to the notebook container. The useful takeaway: open Settings, switch Hardware accelerator to GPU, restart the kernel, then verify CUDA is visible before you run training code. Without the restart, the notebook keeps using the CPU even though the UI shows GPU selected.
Enable the GPU accelerator
Open the notebook in Kaggle. In the side panel, select Settings, then choose GPU under Hardware accelerator. Save the setting. Kaggle restarts the kernel to attach the accelerator.
- Open the notebook editor.
- Open Settings (gear icon or side panel, depending on layout).
- Set Hardware accelerator to GPU.
- Save and allow the kernel to restart.
This is a state-changing operation. The kernel restart clears every variable, imported module, and in-memory DataFrame. Save your notebook before toggling the accelerator; there is no undo that preserves the current session state.
Verify the GPU is attached
Run the following in a notebook cell. It works for PyTorch installations, which Kaggle typically includes.
import torch
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("Device:", torch.cuda.get_device_name(0))
else:
print("No GPU detected; the notebook is still running on CPU.")
You can also run the NVIDIA system management interface directly from a cell:
!nvidia-smi
Where to run: any code cell in the Kaggle Notebook. Permissions: none beyond a standard Kaggle account. Expected check: torch.cuda.is_available() prints True and nvidia-smi prints a table with the GPU name and memory. Risk: if the kernel did not restart after you toggled the setting, both checks report CPU only even though the UI says GPU.
How the accelerator works
Kaggle provisions a container and passes an NVIDIA GPU device into it. When you select GPU and restart the kernel, the Python process starts with CUDA visible, so libraries such as PyTorch or TensorFlow can allocate tensors on the device instead of system RAM. The notebook still runs in the same browser tab; only the backend compute device changes.
Limits and common mistakes
Kaggle commonly documents the following boundaries. Because quotas can change, verify current values on your account Usage page before starting a long job.
| Limit | Practical check |
|---|---|
| Maximum 9 hours of continuous runtime per session | Watch the session timer. Save model checkpoints to /kaggle/working well before the limit. |
| 5 GB of persistent notebook storage | Keep raw datasets in Kaggle Datasets or fetch from external URLs; use /kaggle/working only for outputs and checkpoints. |
| Approximately 100 GPU compute hours per week | Open Account > Usage and review remaining GPU hours. |
| One GPU per notebook instance | Do not expect multiple simultaneous GPU notebooks to add capacity; they may contend for the same allocation. |
Mistakes that waste the GPU session
- Not restarting the kernel. Toggling the UI is not enough; the running Python process must restart to see CUDA.
- Storing large files in the notebook. The 5 GB limit fills quickly with raw CSV or image folders. Load data from Kaggle Datasets or stream it from an external source.
- Assuming the GPU persists after you close the tab. When the session ends, the container is reclaimed. You must re-enable GPU in the next notebook session.
- Ignoring the weekly quota. A long grid search can consume the weekly allowance and trigger an automatic shutdown, losing unsaved in-memory work.
Rollback and state loss
Because selecting GPU restarts the kernel, the only rollback is to switch the accelerator back to None or CPU and restart again. That restores CPU execution but does not recover variables lost during the first restart. Re-run your setup cells after any hardware change.
Verification checklist
- Settings shows GPU under Hardware accelerator.
- A cell containing !nvidia-smi returns a device table rather than a command not found error.
- torch.cuda.is_available() returns True.
- The Usage page shows GPU hours remaining for the week.
If the checks fail, restart the kernel manually from the notebook menu and re-run the verification cell before starting training. GPU allocation is not guaranteed if the weekly quota is exhausted or if the platform is under heavy contention.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.