Getting Real Work Done in Kaggle Code Notebooks: GPU, Datasets, and Persistence
Learn how to reliably use Kaggle Code notebooks with GPU/TPU acceleration: verify devices, attach datasets, persist checkpoints to /kaggle/working, and work around the no‑internet restriction.
10 Jun 2026, 22:46 UTC

The problem: ephemeral compute with hard limits
Kaggle Code notebooks give you a free Jupyter environment with optional NVIDIA GPU or Google TPU acceleration, but the container is torn down when the session ends. Anything you write to the local filesystem disappears unless you explicitly push it to the /kaggle/working output directory or export a new notebook version. On top of that, free‑tier accounts have strict GPU/TPU hour quotas and no outbound internet access, so pip install from PyPI often fails.
1. Verify the accelerator before you start training
Open the notebook settings (gear icon → Accelerator) and pick GPU or TPU. Then run a quick device check in the first cell:
# Run in a notebook cell
import torch, os
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("Device name:", torch.cuda.get_device_name(0))
# Optional: show driver version
!nvidia-smi --query-gpu=driver_version --format=csv,noheader
else:
print("No GPU detected – check accelerator setting.")
Run the cell; you should see CUDA available: True and a device name such as Tesla P100. If it reports False, the accelerator wasn’t enabled or the quota is exhausted. The same pattern works for TPUs using torch_xla.
2. Attach datasets and know where they live
In the notebook sidebar click Add data → choose a public or private Kaggle dataset. Each dataset is mounted read‑only under /kaggle/input/<owner>/<dataset-name>/. List them to confirm:
!ls -la /kaggle/input/
Typical output shows one folder per attached dataset. Because the mount is read‑only, you cannot write preprocessing artifacts there; copy what you need to /kaggle/working first.
3. Persist model checkpoints and logs
The only durable location is /kaggle/working. Everything written here survives the session and becomes part of the notebook version when you click Save version. Example: saving a PyTorch checkpoint.
import torch
model = ... # your model definition
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
# Training loop (truncated)
for epoch in range(5):
# ... training step ...
pass
# Save checkpoint
ckpt_path = "/kaggle/working/model_epoch5.pt"
torch.save({
"epoch": 5,
"model_state_dict": model.state_dict(),
"optimizer_state_dict": optimizer.state_dict(),
}, ckpt_path)
print("Checkpoint saved to", ckpt_path)
After the run, open the Output tab – the file appears there. If you restart the notebook without saving a version, the file vanishes; the only way to keep it across sessions is to publish a new notebook version (or download it manually).
4. Working without outbound internet
Kaggle blocks external network calls in the free tier. Attempting !pip install some‑obscure‑package usually fails with a timeout. Two practical work‑arounds:
- Pre‑install via dataset: Create a private dataset that contains a
requirements.txtand the wheel files (.whl) you need. Attach it, then run!pip install --no-index --find-links /kaggle/input/my‑wheels -r /kaggle/input/my‑wheels/requirements.txt. - Use the built‑in library set: Kaggle pre‑loads recent versions of
torch,tensorflow,transformers,scikit‑learn, etc. Check the environment with!pip listbefore adding anything.
If you must install a package that is not pre‑loaded and you cannot bundle wheels, you’ll need a paid plan that lifts the internet restriction.
Trade‑off: quota vs. experiment length
Free accounts receive roughly 30 GPU‑hours and 20 TPU‑hours per month (numbers shift without notice). A single 5‑epoch run on a ResNet‑50 with batch size 64 can consume 1–2 GPU‑hours. Monitor usage in the account settings page (Settings → Usage) and consider:
- Reducing batch size or using mixed‑precision (
torch.cuda.amp) to stretch hours. - Running hyper‑parameter sweeps on CPU first, then moving only the best config to GPU.
Quick verification checklist before a long run
- Accelerator selected and device check prints
True. - Required datasets appear under
/kaggle/input. - All custom dependencies are either pre‑installed or bundled in an attached dataset.
- Output path
/kaggle/workingis used for every artifact you want to keep. - Quota dashboard shows enough remaining hours for the planned training time.
Following this checklist turns a fragile “run‑and‑hope” notebook into a reproducible experiment that survives session restarts and respects Kaggle’s constraints.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.