{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": "# Pocket Math runner\n\nOne click runs the next queued job for up to 12 hours, then saves everything to Hugging Face, so the next session (on any account) continues it.\n\n1. Settings (right panel): **Accelerator: GPU T4 x2**, **Internet: on**.\n2. Add-ons > Secrets: a secret named **HF_TOKEN** (your Hugging Face write token), attached.\n3. **Save Version > Save & Run All (Commit)**. You can close the tab.\n" }, { "cell_type": "code", "metadata": {}, "source": "JOB_ID = \"auto\" # leave as \"auto\": the session picks the next job in the queue\nOPS_REPO = \"Palaestra/pocket-math-ops\"\n", "outputs": [], "execution_count": null }, { "cell_type": "code", "metadata": {}, "source": "\"\"\"The only code in the Kaggle notebook. It never changes, so friends' copies never go stale.\n\nIt reads the HF token, downloads the current code from the ops repo on the Hub, and hands\nover to kaggle/session.py from that download. JOB_ID and OPS_REPO are the only settings.\n\"\"\"\n\n\nimport glob # noqa: E402\nimport os # noqa: E402\nimport subprocess # noqa: E402\nimport sys # noqa: E402\nimport time # noqa: E402\n\nos.environ[\"PM_SESSION_START\"] = str(time.time())\n\n\ndef _hf_token() -> str:\n try:\n from kaggle_secrets import UserSecretsClient\n\n return UserSecretsClient().get_secret(\"HF_TOKEN\")\n except Exception: # noqa: BLE001 - fall back to a private dataset (own-account script kernels)\n hits = glob.glob(\"/kaggle/input/**/hf_token\", recursive=True)\n if hits:\n return open(hits[0]).read().strip()\n return os.environ.get(\"HF_TOKEN\", \"\")\n\n\nos.environ[\"HF_TOKEN\"] = _hf_token()\nif not os.environ[\"HF_TOKEN\"]:\n raise SystemExit(\"No HF token. Add a Kaggle Secret named HF_TOKEN (Add-ons > Secrets) and attach it.\")\n\nfrom huggingface_hub import snapshot_download # noqa: E402\n\nroot = snapshot_download(OPS_REPO, repo_type=\"dataset\", allow_patterns=[\"code/**\"], local_dir=\"/tmp/pm-ops\",\n token=os.environ[\"HF_TOKEN\"])\nrc = subprocess.call([sys.executable, f\"{root}/code/kaggle/session.py\", \"--job\", JOB_ID, \"--ops-repo\", OPS_REPO])\nprint(f\"session finished (exit code {rc})\")\n", "outputs": [], "execution_count": null } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" }, "kaggle": { "accelerator": "nvidiaTeslaT4", "isInternetEnabled": true, "isGpuEnabled": true } }, "nbformat": 4, "nbformat_minor": 5 }