v1.5b: faz5_eval.py — faz5 checkpoints_350m namespace + torch.load weights_only=False (resume/eval hardening)
Browse files- code/kod/faz5_eval.py +19 -13
code/kod/faz5_eval.py
CHANGED
|
@@ -5,11 +5,13 @@ Faz 5 — SmartCore V1 eval baseline (STANDALONE / kendine yeten).
|
|
| 5 |
en yükseği seç → altın cevapla karşılaştır. acc=ham toplam, acc_norm=token-uzunluğa bölünmüş.
|
| 6 |
|
| 7 |
Model tanımı GÖMÜLÜ (faz3_train.py ile birebir) → hiçbir yerel import'a bağlı DEĞİL.
|
| 8 |
-
Ortam: Colab GPU + mamba-
|
| 9 |
|
| 10 |
-
Kullanım (
|
| 11 |
-
|
| 12 |
-
HF_TOKEN=hf_xxx python faz5_eval.py --tasks xcopa,belebele,hellaswag --limit
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
import os, sys, argparse
|
| 15 |
import torch, torch.nn as nn, torch.nn.functional as F
|
|
@@ -21,7 +23,7 @@ try:
|
|
| 21 |
from mamba_ssm.modules.mlp import GatedMLP
|
| 22 |
from mamba_ssm.ops.triton.layer_norm import RMSNorm
|
| 23 |
except Exception as e:
|
| 24 |
-
sys.exit(f"[hata] mamba-
|
| 25 |
|
| 26 |
|
| 27 |
# ───────────── model (faz3_train.py ile BİREBİR AYNI) ─────────────
|
|
@@ -123,20 +125,22 @@ def load_tok(token):
|
|
| 123 |
return sp
|
| 124 |
|
| 125 |
|
| 126 |
-
def latest_ckpt(token):
|
| 127 |
from huggingface_hub import HfApi, hf_hub_download
|
| 128 |
api = HfApi(token=token)
|
| 129 |
fs = [f for f in api.list_repo_files("kdirgul/smartcore-v1", repo_type="model")
|
| 130 |
-
if f.startswith("
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
print(f"[ckpt] {latest}", flush=True)
|
| 133 |
return hf_hub_download("kdirgul/smartcore-v1", latest, repo_type="model", token=token)
|
| 134 |
|
| 135 |
|
| 136 |
-
def resolve_ckpt(spec, token):
|
| 137 |
-
"""spec yoksa
|
| 138 |
if not spec:
|
| 139 |
-
return latest_ckpt(token)
|
| 140 |
if os.path.exists(spec):
|
| 141 |
return spec
|
| 142 |
from huggingface_hub import hf_hub_download
|
|
@@ -262,7 +266,9 @@ def main():
|
|
| 262 |
ap = argparse.ArgumentParser()
|
| 263 |
ap.add_argument("--tasks", default="xcopa,belebele,hellaswag")
|
| 264 |
ap.add_argument("--limit", type=int, default=200)
|
| 265 |
-
ap.add_argument("--ckpt", default=None, help="HF yolu (sft/epoch_2/ckpt.pt) | yerel .pt | boş=
|
|
|
|
|
|
|
| 266 |
args = ap.parse_args()
|
| 267 |
|
| 268 |
assert torch.cuda.is_available(), "CUDA yok (Colab GPU gerekir)."
|
|
@@ -271,7 +277,7 @@ def main():
|
|
| 271 |
token = os.environ.get("HF_TOKEN") or get_token()
|
| 272 |
|
| 273 |
sp = load_tok(token)
|
| 274 |
-
st = torch.load(resolve_ckpt(args.ckpt, token), map_location="cpu")
|
| 275 |
model = HybridLM(st["cfg"], device="cuda", dtype=torch.bfloat16)
|
| 276 |
model.load_state_dict(st["model"], strict=False); model.eval()
|
| 277 |
tag = f"sft/epoch={st.get('epoch')}" if st.get("sft") else f"base step={st.get('step','?')}"
|
|
|
|
| 5 |
en yükseği seç → altın cevapla karşılaştır. acc=ham toplam, acc_norm=token-uzunluğa bölünmüş.
|
| 6 |
|
| 7 |
Model tanımı GÖMÜLÜ (faz3_train.py ile birebir) → hiçbir yerel import'a bağlı DEĞİL.
|
| 8 |
+
Ortam: Colab GPU + resmî mamba-ssm (wheel-cache). Veri: HF datasets (Faz1'de dekontamine → adil).
|
| 9 |
|
| 10 |
+
Kullanım (mamba-ssm kurulu + HF login'li):
|
| 11 |
+
# v1.5b 350M base — en güncel ara/son ckpt (checkpoints_350m namespace):
|
| 12 |
+
HF_TOKEN=hf_xxx python faz5_eval.py --tasks xcopa,belebele,hellaswag,xnli,turkishmmlu --limit 300
|
| 13 |
+
# belirli ckpt: --ckpt checkpoints_350m/step_020000/ckpt.pt
|
| 14 |
+
# eski v1.0 177M için: --ckpt_subdir checkpoints
|
| 15 |
"""
|
| 16 |
import os, sys, argparse
|
| 17 |
import torch, torch.nn as nn, torch.nn.functional as F
|
|
|
|
| 23 |
from mamba_ssm.modules.mlp import GatedMLP
|
| 24 |
from mamba_ssm.ops.triton.layer_norm import RMSNorm
|
| 25 |
except Exception as e:
|
| 26 |
+
sys.exit(f"[hata] mamba-ssm yok ({e!r}). Önce wheel-cache kurulum hücresini çalıştır (CUDA gerekir).")
|
| 27 |
|
| 28 |
|
| 29 |
# ───────────── model (faz3_train.py ile BİREBİR AYNI) ─────────────
|
|
|
|
| 125 |
return sp
|
| 126 |
|
| 127 |
|
| 128 |
+
def latest_ckpt(token, subdir="checkpoints_350m"):
|
| 129 |
from huggingface_hub import HfApi, hf_hub_download
|
| 130 |
api = HfApi(token=token)
|
| 131 |
fs = [f for f in api.list_repo_files("kdirgul/smartcore-v1", repo_type="model")
|
| 132 |
+
if f.startswith(f"{subdir}/step_") and f.endswith("ckpt.pt")]
|
| 133 |
+
if not fs:
|
| 134 |
+
sys.exit(f"[hata] '{subdir}/' altında checkpoint yok. (v1.0 177M için: --ckpt_subdir checkpoints)")
|
| 135 |
+
latest = max(fs) # step_NNNNNN sıfır-dolgulu → lexikografik = sayısal
|
| 136 |
print(f"[ckpt] {latest}", flush=True)
|
| 137 |
return hf_hub_download("kdirgul/smartcore-v1", latest, repo_type="model", token=token)
|
| 138 |
|
| 139 |
|
| 140 |
+
def resolve_ckpt(spec, token, subdir="checkpoints_350m"):
|
| 141 |
+
"""spec yoksa subdir'deki latest; yerel .pt varsa onu; aksi halde HF yolu (örn sft/epoch_2/ckpt.pt)."""
|
| 142 |
if not spec:
|
| 143 |
+
return latest_ckpt(token, subdir)
|
| 144 |
if os.path.exists(spec):
|
| 145 |
return spec
|
| 146 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 266 |
ap = argparse.ArgumentParser()
|
| 267 |
ap.add_argument("--tasks", default="xcopa,belebele,hellaswag")
|
| 268 |
ap.add_argument("--limit", type=int, default=200)
|
| 269 |
+
ap.add_argument("--ckpt", default=None, help="HF yolu (sft/epoch_2/ckpt.pt) | yerel .pt | boş=subdir latest")
|
| 270 |
+
ap.add_argument("--ckpt_subdir", default="checkpoints_350m",
|
| 271 |
+
help="latest ckpt namespace (v1.5b=checkpoints_350m, v1.0=checkpoints)")
|
| 272 |
args = ap.parse_args()
|
| 273 |
|
| 274 |
assert torch.cuda.is_available(), "CUDA yok (Colab GPU gerekir)."
|
|
|
|
| 277 |
token = os.environ.get("HF_TOKEN") or get_token()
|
| 278 |
|
| 279 |
sp = load_tok(token)
|
| 280 |
+
st = torch.load(resolve_ckpt(args.ckpt, token, args.ckpt_subdir), map_location="cpu", weights_only=False)
|
| 281 |
model = HybridLM(st["cfg"], device="cuda", dtype=torch.bfloat16)
|
| 282 |
model.load_state_dict(st["model"], strict=False); model.eval()
|
| 283 |
tag = f"sft/epoch={st.get('epoch')}" if st.get("sft") else f"base step={st.get('step','?')}"
|