File size: 1,578 Bytes
38326d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
"""GPU smoke-job wrapper: pulls the code from the Hub repo, runs a short
train.py (with trackio + checkpoint upload) and an evaluate.py sweep, and
prints the results. Run via `uv` with deps torch, numpy, huggingface_hub,
trackio."""

import json
import os
import subprocess
import sys

REPO = "eac123/ptr-recurrent-depth"
SPACE_ID = os.environ["TRACKIO_SPACE_ID"]


def sh(cmd):
    print("+", " ".join(cmd), flush=True)
    subprocess.run(cmd, check=True)


from huggingface_hub import snapshot_download

snapshot_download(repo_id=REPO, repo_type="model",
                  allow_patterns=["*.py", "ptr/*.py"], local_dir=".")
sys.path.insert(0, os.getcwd())

sh([sys.executable, "train.py", "--arch", "rec", "--depth", "1",
    "--iters", "4", "--seed", "0", "--run-name", "smoke-t4", "--steps", "300",
    "--eval-every", "150", "--eval-n", "200", "--out-dir", "out",
    "--hub-repo", REPO, "--space-id", SPACE_ID])
sh([sys.executable, "evaluate.py", "--ckpt", "out/smoke-t4.pt",
    "--out-dir", "results", "--n-per-cell", "50"])

with open("results/smoke-t4_eval.json") as fh:
    ev = json.load(fh)
print("SMOKE OK. acc@k=8:", ev["acc_vs_k"]["8"], "acc@k=64:",
      ev["acc_vs_k"]["64"], "lookup:", ev["lookup_reference_acc"])
try:
    from huggingface_hub import HfApi
    HfApi().upload_file(path_or_fileobj="results/smoke-t4_eval.json",
                        path_in_repo="results/smoke-t4_eval.json",
                        repo_id=REPO, repo_type="model")
except Exception as e:  # non-fatal for the smoke test
    print("eval-json upload failed (non-fatal):", e)