pin: train/hubckpt.py (RepoMissing resume branch, disk gate, PHASE4_PREP_ONLY)
Browse files- train/hubckpt.py +13 -0
train/hubckpt.py
CHANGED
|
@@ -52,6 +52,12 @@ def local_manifest(dirpath):
|
|
| 52 |
return out
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def hub_listing(repo, repo_type="dataset", revision="main", token=None, page=None):
|
| 56 |
"""{path_in_repo: (bytes, sha256_or_None)} straight from the Hub's tree endpoint, ALL pages.
|
| 57 |
|
|
@@ -71,6 +77,13 @@ def hub_listing(repo, repo_type="dataset", revision="main", token=None, page=Non
|
|
| 71 |
with urllib.request.urlopen(req, timeout=120) as r:
|
| 72 |
entries = json.loads(r.read().decode())
|
| 73 |
link = r.headers.get("Link") or ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
except Exception as e:
|
| 75 |
raise RuntimeError(f"hub listing failed for {repo}@{revision}: {type(e).__name__}: "
|
| 76 |
f"{str(e)[:160]}") from e
|
|
|
|
| 52 |
return out
|
| 53 |
|
| 54 |
|
| 55 |
+
class RepoMissing(RuntimeError):
|
| 56 |
+
"""The Hub says this repository does not exist -- distinct from "the listing failed", which is what
|
| 57 |
+
RuntimeError means here. Callers that treat a failure as an empty repo would restart training at step
|
| 58 |
+
0 (E-018), so the two must stay distinguishable at the except clause."""
|
| 59 |
+
|
| 60 |
+
|
| 61 |
def hub_listing(repo, repo_type="dataset", revision="main", token=None, page=None):
|
| 62 |
"""{path_in_repo: (bytes, sha256_or_None)} straight from the Hub's tree endpoint, ALL pages.
|
| 63 |
|
|
|
|
| 77 |
with urllib.request.urlopen(req, timeout=120) as r:
|
| 78 |
entries = json.loads(r.read().decode())
|
| 79 |
link = r.headers.get("Link") or ""
|
| 80 |
+
except urllib.error.HTTPError as e:
|
| 81 |
+
# 404 here means the repository itself has never been created, which is a different fact from a
|
| 82 |
+
# failed lookup -- and the first Phase 4 session depends on telling them apart.
|
| 83 |
+
if e.code == 404:
|
| 84 |
+
raise RepoMissing(f"hub repo {repo} does not exist (HTTP 404)") from e
|
| 85 |
+
raise RuntimeError(f"hub listing failed for {repo}@{revision}: HTTPError {e.code}: "
|
| 86 |
+
f"{str(e)[:160]}") from e
|
| 87 |
except Exception as e:
|
| 88 |
raise RuntimeError(f"hub listing failed for {repo}@{revision}: {type(e).__name__}: "
|
| 89 |
f"{str(e)[:160]}") from e
|