Spaces:
Paused
Paused
Commit ·
9536a33
1
Parent(s): bcc27a5
training/train_grpo.ipynb: add Kaggle (/kaggle/working) fresh-clone branch
Browse files- training/train_grpo.ipynb +24 -17
training/train_grpo.ipynb
CHANGED
|
@@ -42,7 +42,7 @@
|
|
| 42 |
"cell_type": "code",
|
| 43 |
"metadata": {},
|
| 44 |
"source": [
|
| 45 |
-
"# Cell 2: Resolve repo path (Colab: fresh clone. Local: auto-detect project root)\n",
|
| 46 |
"import os\n",
|
| 47 |
"import sys\n",
|
| 48 |
"import shutil\n",
|
|
@@ -52,6 +52,7 @@
|
|
| 52 |
"REPO_BRANCH = \"main\"\n",
|
| 53 |
"REPO_URL = \"https://github.com/VaibhavKhandare/viral-posts-env.git\"\n",
|
| 54 |
"COLAB_REPO = Path(\"/content/viral-posts-env\")\n",
|
|
|
|
| 55 |
"\n",
|
| 56 |
"\n",
|
| 57 |
"def _is_repo_root(p: Path) -> bool:\n",
|
|
@@ -64,33 +65,39 @@
|
|
| 64 |
" if _is_repo_root(cand):\n",
|
| 65 |
" return cand\n",
|
| 66 |
" raise FileNotFoundError(\n",
|
| 67 |
-
" \"Could not find project root. cd into viral-posts-env or run this notebook in Google Colab.\"\n",
|
| 68 |
" )\n",
|
| 69 |
"\n",
|
| 70 |
"\n",
|
| 71 |
-
"
|
| 72 |
-
"if
|
| 73 |
-
"
|
| 74 |
-
"
|
| 75 |
" p = subprocess.run(\n",
|
| 76 |
-
" [\n",
|
| 77 |
-
"
|
| 78 |
-
" REPO_URL, str(COLAB_REPO),\n",
|
| 79 |
-
" ],\n",
|
| 80 |
-
" capture_output=True,\n",
|
| 81 |
-
" text=True,\n",
|
| 82 |
" )\n",
|
| 83 |
" if p.returncode != 0:\n",
|
| 84 |
" raise RuntimeError(\n",
|
| 85 |
-
" \"git clone failed.
|
| 86 |
" f\"stdout:\\n{p.stdout}\\nstderr:\\n{p.stderr}\"\n",
|
| 87 |
" )\n",
|
| 88 |
-
" if not
|
| 89 |
-
" raise FileNotFoundError(f\"Clone did not create {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
" os.chdir(COLAB_REPO)\n",
|
| 91 |
" print(\"Mode: Colab (fresh clone)\")\n",
|
| 92 |
"else:\n",
|
| 93 |
-
" # --- Local machine: do not use /content ---\n",
|
| 94 |
" root = _find_local_root()\n",
|
| 95 |
" os.chdir(root)\n",
|
| 96 |
" print(\"Mode: local\")\n",
|
|
@@ -1255,7 +1262,7 @@
|
|
| 1255 |
"name": "python",
|
| 1256 |
"nbconvert_exporter": "python",
|
| 1257 |
"pygments_lexer": "ipython3",
|
| 1258 |
-
"version": "3.
|
| 1259 |
}
|
| 1260 |
},
|
| 1261 |
"nbformat": 4,
|
|
|
|
| 42 |
"cell_type": "code",
|
| 43 |
"metadata": {},
|
| 44 |
"source": [
|
| 45 |
+
"# Cell 2: Resolve repo path (Colab / Kaggle: fresh clone. Local: auto-detect project root)\n",
|
| 46 |
"import os\n",
|
| 47 |
"import sys\n",
|
| 48 |
"import shutil\n",
|
|
|
|
| 52 |
"REPO_BRANCH = \"main\"\n",
|
| 53 |
"REPO_URL = \"https://github.com/VaibhavKhandare/viral-posts-env.git\"\n",
|
| 54 |
"COLAB_REPO = Path(\"/content/viral-posts-env\")\n",
|
| 55 |
+
"KAGGLE_REPO = Path(\"/kaggle/working/viral-posts-env\")\n",
|
| 56 |
"\n",
|
| 57 |
"\n",
|
| 58 |
"def _is_repo_root(p: Path) -> bool:\n",
|
|
|
|
| 65 |
" if _is_repo_root(cand):\n",
|
| 66 |
" return cand\n",
|
| 67 |
" raise FileNotFoundError(\n",
|
| 68 |
+
" \"Could not find project root. cd into viral-posts-env or run this notebook in Google Colab/Kaggle.\"\n",
|
| 69 |
" )\n",
|
| 70 |
"\n",
|
| 71 |
"\n",
|
| 72 |
+
"def _fresh_clone(target: Path) -> None:\n",
|
| 73 |
+
" if target.exists():\n",
|
| 74 |
+
" shutil.rmtree(target, ignore_errors=True)\n",
|
| 75 |
+
" target.parent.mkdir(parents=True, exist_ok=True)\n",
|
| 76 |
" p = subprocess.run(\n",
|
| 77 |
+
" [\"git\", \"clone\", \"--branch\", REPO_BRANCH, \"--depth\", \"1\", REPO_URL, str(target)],\n",
|
| 78 |
+
" capture_output=True, text=True,\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
" )\n",
|
| 80 |
" if p.returncode != 0:\n",
|
| 81 |
" raise RuntimeError(\n",
|
| 82 |
+
" \"git clone failed. On Kaggle, enable Internet in the notebook settings panel.\\n\"\n",
|
| 83 |
" f\"stdout:\\n{p.stdout}\\nstderr:\\n{p.stderr}\"\n",
|
| 84 |
" )\n",
|
| 85 |
+
" if not target.is_dir():\n",
|
| 86 |
+
" raise FileNotFoundError(f\"Clone did not create {target}\")\n",
|
| 87 |
+
"\n",
|
| 88 |
+
"\n",
|
| 89 |
+
"_IS_KAGGLE = bool(os.environ.get(\"KAGGLE_KERNEL_RUN_TYPE\")) or Path(\"/kaggle/working\").is_dir()\n",
|
| 90 |
+
"_IS_COLAB = (not _IS_KAGGLE) and Path(\"/content\").is_dir()\n",
|
| 91 |
+
"\n",
|
| 92 |
+
"if _IS_KAGGLE:\n",
|
| 93 |
+
" _fresh_clone(KAGGLE_REPO)\n",
|
| 94 |
+
" os.chdir(KAGGLE_REPO)\n",
|
| 95 |
+
" print(\"Mode: Kaggle (fresh clone)\")\n",
|
| 96 |
+
"elif _IS_COLAB:\n",
|
| 97 |
+
" _fresh_clone(COLAB_REPO)\n",
|
| 98 |
" os.chdir(COLAB_REPO)\n",
|
| 99 |
" print(\"Mode: Colab (fresh clone)\")\n",
|
| 100 |
"else:\n",
|
|
|
|
| 101 |
" root = _find_local_root()\n",
|
| 102 |
" os.chdir(root)\n",
|
| 103 |
" print(\"Mode: local\")\n",
|
|
|
|
| 1262 |
"name": "python",
|
| 1263 |
"nbconvert_exporter": "python",
|
| 1264 |
"pygments_lexer": "ipython3",
|
| 1265 |
+
"version": "3.14.2"
|
| 1266 |
}
|
| 1267 |
},
|
| 1268 |
"nbformat": 4,
|