Google Colab · Crashes · Stability
Why does my Google Colab session keep crashing? (and how to fix it)
“Colab crashed again” is one of the most common complaints from ML students. Sometimes it’s Colab’s limits, sometimes it’s your code. Let’s separate both and make your sessions more stable.
Common reasons Colab crashes
- Running out of RAM or GPU memory.
- Infinite loops or runaway processes in your code.
- Very heavy visualizations (huge heatmaps, pairplots, etc.).
- Idle timeouts (you left the notebook open for hours).
- Unstable experimental features / extensions.
1. Out of RAM (CPU memory)
Colab will silently kill your kernel if you exceed the RAM limit. Check the RAM meter in the top-right, or run:
import psutil
print(psutil.virtual_memory())
If your data is huge (millions of rows, many columns), use:
- Sampling (load first 50k rows).
- Chunking (process 100k rows at a time).
- Dropping unused columns.
2. Out of GPU memory
For deep learning models, “crash” might be a silent GPU out-of-memory. You’ll often see
CUDA out of memory first, then kernel death.
Fixes:
- Reduce batch size.
- Use smaller models or fewer layers.
- Clear GPU memory between runs (restart runtime if needed).
3. Infinite loops or runaway processes
A bug like while True: without a break can freeze your session.
If a cell hangs for a very long time, interrupt it with the stop button, fix the code, and re-run.
4. Heavy visualizations
Visualizing huge matrices (correlations, attention maps, etc.) can use massive memory. Use:
- Smaller samples.
- Aggregate statistics instead of full heatmaps.
- Limit figure resolution.
5. Idle timeouts & daily limits
Free Colab disconnects idle sessions and has usage limits. There is no way to completely disable this. You can:
- Save models & important artifacts to Drive regularly.
- Use checkpoints or periodic saves during long training.
- Consider Colab Pro if you need more stable sessions.
Make Colab crashes less scary with NoteCapsule
Crashes are frustrating when they happen right before a deadline and you aren’t sure how to reconstruct your working notebook. NoteCapsule helps by capturing a complete snapshot of your project.
!pip install "git+https://github.com/YOUR_GITHUB_USERNAME/notecapsule.git@main"
from notecapsule import create_capsule
create_capsule(
name="pre-experiments-stable",
notebook_path="notebook.ipynb",
data_dirs=["./"],
base_dir="."
)
If a crash or bad refactor breaks everything, you still have a Capsule containing the working notebook,
environment snapshot, and data manifest.