Upload folder using huggingface_hub
Browse files
src/mathcompose/train/colab_train.ipynb
CHANGED
|
@@ -7,9 +7,7 @@
|
|
| 7 |
"# mathcompose \u2014 QLoRA training on Colab (free T4)\n",
|
| 8 |
"\n",
|
| 9 |
"Pulls the code **and** the Model-V dataset from HF Hub with just your token \u2014 no\n",
|
| 10 |
-
"GitHub needed
|
| 11 |
-
"\n",
|
| 12 |
-
"**Runtime \u2192 Change runtime type \u2192 T4 GPU** before running."
|
| 13 |
]
|
| 14 |
},
|
| 15 |
{
|
|
@@ -18,7 +16,7 @@
|
|
| 18 |
"execution_count": null,
|
| 19 |
"outputs": [],
|
| 20 |
"source": [
|
| 21 |
-
"# 1. GPU deps (
|
| 22 |
"!pip -q install \"transformers>=5.13,<6\" \"trl>=1.7,<2\" \"peft>=0.19,<0.20\" \\\n",
|
| 23 |
" \"accelerate>=1.14\" \"datasets>=5.0\" \"huggingface_hub>=1.22\" sympy bitsandbytes"
|
| 24 |
]
|
|
@@ -32,11 +30,10 @@
|
|
| 32 |
"# 2. Token -> pull the code+data snapshot -> install\n",
|
| 33 |
"import os\n",
|
| 34 |
"from huggingface_hub import HfApi, snapshot_download, login\n",
|
| 35 |
-
"os.environ[\"HF_TOKEN\"] = \"hf_xxx\" # paste, or
|
| 36 |
"login(os.environ[\"HF_TOKEN\"])\n",
|
| 37 |
"USER = HfApi().whoami()[\"name\"]\n",
|
| 38 |
-
"
|
| 39 |
-
"proj = snapshot_download(CODE_REPO, repo_type=\"model\")\n",
|
| 40 |
"%cd {proj}\n",
|
| 41 |
"!pip -q install -e .\n",
|
| 42 |
"print(\"project at\", proj, \"| data:\", os.listdir(\"data/verifier\"))"
|
|
@@ -48,7 +45,7 @@
|
|
| 48 |
"execution_count": null,
|
| 49 |
"outputs": [],
|
| 50 |
"source": [
|
| 51 |
-
"# 3.
|
| 52 |
"import torch; print(\"CUDA:\", torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"\")"
|
| 53 |
]
|
| 54 |
},
|
|
@@ -72,8 +69,8 @@
|
|
| 72 |
"cell_type": "markdown",
|
| 73 |
"metadata": {},
|
| 74 |
"source": [
|
| 75 |
-
"## 5. Eval V on ProcessBench \u2014 base vs tuned (Maj@8
|
| 76 |
-
"
|
| 77 |
]
|
| 78 |
},
|
| 79 |
{
|
|
@@ -85,14 +82,14 @@
|
|
| 85 |
"!python -m mathcompose.eval.run processbench --tag base --maj-k 1 --limit 200\n",
|
| 86 |
"!python -m mathcompose.eval.run processbench --adapter runs/verifier_v --tag tuned --maj-k 8 --limit 200\n",
|
| 87 |
"!python -m mathcompose.eval.run prmbench --adapter runs/verifier_v --tag tuned --limit 300\n",
|
| 88 |
-
"!python -m mathcompose.eval.run report
|
| 89 |
]
|
| 90 |
},
|
| 91 |
{
|
| 92 |
"cell_type": "markdown",
|
| 93 |
"metadata": {},
|
| 94 |
"source": [
|
| 95 |
-
"## 6. Push the trained V adapter
|
| 96 |
]
|
| 97 |
},
|
| 98 |
{
|
|
@@ -101,8 +98,11 @@
|
|
| 101 |
"execution_count": null,
|
| 102 |
"outputs": [],
|
| 103 |
"source": [
|
| 104 |
-
"
|
| 105 |
-
"
|
|
|
|
|
|
|
|
|
|
| 106 |
]
|
| 107 |
},
|
| 108 |
{
|
|
@@ -110,8 +110,8 @@
|
|
| 110 |
"metadata": {},
|
| 111 |
"source": [
|
| 112 |
"## 7. (Later) Model G + the composition\n",
|
| 113 |
-
"
|
| 114 |
-
"
|
| 115 |
]
|
| 116 |
},
|
| 117 |
{
|
|
@@ -121,7 +121,6 @@
|
|
| 121 |
"outputs": [],
|
| 122 |
"source": [
|
| 123 |
"# !python -m mathcompose.train.train --task g --config configs/generator_g.yaml\n",
|
| 124 |
-
"# !python -m mathcompose.eval.run math --adapter runs/generator_g --tag tuned --limit 200\n",
|
| 125 |
"# !python -m mathcompose.eval.run compose --gen-adapter runs/generator_g --ver-adapter runs/verifier_v \\\n",
|
| 126 |
"# --dataset Maxwell-Jia/AIME_2024 --split train --problem-field Problem --answer-field Answer"
|
| 127 |
]
|
|
|
|
| 7 |
"# mathcompose \u2014 QLoRA training on Colab (free T4)\n",
|
| 8 |
"\n",
|
| 9 |
"Pulls the code **and** the Model-V dataset from HF Hub with just your token \u2014 no\n",
|
| 10 |
+
"GitHub needed. **Runtime \u2192 Change runtime type \u2192 T4 GPU** before running."
|
|
|
|
|
|
|
| 11 |
]
|
| 12 |
},
|
| 13 |
{
|
|
|
|
| 16 |
"execution_count": null,
|
| 17 |
"outputs": [],
|
| 18 |
"source": [
|
| 19 |
+
"# 1. GPU deps (versions this project was built against) + 4-bit kernels\n",
|
| 20 |
"!pip -q install \"transformers>=5.13,<6\" \"trl>=1.7,<2\" \"peft>=0.19,<0.20\" \\\n",
|
| 21 |
" \"accelerate>=1.14\" \"datasets>=5.0\" \"huggingface_hub>=1.22\" sympy bitsandbytes"
|
| 22 |
]
|
|
|
|
| 30 |
"# 2. Token -> pull the code+data snapshot -> install\n",
|
| 31 |
"import os\n",
|
| 32 |
"from huggingface_hub import HfApi, snapshot_download, login\n",
|
| 33 |
+
"os.environ[\"HF_TOKEN\"] = \"hf_xxx\" # paste, or Colab Secrets: userdata.get('HF_TOKEN')\n",
|
| 34 |
"login(os.environ[\"HF_TOKEN\"])\n",
|
| 35 |
"USER = HfApi().whoami()[\"name\"]\n",
|
| 36 |
+
"proj = snapshot_download(f\"{USER}/mathcompose\", repo_type=\"model\")\n",
|
|
|
|
| 37 |
"%cd {proj}\n",
|
| 38 |
"!pip -q install -e .\n",
|
| 39 |
"print(\"project at\", proj, \"| data:\", os.listdir(\"data/verifier\"))"
|
|
|
|
| 45 |
"execution_count": null,
|
| 46 |
"outputs": [],
|
| 47 |
"source": [
|
| 48 |
+
"# 3. GPU present?\n",
|
| 49 |
"import torch; print(\"CUDA:\", torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"\")"
|
| 50 |
]
|
| 51 |
},
|
|
|
|
| 69 |
"cell_type": "markdown",
|
| 70 |
"metadata": {},
|
| 71 |
"source": [
|
| 72 |
+
"## 5. Eval V on ProcessBench \u2014 base vs tuned (Maj@8) + PRMBench\n",
|
| 73 |
+
"Use `--limit` for a fast read; drop it for the full 3,400-example score."
|
| 74 |
]
|
| 75 |
},
|
| 76 |
{
|
|
|
|
| 82 |
"!python -m mathcompose.eval.run processbench --tag base --maj-k 1 --limit 200\n",
|
| 83 |
"!python -m mathcompose.eval.run processbench --adapter runs/verifier_v --tag tuned --maj-k 8 --limit 200\n",
|
| 84 |
"!python -m mathcompose.eval.run prmbench --adapter runs/verifier_v --tag tuned --limit 300\n",
|
| 85 |
+
"!python -m mathcompose.eval.run report"
|
| 86 |
]
|
| 87 |
},
|
| 88 |
{
|
| 89 |
"cell_type": "markdown",
|
| 90 |
"metadata": {},
|
| 91 |
"source": [
|
| 92 |
+
"## 6. Push the trained V adapter (no retrain) \u2014 deliverable #2"
|
| 93 |
]
|
| 94 |
},
|
| 95 |
{
|
|
|
|
| 98 |
"execution_count": null,
|
| 99 |
"outputs": [],
|
| 100 |
"source": [
|
| 101 |
+
"from huggingface_hub import HfApi, create_repo\n",
|
| 102 |
+
"MODEL_REPO = f\"{USER}/mathcompose-verifier-1.5b\"\n",
|
| 103 |
+
"create_repo(MODEL_REPO, exist_ok=True)\n",
|
| 104 |
+
"HfApi().upload_folder(folder_path=\"runs/verifier_v\", repo_id=MODEL_REPO, repo_type=\"model\")\n",
|
| 105 |
+
"print(\"pushed ->\", f\"https://huggingface.co/{MODEL_REPO}\")"
|
| 106 |
]
|
| 107 |
},
|
| 108 |
{
|
|
|
|
| 110 |
"metadata": {},
|
| 111 |
"source": [
|
| 112 |
"## 7. (Later) Model G + the composition\n",
|
| 113 |
+
"Build G's dataset (teacher=claude-opus-4-8), train, then run V-reranks-G \u2014 the\n",
|
| 114 |
+
"headline generator-verifier-gap number."
|
| 115 |
]
|
| 116 |
},
|
| 117 |
{
|
|
|
|
| 121 |
"outputs": [],
|
| 122 |
"source": [
|
| 123 |
"# !python -m mathcompose.train.train --task g --config configs/generator_g.yaml\n",
|
|
|
|
| 124 |
"# !python -m mathcompose.eval.run compose --gen-adapter runs/generator_g --ver-adapter runs/verifier_v \\\n",
|
| 125 |
"# --dataset Maxwell-Jia/AIME_2024 --split train --problem-field Problem --answer-field Answer"
|
| 126 |
]
|