train: hubckpt -- readback counts as verification; GQA kv must divide heads; pargs reports before optional probe
Browse files- train/hubckpt.py +13 -8
train/hubckpt.py
CHANGED
|
@@ -96,25 +96,30 @@ def verify_checkpoint(repo, dirpath, path_in_repo, token=None, repo_type="datase
|
|
| 96 |
if hsz != lsz or (comparable and hsha != lsha):
|
| 97 |
mismatch.append({"path": k, "local": [lsz, lsha[:16]], "hub": [hsz, (hsha or "")[:16]]})
|
| 98 |
rb = None
|
|
|
|
| 99 |
if readback_one and have:
|
| 100 |
-
# Download
|
| 101 |
-
#
|
| 102 |
pick = min(have, key=lambda k: have[k][0])
|
| 103 |
tmp = os.path.join("/tmp", "hubverify_" + os.path.basename(pick))
|
| 104 |
-
url = f"{HUB}/{repo_type}s/{repo}/resolve/{prefix}{pick}"
|
| 105 |
try:
|
| 106 |
urllib.request.urlretrieve(url, tmp)
|
| 107 |
got = sha256_file(tmp)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
except Exception as e:
|
| 111 |
-
rb = {"path": pick, "
|
|
|
|
| 112 |
finally:
|
| 113 |
if os.path.exists(tmp):
|
| 114 |
os.remove(tmp)
|
| 115 |
-
ok
|
|
|
|
|
|
|
| 116 |
return {"ok": ok, "n_local": len(want), "n_hub": len(have), "missing": missing[:10],
|
| 117 |
-
"mismatch": mismatch[:10], "extra": extra[:10], "readback": rb
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
def ensure_repo(repo, api, token=None, repo_type="dataset"):
|
|
|
|
| 96 |
if hsz != lsz or (comparable and hsha != lsha):
|
| 97 |
mismatch.append({"path": k, "local": [lsz, lsha[:16]], "hub": [hsz, (hsha or "")[:16]]})
|
| 98 |
rb = None
|
| 99 |
+
rb_ok = False
|
| 100 |
if readback_one and have:
|
| 101 |
+
# Download one file back over an anonymous connection: cheapest possible proof that the bytes are
|
| 102 |
+
# *readable*, not merely listed (§3.13 is explicit that listing is not verification).
|
| 103 |
pick = min(have, key=lambda k: have[k][0])
|
| 104 |
tmp = os.path.join("/tmp", "hubverify_" + os.path.basename(pick))
|
| 105 |
+
url = f"{HUB}/{repo_type}s/{repo}/resolve/main/{prefix}{pick}"
|
| 106 |
try:
|
| 107 |
urllib.request.urlretrieve(url, tmp)
|
| 108 |
got = sha256_file(tmp)
|
| 109 |
+
rb_ok = bool(pick in want and got == want[pick][1])
|
| 110 |
+
rb = {"path": pick, "bytes": os.path.getsize(tmp), "sha_matches_manifest": rb_ok}
|
| 111 |
except Exception as e:
|
| 112 |
+
rb = {"path": pick, "url": url,
|
| 113 |
+
"error": f"{type(e).__name__}: {str(e)[:160]}"}
|
| 114 |
finally:
|
| 115 |
if os.path.exists(tmp):
|
| 116 |
os.remove(tmp)
|
| 117 |
+
# ok must include the read-back: a repo whose files are listed but not downloadable is not a
|
| 118 |
+
# checkpoint, and pruning into that state loses the run.
|
| 119 |
+
ok = bool(want) and not missing and not mismatch and (rb_ok or not readback_one)
|
| 120 |
return {"ok": ok, "n_local": len(want), "n_hub": len(have), "missing": missing[:10],
|
| 121 |
+
"mismatch": mismatch[:10], "extra": extra[:10], "readback": rb,
|
| 122 |
+
"readback_ok": rb_ok}
|
| 123 |
|
| 124 |
|
| 125 |
def ensure_repo(repo, api, token=None, repo_type="dataset"):
|