Cion-lab commited on
Commit
17135b7
·
verified ·
1 Parent(s): c9ea4eb

mirror kernels/ so the kept code is self-contained

Browse files
kernels/p7_probe_publish_source.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Does `--ckpt-repo` actually choose the repo the publisher reads its weights from?
2
+
3
+ Hard-coding `Cion-lab/ounce100m-ckpt` as the only source was harmless while that repo existed and there was one
4
+ model. It is not harmless now: a second run publishing to its own repo would still resolve `latest.json` from
5
+ the first run's -- i.e. publish one model's weights under another model's card -- and since that repo has been
6
+ deleted the failure arrives as a confusing 404 instead of a wrong answer.
7
+
8
+ Why a 404 cannot be the test. A traceback prints the failing *source line*, which contains the literal
9
+ `{a.ckpt_repo}`, not the URL it resolved to. "It died" therefore says nothing about which repo it asked for,
10
+ and a probe asserting on that text would pass whether or not the fix works. So the decisive read is the
11
+ publisher's own `ckpt latest.json -> {...}` print, which names the repo it fetched -- that needs a repo that
12
+ answers. The kernel therefore creates a throwaway **private** dataset repo containing nothing but
13
+ `latest.json = {"step": 0, "path_in_repo": "final"}`, reads that dict back out of the publisher's stdout, and
14
+ deletes the repo in a `finally`. If the constant still won, the print would name `ounce100m-ckpt` and the fetch
15
+ would 404, and the assertion fails for the right reason.
16
+
17
+ Four cases, free CPU, nothing published:
18
+ 1 static -- the fetch is built from the argument; no fetch is built from the constant.
19
+ 2 help -- `--help` lists `--ckpt-repo`.
20
+ 3 positive-- the new file, told to read the temp repo, prints that repo's name and step 0.
21
+ 4 contrast-- the old file at REV `55f23ef5` rejects `--ckpt-repo` outright (rc 2, argparse), so case 3 is
22
+ evidence about the change and not about something that was always true.
23
+ """
24
+ import hashlib
25
+ import io
26
+ import json
27
+ import os
28
+ import subprocess
29
+ import sys
30
+ import urllib.request
31
+
32
+ CODE = "Cion-lab/ounce100m-code"
33
+ NEW_REV = "dd1b6b94cc90ae6deff94e0990d58da64c6637f1"
34
+ NEW_SHA = "d1f3c4eb2b80cd4bff35c1b1b90a67ec6204dd753e09f354673d0812cc231e01"
35
+ OLD_REV = "55f23ef5d0e8e6a60adad23bf8a2ffffc6bc7580"
36
+ TMP = "Cion-lab/ounce100m-p7-probe-tmp"
37
+
38
+
39
+ def fetch(rev):
40
+ url = f"https://huggingface.co/{CODE}/resolve/{rev}/build/publish_model.py"
41
+ return urllib.request.urlopen(url, timeout=120).read()
42
+
43
+
44
+ def report(R, why=""):
45
+ print("PROBE_JSON_BEGIN\n" + json.dumps(R, indent=1) + "\nPROBE_JSON_END", flush=True)
46
+ ok = all(v for k, v in R.items() if k.startswith("case"))
47
+ print(f"VERDICT PUBLISH_SOURCE {'PASS' if ok else 'FAIL'} {why}", flush=True)
48
+ return ok
49
+
50
+
51
+ R = {}
52
+ try:
53
+ sys.path.insert(0, "/kaggle/working/lib")
54
+ import ounce100m_credentials
55
+ ounce100m_credentials.install(verify=True)
56
+ from huggingface_hub import HfApi
57
+ api = HfApi()
58
+
59
+ os.makedirs("/kaggle/working/lib", exist_ok=True)
60
+ newp, oldp = "/kaggle/working/pub_new.py", "/kaggle/working/pub_old.py"
61
+ nb = fetch(NEW_REV)
62
+ open(newp, "wb").write(nb)
63
+ got = hashlib.sha256(nb).hexdigest()
64
+ R["fetched"] = f"{NEW_REV[:10]} sha_ok={got == NEW_SHA}"
65
+ assert got == NEW_SHA, "the pinned publisher bytes are not what this probe was written against"
66
+ open(oldp, "wb").write(fetch(OLD_REV))
67
+
68
+ src = nb.decode("utf-8")
69
+ R["case1_static_arg_wired"] = "datasets/{a.ckpt_repo}/resolve/main/latest.json" in src
70
+ R["case1_static_no_constant_fetch"] = ("datasets/{CKPT}/resolve" not in src
71
+ and "snapshot_download(CKPT" not in src)
72
+ R["case2_help_lists_flag"] = "--ckpt-repo" in subprocess.run(
73
+ [sys.executable, newp, "--help"], capture_output=True, text=True).stdout
74
+
75
+ api.create_repo(repo_id=TMP, repo_type="dataset", private=True, exist_ok=True,
76
+ token=os.environ["HF_TOKEN"])
77
+ api.upload_file(path_or_fileobj=io.BytesIO(json.dumps({"step": 0, "path_in_repo": "final"}).encode()),
78
+ path_in_repo="latest.json", repo_id=TMP, repo_type="dataset", token=os.environ["HF_TOKEN"])
79
+ made = True
80
+
81
+ r = subprocess.run([sys.executable, newp, "--dry-run", "--ckpt-repo", TMP],
82
+ capture_output=True, text=True)
83
+ out = r.stdout + r.stderr
84
+ R["case3_names_the_repo_it_was_given"] = f"'repo': '{TMP}'" in out
85
+ R["case3_read_the_pointer"] = "'step': 0" in out and "path_in_repo" in out
86
+ # It then looks for `final/`, which the temp repo does not have: stopping there is the expected outcome,
87
+ # and it is what proves no upload was attempted.
88
+ R["case3_stopped_before_upload"] = r.returncode != 0 and "upload" not in out.lower()
89
+
90
+ ro = subprocess.run([sys.executable, oldp, "--dry-run", "--ckpt-repo", TMP],
91
+ capture_output=True, text=True)
92
+ R["case4_old_file_rejects_the_flag"] = ro.returncode == 2 and "unrecognized arguments" in ro.stderr
93
+ except Exception as e:
94
+ R["aborted"] = f"{type(e).__name__}: {str(e)[:200]}"
95
+ finally:
96
+ if locals().get("made"):
97
+ try:
98
+ api.delete_repo(repo_id=TMP, repo_type="dataset")
99
+ R["temp_repo_deleted"] = True
100
+ except Exception as e:
101
+ R["temp_repo_deleted"] = f"FAILED {type(e).__name__} -- remove {TMP} by hand"
102
+
103
+ sys.exit(0 if report(R, R.get("aborted", "")) else 1)
kernels/phase4_bootstrap.py CHANGED
@@ -10,7 +10,7 @@ sys.path.insert(0, "/kaggle/working")
10
  REV = "c237b478076f68da43dabd3403daa5639286899e"
11
  LAUNCHER_SHA = "5fb14bc3597d999a21772a66b6f409f01f722019dc78da313feddb2f9c769c48"
12
  os.environ["OUNCE100M_REV"] = REV
13
- os.environ["QUOTA_LEFT_HOURS"] = "24.9" # live read 2026-09-20T11:10Z: 18,137 s of 108,000 used
14
 
15
  url = f"https://huggingface.co/Cion-lab/ounce100m-code/resolve/{REV}/kernels/phase4_session.py"
16
  rc = subprocess.run(["curl", "-sfL", url, "-o", "phase4_session.py"]).returncode
 
10
  REV = "c237b478076f68da43dabd3403daa5639286899e"
11
  LAUNCHER_SHA = "5fb14bc3597d999a21772a66b6f409f01f722019dc78da313feddb2f9c769c48"
12
  os.environ["OUNCE100M_REV"] = REV
13
+ os.environ["QUOTA_LEFT_HOURS"] = "7.0" # live read 2026-09-21T08:29Z: 82,755.0 s of 108,000 used
14
 
15
  url = f"https://huggingface.co/Cion-lab/ounce100m-code/resolve/{REV}/kernels/phase4_session.py"
16
  rc = subprocess.run(["curl", "-sfL", url, "-o", "phase4_session.py"]).returncode