Upload train/hubckpt.py with huggingface_hub
Browse files- train/hubckpt.py +11 -6
train/hubckpt.py
CHANGED
|
@@ -131,10 +131,13 @@ def verify_checkpoint(repo, dirpath, path_in_repo, token=None, repo_type="datase
|
|
| 131 |
rb = None
|
| 132 |
rb_ok = False
|
| 133 |
if readback_one and have:
|
| 134 |
-
#
|
| 135 |
-
#
|
| 136 |
-
#
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
| 138 |
tmp = os.path.join("/tmp", "hubverify_" + os.path.basename(pick))
|
| 139 |
url = f"{HUB}/{repo_type}s/{repo}/resolve/main/{prefix}{pick}"
|
| 140 |
try:
|
|
@@ -153,8 +156,10 @@ def verify_checkpoint(repo, dirpath, path_in_repo, token=None, repo_type="datase
|
|
| 153 |
if os.path.exists(tmp):
|
| 154 |
os.remove(tmp)
|
| 155 |
# ok must include the read-back: a repo whose files are listed but not downloadable is not a
|
| 156 |
-
# checkpoint, and pruning into that state loses the run.
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
return {"ok": ok, "n_local": len(want), "n_hub": len(have), "missing": missing[:10],
|
| 159 |
"mismatch": mismatch[:10], "extra": extra[:10], "readback": rb,
|
| 160 |
"readback_ok": rb_ok}
|
|
|
|
| 131 |
rb = None
|
| 132 |
rb_ok = False
|
| 133 |
if readback_one and have:
|
| 134 |
+
# Read back the LARGEST file and re-hash it. In a Trainer checkpoint that is the fp16
|
| 135 |
+
# model.safetensors -- an LFS object -- and it is the only file whose retrievability the Hub's
|
| 136 |
+
# listing cannot establish, because the listing reports the oid the commit *claims*. Picking the
|
| 137 |
+
# cheapest file (cursor.json, a few dozen git-stored bytes) proved the git tree while leaving
|
| 138 |
+
# 1.7 GB of weights untested, and `ok=True` then authorised deleting the only local copy (E-031).
|
| 139 |
+
# The token is sent when there is one, so this also works if the repo is ever made private.
|
| 140 |
+
pick = max(have, key=lambda k: (have[k][0] or 0))
|
| 141 |
tmp = os.path.join("/tmp", "hubverify_" + os.path.basename(pick))
|
| 142 |
url = f"{HUB}/{repo_type}s/{repo}/resolve/main/{prefix}{pick}"
|
| 143 |
try:
|
|
|
|
| 156 |
if os.path.exists(tmp):
|
| 157 |
os.remove(tmp)
|
| 158 |
# ok must include the read-back: a repo whose files are listed but not downloadable is not a
|
| 159 |
+
# checkpoint, and pruning into that state loses the run. `extra` is gated too: a file on the Hub that
|
| 160 |
+
# is not in this directory means the path being pushed to already held something else, which is a
|
| 161 |
+
# naming collision, not a clean checkpoint (E-031 -- the docstring here used to claim otherwise).
|
| 162 |
+
ok = bool(want) and not missing and not mismatch and not extra and (rb_ok or not readback_one)
|
| 163 |
return {"ok": ok, "n_local": len(want), "n_hub": len(have), "missing": missing[:10],
|
| 164 |
"mismatch": mismatch[:10], "extra": extra[:10], "readback": rb,
|
| 165 |
"readback_ok": rb_ok}
|