How to Use GPU in Kaggle: Step-by-Step Guide
In this article
To use a GPU in Kaggle, open your notebook, click the Settings panel on the right, and under Accelerator select GPU T4 x2 or GPU P100, then click Save. The GPU is allocated to your session immediately, and you can verify it by running !nvidia-smi in a code cell. That is the short answer. The rest of this guide covers the prerequisites, the exact steps, what to check when the option is missing, and how to avoid the most common pitfalls.
What You'll Need
- A free Kaggle account (sign in at kaggle.com).
- Phone verification completed on your Kaggle profile. Kaggle requires a verified phone number to unlock GPU and TPU accelerators; without it, the accelerator dropdown may show only CPU or be greyed out.
- A notebook (either a new one or an existing one you own) opened in the Kaggle Notebook editor.
- Basic familiarity with running a code cell (Shift+Enter).
Note: menu labels and the exact wording of the Settings panel can differ slightly by Kaggle version and by whether you are on the classic or new notebook editor. The steps below describe the current standard editor.
Step-by-Step
- Open or create a notebook. From the Kaggle homepage, click Create > Notebook, or open an existing notebook and click Edit.
- Open the Settings panel. In the notebook editor, look at the right-hand sidebar. If it is collapsed, click the gear or Settings icon to expand it. On smaller screens the panel may be behind a menu button.
- Find the Accelerator dropdown. Under the Settings section, locate Accelerator. It usually defaults to None (CPU only).
- Select a GPU option. Click the dropdown and choose GPU T4 x2 or GPU P100. Both are NVIDIA GPUs; T4 x2 gives you two T4 GPUs, while P100 gives one P100. Pick based on what your framework supports and what is available; if one is not listed, the other may be.
- Save the setting. Click Save (or the checkmark) if the panel requires it. Kaggle may briefly show a message that the session is restarting to apply the accelerator.
- Verify the GPU is active. In a new code cell, run:
You should see a table listing the GPU model, memory, and driver version. If you see "command not found" or no GPU listed, the accelerator did not attach; repeat step 4 and save again.!nvidia-smi - Check framework visibility (optional). For PyTorch, run
import torch; print(torch.cuda.is_available()). For TensorFlow, runimport tensorflow as tf; print(tf.config.list_physical_devices('GPU')). ATrueor a non-empty list confirms the GPU is usable. - Run your training code. Move tensors and models to the GPU as you normally would (e.g.,
.to('cuda')in PyTorch). The notebook session keeps the GPU until it times out or you stop it.
If the accelerator dropdown is missing or only shows CPU, the most common cause is an unverified phone number. Go to your Kaggle account settings, complete phone verification, then reload the notebook editor. Also note that GPU is not available in some notebook types or when you are viewing someone else's notebook without editing it.
Common Mistakes
- Forgetting to save the accelerator setting. Selecting GPU in the dropdown but not saving leaves the session on CPU. Always confirm with
!nvidia-smi. - Assuming a GPU is always available. Kaggle allocates GPUs on a quota basis; if you have used your weekly GPU hours, the option may be unavailable until the quota resets. The Settings panel usually shows remaining hours.
- Running out of GPU memory. T4 and P100 have limited memory (roughly 16 GB). Large batch sizes or models can trigger out-of-memory errors. Reduce batch size or use gradient accumulation.
- Leaving the session idle. Kaggle stops idle sessions after a period of inactivity, which frees the GPU. Save your work and use the commit feature if you need long runs.
- Expecting the GPU to persist across sessions. Each new session starts fresh; you must set the accelerator again unless you save it in the notebook's settings (Kaggle remembers the last accelerator for that notebook in many cases, but verify).
Tips
- Use
!nvidia-smiat the start of every session to confirm the GPU and check free memory. - Prefer T4 x2 if your code can use multiple GPUs (e.g., via
DataParallelorDistributedDataParallel); otherwise a single P100 may be simpler. - Keep an eye on your GPU quota in the Settings panel; plan heavy experiments accordingly.
- Use Kaggle's Save Version (commit) to run long training jobs in the background, which can use GPU without keeping the browser open.
- Clear GPU memory between experiments by restarting the session (Run > Restart) rather than letting tensors accumulate.
Troubleshooting
The Accelerator dropdown only shows CPU. Verify your phone number in account settings. If already verified, try a different browser or incognito mode, and ensure you are editing your own notebook, not viewing a read-only copy.
!nvidia-smi shows no GPU. The session may not have restarted after saving. Use Run > Restart (or the restart button) and run the command again. If it still fails, switch to the other GPU option and save.
Framework says CUDA is not available. Confirm you are using a GPU-enabled runtime (the accelerator is set) and that your code does not force CPU. In PyTorch, check torch.cuda.is_available(); in TensorFlow, check the physical devices list. If the GPU is present in nvidia-smi but not in the framework, the installed framework build may be CPU-only; Kaggle's preinstalled images normally include GPU builds, so a session restart usually resolves it.
Out-of-memory errors. Reduce batch size, use mixed precision, or free tensors with del and torch.cuda.empty_cache(). Restart the session to clear fragmented memory.
Quota exhausted. The Settings panel shows remaining GPU hours. Wait for the reset or use CPU for lighter tasks. There is no workaround to bypass the quota.
Frequently Asked Questions
Do I need to pay to use a GPU on Kaggle?
No. GPU accelerators are available on free Kaggle accounts, subject to a weekly quota. Verified phone number is required.
Can I use a GPU in Kaggle Kernels (notebooks) without phone verification?
No. Phone verification is required to unlock GPU and TPU options.
Which GPU should I choose, T4 x2 or P100?
Choose T4 x2 if your code can use two GPUs; otherwise P100 is a single, slightly faster GPU for many workloads. Availability varies, so pick whichever is listed.
Does the GPU stay attached when I close the browser?
The session continues running in the background for a while, but idle sessions are stopped. Use Save Version (commit) for long jobs.
Can I install my own CUDA version?
You can install packages with pip, but the base CUDA driver is fixed by Kaggle's environment. Most common frameworks are preinstalled and GPU-ready.
Why does my notebook show GPU but training is slow?
Check that your model and data are actually on the GPU (e.g., model.to('cuda')). Data loading from disk can also bottleneck; use num_workers in DataLoader where supported.