Download rsm_rise/scripts/wmb/patch_body.py from rli14/rsm_rise_code: direct link, hf CLI and curl.
- Browser
- Download file 18 kB
-
https://huggingface.co/rli14/rsm_rise_code/resolve/main/rsm_rise/scripts/wmb/patch_body.py
- Command line
-
hf download hf://rli14/rsm_rise_code/rsm_rise/scripts/wmb/patch_body.py
-
curl -L -o patch_body.py https://huggingface.co/rli14/rsm_rise_code/resolve/main/rsm_rise/scripts/wmb/patch_body.py
18 kB
| #!/usr/bin/env python3 | |
| """gen_q#288 -- patch the issue BODY in place (run 42; renamed off the run number in run 43, | |
| since the whole point is that ONE script is re-run and REPLACES its block each time). | |
| Two things, both aimed at the brief's rule that the body is "the clean, current source of truth ... no | |
| run-by-run logs in the body": | |
| 1. refresh the live pair counts on the matched-rung block (numbers only -- partial-rung DELTAS stay | |
| withheld, the standing refusal in this stream); | |
| 2. install a DELIMITED, REPLACEABLE block for the current run's state. Every earlier run APPENDED a new | |
| section, which is why the body grew 108854 -> 111671 -> 115982 chars in three runs. This block is | |
| bounded by BEGIN/END markers and is REPLACED, not appended, so the body stops growing. | |
| Re-running is safe: the pair-count edit is idempotent (it rewrites one line to the same value) and the | |
| block is replaced wholesale. Refuses if the anchor line it must rewrite is missing. | |
| """ | |
| import json, os, re, subprocess, sys, glob | |
| ROOT = "/proj/dmfexp/zwhong/rsm_rise" | |
| REPO = "williamd4112/gen_q" | |
| NUM = 288 | |
| BEGIN = "<!-- WMB_CURRENT_STATE_BEGIN -->" | |
| END = "<!-- WMB_CURRENT_STATE_END -->" | |
| def token(): | |
| with open(os.path.expanduser("~/.git-credentials")) as f: | |
| for ln in f: | |
| if "github.com" in ln: | |
| return ln.split(":")[2].split("@")[0].strip() | |
| raise SystemExit("no github token") | |
| def api(method, url, payload=None): | |
| cmd = ["curl", "-s", "-X", method, "-H", f"Authorization: token {token()}", | |
| "-H", "Accept: application/vnd.github+json", url] | |
| if payload is not None: | |
| cmd += ["-d", json.dumps(payload)] | |
| out = subprocess.run(cmd, capture_output=True, text=True).stdout | |
| return json.loads(out) | |
| def rung_deltas(): | |
| """Parse scripts/wmb/paired_matched_delta.py -- the single source of truth for the matched deltas. | |
| Run 44: the body's matched-rung table was hand-written for the 16-frame rung, so publishing the second | |
| completed rung by hand would have been a second place for these numbers to drift out of the code. | |
| """ | |
| out = subprocess.run([sys.executable, f"{ROOT}/scripts/wmb/paired_matched_delta.py"], | |
| capture_output=True, text=True, cwd=ROOT).stdout | |
| rows = {} | |
| for m in re.finditer(r"realfr=\s*(\d+) \(LeWM H=(\d+) vs DINO H=(\d+)\): paired (\d+)/(\d+)\s+" | |
| r"LeWM\s+([\d.]+)\s+DINO\s+([\d.]+)\s+delta\s+([-+][\d.]+) pts\s+" | |
| r"SE ([\d.]+)\s+up (\d+)/(\d+)", out): | |
| rf = int(m.group(1)) | |
| rows[rf] = dict(rf=rf, lh=int(m.group(2)), dh=int(m.group(3)), pairs=int(m.group(4)), | |
| tot=int(m.group(5)), lewm=float(m.group(6)), dino=float(m.group(7)), | |
| delta=float(m.group(8)), se=float(m.group(9)), up=int(m.group(10))) | |
| if not rows: | |
| raise SystemExit("REFUSING: could not parse paired_matched_delta.py output") | |
| return rows | |
| def counts(): | |
| d = {} | |
| for h in (128, 192, 448, 832, 1600): | |
| d[h] = len(glob.glob(f"{ROOT}/runs/*/eval_onactor/E1-LEWM-R0.95-{h}-*M16-es*.json")) | |
| return d | |
| def main(): | |
| body = api("GET", f"https://api.github.com/repos/{REPO}/issues/{NUM}")["body"] | |
| before = len(body) | |
| c = counts() | |
| # 1. the pair-count line on the matched-rung block | |
| pat = re.compile(r"Pair counts only: 24 frames \*\*\d+/63\*\*, 56 frames \*\*\d+/63\*\*, 104 frames\s+" | |
| r"\*\*\d+/63\*\*,\s*\n?\s*200 frames \*\*\d+/63\*\*\.") | |
| new_line = (f"Pair counts only: 24 frames **{c[192]}/63**, 56 frames **{c[448]}/63**, " | |
| f"104 frames **{c[832]}/63**, 200 frames **{c[1600]}/63**.") | |
| if not pat.search(body): | |
| print("REFUSING: the pair-count anchor line is not in the body -- not editing blind") | |
| return 2 | |
| body = pat.sub(new_line, body) | |
| # 1b. the matched-rung TABLE: rebuild its rows from every COMPLETE (63/63) rung. Run 44 completed the | |
| # 24-frame rung, and the table had been hand-written for 16 frames only. Partial rungs stay OUT of the | |
| # table (the standing refusal); they appear only as the pair counts rewritten just above. | |
| rd = rung_deltas() | |
| complete = [rd[rf] for rf in sorted(rd) if rd[rf]["pairs"] == rd[rf]["tot"]] | |
| tpat = re.compile(r"(\| real frames \| LeWM \| DINO-WM \| paired delta \(LeWM - DINO\) \| pairs \|\n" | |
| r"\s*\|---\|---\|---\|---\|---\|\n)((?:[ \t]*\|[^\n]*\|\n)+)") | |
| tm = tpat.search(body) | |
| if not tm: | |
| print("REFUSING: matched-rung table header not found -- not editing blind") | |
| return 2 | |
| indent = re.match(r"[ \t]*", tm.group(2)).group(0) | |
| rows = "".join( | |
| f"{indent}| **{r['rf']}** | **{r['lewm']:.1f} %** | **{r['dino']:.1f} %** | " | |
| f"**{r['delta']:+.1f} pts**, paired SE {r['se']:.2f}, t ~ {abs(r['delta'])/r['se']:.1f} | " | |
| f"**{r['pairs']}/{r['tot']}** |\n" | |
| for r in complete) | |
| body = body[:tm.start(2)] + rows + body[tm.end(2):] | |
| # 1b-ii. the sentence after the table quoted a single rung's t. Generate it from the complete rungs so | |
| # it cannot drift as rungs land (run 44: two complete rungs, t ~ 4.2 and ~ 2.9). | |
| ts = ", ".join(f"{abs(r['delta'])/r['se']:.1f} ({r['rf']} frames)" for r in complete) | |
| tsent = (f"3150 episodes per side per rung. **t ~ {ts} -- every complete rung is outside noise, so the " | |
| f"answer is NO: the 8x horizon-label gap is not why LeWM trails DINO-WM.**") | |
| pat_t = re.compile(r"3150 episodes per side(?: per rung)?\. \*\*t ~ [^*]*?\*\*") | |
| if not pat_t.search(body): | |
| print("REFUSING: the post-table t sentence anchor is missing -- not editing blind") | |
| return 2 | |
| body = pat_t.sub(lambda _m: tsent, body, count=1) | |
| # 1b-iii. "Give LeWM the same real lookahead and DINO-WM still wins by ~N pts. Cells up: ..." -- | |
| # GENERATE both halves. Run 44 made this sentence say "~4-5 pts" and its own anchor required | |
| # "~\d+ pts", so from run 45 the regex silently stopped matching and the cells-up list quietly froze | |
| # at two rungs while a third had landed. A generator whose anchor its own output breaks is worse than | |
| # a hand-written line, so the anchor now accepts the range form it writes. | |
| ups = ", ".join(f"{r['up']}/{r['tot']} at {r['rf']} frames" for r in complete) | |
| mags = sorted(abs(r["delta"]) for r in complete) | |
| # One decimal, not f"{x:.0f}": 3.9..6.5 printed as "~4-6", which rounds the LARGEST measured gap DOWN. | |
| # An error in the conservative direction is still an error in a published span. | |
| span = (f"{mags[0]:.1f}" if abs(mags[0] - mags[-1]) < 0.05 else f"{mags[0]:.1f}-{mags[-1]:.1f}") | |
| pat_u = re.compile(r"Give LeWM the same real lookahead and DINO-WM still wins by ~?[\d.]+(?:-[\d.]+)?" r" pts(?: at every complete rung)?\.\s*" | |
| r"(?:\d+/\d+\s*\n?\s*cells up|Cells up: [^.]*)\.") | |
| if not pat_u.search(body): | |
| print("REFUSING: the cells-up / win-span sentence anchor is missing -- not editing blind") | |
| return 2 | |
| body = pat_u.sub("Give LeWM the same real lookahead and DINO-WM still wins by " | |
| f"{span} pts at every complete rung. Cells up: {ups}.", body, count=1) | |
| # 1c. "the other N rungs are in flight" must track how many are actually incomplete | |
| n_partial = sum(1 for rf in rd if rd[rf]["pairs"] != rd[rf]["tot"]) | |
| words = {1: "one rung", 2: "two rungs", 3: "three rungs", 4: "four rungs", 5: "five rungs"} | |
| body = re.sub(r"The other (one rung|two rungs|three rungs|four rungs|five rungs) (?:is|are) in flight", | |
| "The other " + words.get(n_partial, f"{n_partial} rungs") | |
| + (" is in flight" if n_partial == 1 else " are in flight"), body) | |
| # 1d. The H=1600 real-frame-parity checklist item (run 45): the rung is 63/63 and reported, so leaving | |
| # it unticked would make the checklist -- which the brief calls the body's source of truth -- understate | |
| # the work. GENERATED rather than ticked once by hand: the span between the item's lead and " and run 37 | |
| # proved" is rewritten wholesale, so this matches the ORIGINAL "WAVE 27 IN FLIGHT" wording, the broken | |
| # first attempt of this run (which opened a second `**` inside the item's bold span and rendered wrong), | |
| # and its own output -- i.e. it is self-healing and the numbers cannot drift from paired_matched_delta.py. | |
| # A one-shot tick could not repair its own bad markdown; a generator can. | |
| LEAD = "**Real-frame PARITY leg for LeWM \u2014 `H=1600`" | |
| pat_h = re.compile(r"- \[[ x]\] " + re.escape(LEAD) + r".*?(?= and run 37 proved)", re.S) | |
| r1600 = rd.get(200) | |
| if r1600 and r1600["pairs"] == r1600["tot"] and pat_h.search(body): | |
| d = f"{abs(r1600['delta']):.1f}" | |
| body = pat_h.sub( | |
| f"- [x] {LEAD} (depth 200 = 200 real frames = DINO-WM's H=200) \u2014 COMPLETE " | |
| f"{r1600['pairs']}/{r1600['tot']} and REPORTED: LeWM {r1600['lewm']:.1f} % vs DINO-WM " | |
| f"{r1600['dino']:.1f} %, \u2212{d} pts paired, SE {r1600['se']:.2f}, " | |
| f"t ~ {abs(r1600['delta'])/r1600['se']:.1f},", | |
| body, count=1) | |
| # 1e. The LeWM real-frame-LABELLING item (run 49). It is ANSWERED only once EVERY rung of the matched | |
| # axis is final -- the whole point of the axis was to show what the 8x label costs, and a partial axis | |
| # answers it with exactly the kind of number this stream has now had read wrong 7 times. Generated, and | |
| # gated on all five rungs being 63/63, so it un-ticks itself if a cell were ever lost. | |
| LEAD_L = ("**LeWM's hop advances +1 REAL FRAME, not the 8 the scorer assumes") | |
| pat_l = re.compile(r"- \[[ x]\] (?:\*\*ANSWERED[^*]*\*\* )?" + re.escape(LEAD_L)) | |
| if len(complete) == 5 and pat_l.search(body): | |
| span = ("β" + " / β".join(f"{abs(rd[rf]['delta']):.1f}" for rf in sorted(rd))) | |
| body = pat_l.sub( | |
| "- [x] **ANSWERED on the COMPLETE matched axis (5/5 rungs, 63/63 pairs each): correcting the " | |
| "label does NOT change the conclusion β at real-frame parity LeWM is behind DINO-WM at " | |
| f"every budget ({span} pts at 16/24/56/104/200 real frames). Documentation-only.** " + LEAD_L, | |
| body, count=1) | |
| # 2. the replaceable current-state block. | |
| # Run 45: the rung-count line's COMPLETE labels and the "they agree: X and Y pts" sentence were | |
| # hand-written, which is the same drift risk run 44 removed from the table. Both are generated now: | |
| # a third rung (200 frames) completed this run and the hand-written sentence still said "Both". | |
| H2RF = {128: 16, 192: 24, 448: 56, 832: 104, 1600: 200} | |
| rungline = ", ".join( | |
| f"{H2RF[h]}{' frames' if i == 0 else ''} (H={h}) **{c[h]}/63" | |
| + (" COMPLETE" if H2RF[h] in rd and rd[H2RF[h]]["pairs"] == rd[H2RF[h]]["tot"] else "") + "**" | |
| for i, h in enumerate((128, 192, 448, 832, 1600))) | |
| n_c = len(complete) | |
| _ds = [f"{r['delta']:+.1f}".replace("+", "").replace("-", "\u2212") for r in complete] | |
| dlist = (" and ".join(_ds) if n_c < 3 else ", ".join(_ds[:-1]) + " and " + _ds[-1]) | |
| agree = (("Both" if n_c == 2 else f"All {n_c}") + f" complete rungs are in the table above and agree: " | |
| f"**{dlist}** pts." if n_c > 1 else | |
| f"The one complete rung is in the table above: **{dlist}** pts.") | |
| r832 = rd[104] | |
| block = f"""{BEGIN} | |
| ### Current state β run 49, 2026-09-27 08:35 UTC (this block is REPLACED each run, never appended) | |
| **Matched LeWM rungs (real-frame parity with the published DINO-WM grid):** {rungline}. {agree} | |
| Partial-rung deltas stay withheld β the fast tasks land first and this stream has published a sign flip | |
| that way. **No rung is partial any more: the axis is COMPLETE.** | |
| **THE RESULT: all five rungs are FINAL, all five have the SAME sign, and the gap is WIDEST at DINO-WM's own | |
| best horizon.** The table above is generated from `paired_matched_delta.py`. The headline rung is 200 real | |
| frames β LeWM H=1600 against **DINO-WM H=200, the horizon the owner asked the top-up to focus on** | |
| (DINO-WM's argmax arm on 4/7 tasks): LeWM **{rd[200]['lewm']:.1f} %** vs DINO-WM **{rd[200]['dino']:.1f} %**, | |
| **β{abs(rd[200]['delta']):.1f} pts**, paired SE {rd[200]['se']:.2f}, **t ~ {abs(rd[200]['delta'])/rd[200]['se']:.1f}** on 63/63. | |
| Giving LeWM an 8Γ deeper rollout so it sees the *same number of real frames* does not close the gap; at | |
| DINO-WM's best horizon it is wider than at any shallower rung. **The 8Γ horizon-label gap is therefore not | |
| what holds LeWM back** β that was the question this axis was built to answer, and it is now answered on | |
| five complete rungs rather than argued from one. | |
| **What the complete curve says: LeWM SATURATES, it does not dip.** LeWM reads | |
| {rd[16]['lewm']:.1f} β {rd[24]['lewm']:.1f} β {rd[56]['lewm']:.1f} β {rd[104]['lewm']:.1f} β {rd[200]['lewm']:.1f} β | |
| monotone rising throughout, but the last three steps buy +{rd[56]['lewm']-rd[24]['lewm']:.1f} / | |
| **+{rd[104]['lewm']-rd[56]['lewm']:.1f} / +{rd[200]['lewm']-rd[104]['lewm']:.1f}** pts. From 56 to 200 real frames | |
| (3.6Γ the lookahead) LeWM gains **+{rd[200]['lewm']-rd[56]['lewm']:.1f}** while DINO-WM gains | |
| **+{rd[200]['dino']-rd[56]['dino']:.1f}**. DINO-WM's own curve | |
| ({rd[16]['dino']:.1f} β {rd[24]['dino']:.1f} β {rd[56]['dino']:.1f} β {rd[104]['dino']:.1f} β {rd[200]['dino']:.1f}) | |
| is *not* monotone β it dips at 24 and at 104 frames β so LeWM is the better-behaved curve of the two and | |
| still the losing one at every budget. | |
| **A claim withdrawn in public, and it was mine.** Until this run this body β and comment `5853170823` β | |
| argued LeWM's matched curve was *non-monotone* in depth, resting entirely on the **withheld 104-frame | |
| partial**, which at 56/63 read LeWM **21.8 %** / DINO-WM **25.4 %** and at 62/63 read **20.8 %** / | |
| **23.9 %**. Final at 63/63 it reads **{rd[104]['lewm']:.1f} %** / **{rd[104]['dino']:.1f} %** β the partial was | |
| **{21.8-rd[104]['lewm']:.1f}** and **{25.4-rd[104]['dino']:.1f} pts** high, and its delta walked | |
| β3.6 (57/63) β β3.1 (62/63) β **{rd[104]['delta']:+.1f}** (final). The non-monotonicity claim is **withdrawn**; | |
| the paragraph above rests only on final rungs. This is the **7th** partial rung in this stream to read | |
| materially wrong. The withheld-delta rule is why this is a withdrawn *comment* and not a withdrawn table: | |
| **no partial rung has ever entered a published `.tex`.** | |
| **This run's job was to finish the axis, and it did β the run-47/48 fixes are what made that automatic.** | |
| The last cell (104-frame rung, `two_piece_expert_play_tipping`) had been `TERM_ADMIN`-killed at 07:32Z at | |
| 38/50 episodes; rescue `1932617` resumed it and **completed the axis at 08:19:56Z**. The render `1931090` | |
| released **7 seconds later**, at 08:20:03Z, on `H=832:63/63` β its log then printed | |
| **`MATCHED GATE SUMMARY: 5/5 rungs complete`** and all five rungs `COMPLETE -> publishable`. Run 47's | |
| lengthened wait is the reason: the **old 20-minute wait would have expired at ~08:07Z**, 13 minutes before | |
| the cell landed, and would have published "PARTIAL" on the one rung the whole axis was waiting for. Run | |
| 48's rescue-guard fix (ownership keyed on *(wave, job liveness)* rather than on a leftover drain-queue | |
| **file**) is what let the cell be relaunched at all. Both fixes were verified in both directions before use. | |
| **The grid is COMPLETE and this stream has no launchable work left.** All 12 horizons on disk read | |
| **63/63** (pre-registered {{10, 20, 50, 100, 200}} plus the matched axis 128/192/400/448/800/832/1600); | |
| `abandoned_cells.py` **0**, `orphan_census.py` **TOTAL TRUE ORPHANS 0**, `deadline_risk.py` **0 in-flight, | |
| 0 at-risk**. **Zero GPU jobs running for this stream, and zero 1-GPU jobs ever submitted by it.** | |
| **Which of these horizons are publishable (answering #287's question).** H β {{10, 20, 50, 100, 200}} is the | |
| pre-registered grid and the only one `tab:flagship` prints. **128/192/400/448/800/832/1600 are the | |
| real-frame-MATCHED diagnostic axis** (a LeWM hop advances 1 real frame against DINO-WM's 8, so LeWM H=1600 | |
| β DINO-WM H=200 in real frames) and were never pre-registered as publishable arms. They belong in the | |
| methods/appendix comparison, **not** in a max-over-arms that sets a baseline β so `tab:flagship`'s gate is | |
| right and `verdict_table`'s ungated per-family max is the side to fix. | |
| **Nothing published moved:** LeWM **48.7** / DINO-WM **50.0** / RSM **54.0**; builder md5 `5bb4a170087e`; | |
| provenance escaped=1 raw=0 on all three `flagship_*.tex`; `grep -c wm=UNFILTERED` = 2 (FLAG_TOPUP's, not | |
| mine). The render's own diff against the artefact on disk is `IDENTICAL` on every table, with | |
| `EQUIVALENT` (explicit == default), `GUARD A: INERT`, `GUARD B: MONOTONE` over 343 numeric cells, filter | |
| guard `differ, as required` and `ESCAPED`. The owner's 02:20 decision stands untouched: **DINO-WM publishes | |
| M1, LeWM publishes M16**, never pooled. `docs/tex/appendix_rise_methods.tex` untouched (mtime | |
| 2026-09-25 21:39:17Z) and its M-rollout text still matches the code. Disk 99 % / 5.2 T. | |
| {END}""" | |
| if BEGIN in body: | |
| body = re.sub(re.escape(BEGIN) + r".*?" + re.escape(END), block, body, flags=re.S) | |
| how = "REPLACED existing block" | |
| else: | |
| anchor = "## Checklist" | |
| if anchor not in body: | |
| print("REFUSING: no '## Checklist' anchor to insert before") | |
| return 2 | |
| body = body.replace(anchor, block + "\n\n" + anchor, 1) | |
| how = "INSERTED new block" | |
| r = api("PATCH", f"https://api.github.com/repos/{REPO}/issues/{NUM}", {"body": body}) | |
| ok = isinstance(r, dict) and r.get("number") == NUM | |
| print(f"{how}; body {before} -> {len(body)} chars; PATCH {'OK' if ok else 'FAILED: ' + str(r)[:200]}") | |
| print(f"markers in body: BEGIN={body.count(BEGIN)} END={body.count(END)} (must be 1/1)") | |
| return 0 if ok else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |