Upload folder using huggingface_hub
Browse files- configs/verifier_v_7b.yaml +16 -10
- src/mathcompose/train/train.py +10 -1
- src/mathcompose/train/train_7b.ipynb +136 -0
configs/verifier_v_7b.yaml
CHANGED
|
@@ -1,27 +1,33 @@
|
|
| 1 |
-
# Model V on the 7B-Math base —
|
| 2 |
-
#
|
| 3 |
-
#
|
| 4 |
-
#
|
| 5 |
-
#
|
| 6 |
extends: "base.yaml"
|
| 7 |
|
| 8 |
task: "v"
|
| 9 |
output_dir: "runs/verifier_v_7b"
|
| 10 |
-
hub_model_id: null # e.g. "42e/mathcompose-verifier-7b"
|
| 11 |
|
| 12 |
model:
|
| 13 |
base_id: "Qwen/Qwen2.5-Math-7B-Instruct"
|
| 14 |
max_context: 4096
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
data:
|
| 17 |
-
train_path: "data/verifier/train.jsonl" #
|
| 18 |
val_path: "data/verifier/val.jsonl"
|
| 19 |
|
| 20 |
train:
|
| 21 |
max_length: 4096
|
| 22 |
-
per_device_train_batch_size:
|
| 23 |
-
gradient_accumulation_steps:
|
| 24 |
-
gradient_checkpointing: true
|
|
|
|
|
|
|
| 25 |
|
| 26 |
eval:
|
| 27 |
processbench_splits: ["gsm8k", "math", "olympiadbench", "omnimath"]
|
|
|
|
| 1 |
+
# Model V on the 7B-Math base — tuned to USE the 80GB A100 (fast).
|
| 2 |
+
# Run with --gpu-preset none so these settings apply (not the 1.5B preset), and
|
| 3 |
+
# --push so the adapter lands on the Hub (Colab storage is ephemeral):
|
| 4 |
+
# python -m mathcompose.train.train --task v --config configs/verifier_v_7b.yaml \
|
| 5 |
+
# --gpu-preset none --push --hub-model-id <you>/mathcompose-verifier-7b
|
| 6 |
extends: "base.yaml"
|
| 7 |
|
| 8 |
task: "v"
|
| 9 |
output_dir: "runs/verifier_v_7b"
|
| 10 |
+
hub_model_id: null # set via --hub-model-id, e.g. "42e/mathcompose-verifier-7b"
|
| 11 |
|
| 12 |
model:
|
| 13 |
base_id: "Qwen/Qwen2.5-Math-7B-Instruct"
|
| 14 |
max_context: 4096
|
| 15 |
|
| 16 |
+
quant:
|
| 17 |
+
load_in_4bit: false # bf16 LoRA on the 80GB A100: faster than 4-bit (no dequant),
|
| 18 |
+
# and actually uses the VRAM (14GB weights vs ~4.5GB in 4-bit)
|
| 19 |
+
|
| 20 |
data:
|
| 21 |
+
train_path: "data/verifier/train.jsonl" # v2 genuine-detection data
|
| 22 |
val_path: "data/verifier/val.jsonl"
|
| 23 |
|
| 24 |
train:
|
| 25 |
max_length: 4096
|
| 26 |
+
per_device_train_batch_size: 16 # up from 4: ~4x fewer forward passes -> much faster
|
| 27 |
+
gradient_accumulation_steps: 1 # eff batch 16
|
| 28 |
+
gradient_checkpointing: true # keep on (no-ckpt @ seq 4096 OOMs even the 1.5B)
|
| 29 |
+
# ~35GB VRAM at these settings. To use more / go faster: raise batch to 24 or 32
|
| 30 |
+
# (fits 80GB). NOTE: training has no auto-OOM-recovery — if it OOMs, lower it.
|
| 31 |
|
| 32 |
eval:
|
| 33 |
processbench_splits: ["gsm8k", "math", "olympiadbench", "omnimath"]
|
src/mathcompose/train/train.py
CHANGED
|
@@ -78,6 +78,10 @@ def build_and_train(args) -> str:
|
|
| 78 |
# reduce fragmentation OOMs (set before CUDA initializes)
|
| 79 |
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 80 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
from datasets import load_dataset
|
| 82 |
from transformers import AutoModelForCausalLM
|
| 83 |
from trl import SFTConfig, SFTTrainer
|
|
@@ -214,8 +218,13 @@ def build_and_train(args) -> str:
|
|
| 214 |
|
| 215 |
hub_id = args.hub_model_id or cfg.get("hub_model_id")
|
| 216 |
if args.push and hub_id:
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
| 218 |
print(f"Pushed adapter to https://huggingface.co/{hub_id}")
|
|
|
|
|
|
|
| 219 |
|
| 220 |
print(f"Saved adapter to {output_dir}")
|
| 221 |
return output_dir
|
|
|
|
| 78 |
# reduce fragmentation OOMs (set before CUDA initializes)
|
| 79 |
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 80 |
import torch
|
| 81 |
+
|
| 82 |
+
if torch.cuda.is_available():
|
| 83 |
+
torch.backends.cuda.matmul.allow_tf32 = True # free ~1.3x matmul speedup on A100+
|
| 84 |
+
torch.backends.cudnn.allow_tf32 = True
|
| 85 |
from datasets import load_dataset
|
| 86 |
from transformers import AutoModelForCausalLM
|
| 87 |
from trl import SFTConfig, SFTTrainer
|
|
|
|
| 218 |
|
| 219 |
hub_id = args.hub_model_id or cfg.get("hub_model_id")
|
| 220 |
if args.push and hub_id:
|
| 221 |
+
from huggingface_hub import HfApi, create_repo
|
| 222 |
+
|
| 223 |
+
create_repo(hub_id, exist_ok=True)
|
| 224 |
+
HfApi().upload_folder(folder_path=output_dir, repo_id=hub_id, repo_type="model")
|
| 225 |
print(f"Pushed adapter to https://huggingface.co/{hub_id}")
|
| 226 |
+
elif args.push and not hub_id:
|
| 227 |
+
print("[warn] --push given but no --hub-model-id; adapter saved locally only.")
|
| 228 |
|
| 229 |
print(f"Saved adapter to {output_dir}")
|
| 230 |
return output_dir
|
src/mathcompose/train/train_7b.ipynb
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# mathcompose \u2014 train the **7B** verifier (Colab A100)\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"Everything baked in: bf16 LoRA (uses the VRAM, faster than 4-bit), batch 16 + TF32,\n",
|
| 10 |
+
"**auto-push** so the adapter can't get lost, base-inferred eval, and the code-exec probe.\n",
|
| 11 |
+
"**Runtime \u2192 A100 GPU** first. Expect ~35 GB VRAM (vs <8 before); raise batch in the\n",
|
| 12 |
+
"config to 24/32 to use more."
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"execution_count": null,
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"source": [
|
| 21 |
+
"# 1. GPU deps + drop Colab's incompatible torchao\n",
|
| 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\n",
|
| 24 |
+
"!pip -q uninstall -y torchao 2>/dev/null; echo done"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "code",
|
| 29 |
+
"metadata": {},
|
| 30 |
+
"execution_count": null,
|
| 31 |
+
"outputs": [],
|
| 32 |
+
"source": [
|
| 33 |
+
"# 2. Token -> pull code+data -> install (cwd = the snapshot, which has data/verifier)\n",
|
| 34 |
+
"import os\n",
|
| 35 |
+
"from huggingface_hub import HfApi, snapshot_download, login\n",
|
| 36 |
+
"os.environ[\"HF_TOKEN\"] = \"hf_xxx\" # paste, or Colab Secrets\n",
|
| 37 |
+
"login(os.environ[\"HF_TOKEN\"])\n",
|
| 38 |
+
"USER = HfApi().whoami()[\"name\"]\n",
|
| 39 |
+
"proj = snapshot_download(f\"{USER}/mathcompose\", repo_type=\"model\")\n",
|
| 40 |
+
"%cd {proj}\n",
|
| 41 |
+
"!pip -q install -e .\n",
|
| 42 |
+
"print(\"data:\", os.listdir(\"data/verifier\"))"
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"cell_type": "code",
|
| 47 |
+
"metadata": {},
|
| 48 |
+
"execution_count": null,
|
| 49 |
+
"outputs": [],
|
| 50 |
+
"source": [
|
| 51 |
+
"# 3. Confirm A100\n",
|
| 52 |
+
"import torch; print(torch.cuda.get_device_name(0), f\"{torch.cuda.get_device_properties(0).total_memory/1e9:.0f}GB\")"
|
| 53 |
+
]
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"cell_type": "markdown",
|
| 57 |
+
"metadata": {},
|
| 58 |
+
"source": [
|
| 59 |
+
"## 4. Train the 7B verifier (bf16 LoRA, batch 16, TF32) with auto-push\n",
|
| 60 |
+
"~1\u20131.5 hr on the A100. You should see `[gpu] ... compute=bf16`, `[train] ... batch=16`,\n",
|
| 61 |
+
"and VRAM climb to ~35 GB. The adapter is pushed to `{USER}/mathcompose-verifier-7b`\n",
|
| 62 |
+
"at the end so it survives the session."
|
| 63 |
+
]
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"cell_type": "code",
|
| 67 |
+
"metadata": {},
|
| 68 |
+
"execution_count": null,
|
| 69 |
+
"outputs": [],
|
| 70 |
+
"source": [
|
| 71 |
+
"!python -m mathcompose.train.train --task v --config configs/verifier_v_7b.yaml \\\n",
|
| 72 |
+
" --gpu-preset none --push --hub-model-id {USER}/mathcompose-verifier-7b"
|
| 73 |
+
]
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"cell_type": "markdown",
|
| 77 |
+
"metadata": {},
|
| 78 |
+
"source": [
|
| 79 |
+
"### Want to use even more VRAM / go faster?\n",
|
| 80 |
+
"Add `--batch-size 24` (or `32`) to the command above \u2014 both fit 80 GB. Training has\n",
|
| 81 |
+
"no auto-OOM-recovery, so if it OOMs, drop it back down."
|
| 82 |
+
]
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"cell_type": "markdown",
|
| 86 |
+
"metadata": {},
|
| 87 |
+
"source": [
|
| 88 |
+
"## 5. Eval: 7B base vs tuned (base auto-inferred from the adapter)"
|
| 89 |
+
]
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"cell_type": "code",
|
| 93 |
+
"metadata": {},
|
| 94 |
+
"execution_count": null,
|
| 95 |
+
"outputs": [],
|
| 96 |
+
"source": [
|
| 97 |
+
"!python -m mathcompose.eval.run --base-id Qwen/Qwen2.5-Math-7B-Instruct processbench --tag base_7b --maj-k 1 --limit 100\n",
|
| 98 |
+
"!python -m mathcompose.eval.run --adapter {USER}/mathcompose-verifier-7b --tag tuned_7b --maj-k 1 --limit 100\n",
|
| 99 |
+
"!python -m mathcompose.eval.run report"
|
| 100 |
+
]
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"cell_type": "markdown",
|
| 104 |
+
"metadata": {},
|
| 105 |
+
"source": [
|
| 106 |
+
"## 6. M1c probe \u2014 does code execution close the arithmetic gap?\n",
|
| 107 |
+
"Per-example tool loop (slower) \u2192 small limit. gsm8k is the arithmetic split where it helps most."
|
| 108 |
+
]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"cell_type": "code",
|
| 112 |
+
"metadata": {},
|
| 113 |
+
"execution_count": null,
|
| 114 |
+
"outputs": [],
|
| 115 |
+
"source": [
|
| 116 |
+
"!python -m mathcompose.eval.run --adapter {USER}/mathcompose-verifier-7b --tag tuned7b_codeexec --code-exec --limit 40 --splits gsm8k math\n",
|
| 117 |
+
"!python -m mathcompose.eval.run --base-id Qwen/Qwen2.5-Math-7B-Instruct processbench --tag base7b_codeexec --code-exec --limit 40 --splits gsm8k math"
|
| 118 |
+
]
|
| 119 |
+
}
|
| 120 |
+
],
|
| 121 |
+
"metadata": {
|
| 122 |
+
"accelerator": "GPU",
|
| 123 |
+
"colab": {
|
| 124 |
+
"provenance": []
|
| 125 |
+
},
|
| 126 |
+
"kernelspec": {
|
| 127 |
+
"display_name": "Python 3",
|
| 128 |
+
"name": "python3"
|
| 129 |
+
},
|
| 130 |
+
"language_info": {
|
| 131 |
+
"name": "python"
|
| 132 |
+
}
|
| 133 |
+
},
|
| 134 |
+
"nbformat": 4,
|
| 135 |
+
"nbformat_minor": 0
|
| 136 |
+
}
|