#!/usr/bin/env bash
# Real demos for P191 "How to Fix Python CUDA Memory Errors in PyTorch".
# Mary's notebook, sent cell by cell to one real Google Colab T4 runtime with Google's colab CLI (~/.venvs/colab,
# signed in on the main Mac). lab/flowers.py (uploaded to the runtime) turns the Oxford 102 Flowers photos into
# tensors and caches them on the VM; lab/colab_lab.py runs the blocks in order, restarting the kernel between them
# as Runtime > Restart session would: prep (cache the photos, off screen), k1 (batch 256 crashes, batch 64 crashes too
# in the same kernel), k2 (a clean start, one epoch at 64, a check without no_grad that climbs and crashes), k3 (the
# check under no_grad), k4 (what one step keeps, peak per batch size), k5 (384-pixel photos crash at 64), k6 (batch
# 32, mixed precision, accumulation, checkpointing, then the real three-epoch run and the check). Every cell's code
# and output go to lab/raw_output.json; `colab_lab.py tidy` writes demo_output.json (an error kept as its last line).
# A block can be rerun alone: python3 lab/colab_lab.py k4 --resume
set -euo pipefail
cd "$(dirname "$0")"
python3 lab/colab_lab.py
