File size: 2,133 Bytes
f80e81a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Colab cell: (1) upload the H4 F1 train record, (2) evaluate the non-weight kNN datastore (NW-1) on the REAL holdout cache
with the full vocabulary, with and without a near-duplicate cosine cap (duplicate-sensitivity audit). Results go to
STAR-future/Trinity eval/t3/. Needs /content/k3p/out_train2 (train2 cache) already on the runtime."""
import os
import subprocess
import sys
from pathlib import Path

from huggingface_hub import HfApi, hf_hub_download, snapshot_download

TOK = os.environ["HF_TOKEN"]
REPO = "STAR-future/Trinity"
W = Path("/content/k3p")
api = HfApi(token=TOK)
rec = W / "h4" / "F1_Arm3_HeadLoRA" / "train_record.json"
if rec.exists():
    api.upload_file(path_or_fileobj=str(rec), path_in_repo="eval/h4/F1_Arm3_HeadLoRA_train_record.json", repo_id=REPO,
                    commit_message="H4 F1 train record")
for f in ("k3ref.py", "k3pass.py", "lb_tail_train.py", "lb_tail_eval.py", "trinity_full_tail_wsp.py",
          "eval_t3_nonweight_on_k3cache.py"):
    (W / f).write_bytes(Path(hf_hub_download(REPO, f"tools/{f}", token=TOK, force_download=True)).read_bytes())
if not (W / "out_holdout" / "summary.json").exists():
    snapshot_download("STAR-future/Trinity-k3cache", repo_type="dataset", token=TOK, allow_patterns=["holdout/*"],
                      local_dir=str(W / "cache_dl"))
    (W / "out_holdout").mkdir(exist_ok=True)
    for f in (W / "cache_dl" / "holdout").iterdir():
        f.rename(W / "out_holdout" / f.name)
env = dict(os.environ, PYTHONPATH=str(W))
for tag, cap in (("t3_nocap", "2.0"), ("t3_cap098", "0.98")):
    out = W / tag
    rc = subprocess.run([sys.executable, "-u", str(W / "eval_t3_nonweight_on_k3cache.py"), "--train-cache", str(W / "out_train2"),
                         "--holdout-cache", str(W / "out_holdout"), "--out", str(out), "--cos-cap", cap], cwd=W, env=env).returncode
    print(tag, "rc", rc, flush=True)
    for p in out.glob("*"):
        if p.is_file() and p.stat().st_size < 200e6:
            api.upload_file(path_or_fileobj=str(p), path_in_repo=f"eval/t3/{tag}/{p.name}", repo_id=REPO,
                            commit_message=f"{tag} {p.name}")