resume-unicode · e5ea29464d73
Browse files- reports/amendments.md +3 -0
- src/study/evaluate.py +2 -2
- src/study/learnability.py +6 -5
- src/study/storage.py +22 -0
- src/study/training.py +2 -2
- tests/test_storage.py +28 -0
reports/amendments.md
CHANGED
|
@@ -15,3 +15,6 @@ Report seed-specific paired problem intervals and the secondary three-judge vers
|
|
| 15 |
Before any transfer evaluation, an invariant test on development fixtures showed that simple negation preserved absolute magnitude. The transfer implementation now reverses the sign and adds three to the absolute magnitude. Zero maps to minus three and is an explicit exception to sign reversal. For the same fixed problem IDs, cross the familiar and novel error with familiar and reserved layouts. These descriptive controls separate the two shifts. Method-level evidence results with the identical frozen Judge 3, input cohort and greedy decoder reuse a single observation set and name its source.
|
| 16 |
|
| 17 |
The field-level breakdown counts syntactically complete reports, correct solver bits, correct audit bits and altered reviews correctly rejected with the exact field and replacement. All reports remain in their corresponding denominator, including malformed output. These counts describe the registered whole-pair failures after inspection of the frozen development examples. They leave the whole-pair success criterion intact.
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
Before any transfer evaluation, an invariant test on development fixtures showed that simple negation preserved absolute magnitude. The transfer implementation now reverses the sign and adds three to the absolute magnitude. Zero maps to minus three and is an explicit exception to sign reversal. For the same fixed problem IDs, cross the familiar and novel error with familiar and reserved layouts. These descriptive controls separate the two shifts. Method-level evidence results with the identical frozen Judge 3, input cohort and greedy decoder reuse a single observation set and name its source.
|
| 16 |
|
| 17 |
The field-level breakdown counts syntactically complete reports, correct solver bits, correct audit bits and altered reviews correctly rejected with the exact field and replacement. All reports remain in their corresponding denominator, including malformed output. These counts describe the registered whole-pair failures after inspection of the frozen development examples. They leave the whole-pair success criterion intact.
|
| 18 |
+
## Recovery of the first solver's development replay
|
| 19 |
+
|
| 20 |
+
A mathematical minus sign interrupted the Windows redirected terminal while a replay batch was generating. The original prompt and partial output are present in its UTF-8 journal. The restarted evaluation reuses completed problem IDs, the same checkpoint, batch ordering and seeds. Terminal output now uses UTF-8 as well. Reported generation cost includes every completed call across attempts, including repeated work. Each unfinished batch is counted separately because its complete time and output-token count are unavailable. [Recovery tests](../tests/test_storage.py) · [Evaluation implementation](../src/study/evaluate.py)
|
src/study/evaluate.py
CHANGED
|
@@ -9,7 +9,7 @@ from .domain import problems
|
|
| 9 |
from .exposures import check_exposures
|
| 10 |
from .judging import chain, majority, twin, votes
|
| 11 |
from .records import expected, mask_evidence, parse, solver_truth, sound, terminal
|
| 12 |
-
from .storage import RESULTS, Journal, adapter, append, atomic, read_json, rows, stamp, write_json
|
| 13 |
|
| 14 |
|
| 15 |
def weights_digest(name):
|
|
@@ -169,6 +169,6 @@ def evaluate(name, final=False):
|
|
| 169 |
evidence_sources[filename] = evidence_cohort(backend, snapshots[2], name, phase, "dev", 8, filename,
|
| 170 |
pool=population(profile, "dev", 8))
|
| 171 |
result = {"time": stamp(), "phase": phase, "weights": weights_digest(name) if run else "frozen base",
|
| 172 |
-
"
|
| 173 |
write_json(marker, result)
|
| 174 |
return result
|
|
|
|
| 9 |
from .exposures import check_exposures
|
| 10 |
from .judging import chain, majority, twin, votes
|
| 11 |
from .records import expected, mask_evidence, parse, solver_truth, sound, terminal
|
| 12 |
+
from .storage import RESULTS, Journal, adapter, append, atomic, generation_cost, read_json, rows, stamp, write_json
|
| 13 |
|
| 14 |
|
| 15 |
def weights_digest(name):
|
|
|
|
| 169 |
evidence_sources[filename] = evidence_cohort(backend, snapshots[2], name, phase, "dev", 8, filename,
|
| 170 |
pool=population(profile, "dev", 8))
|
| 171 |
result = {"time": stamp(), "phase": phase, "weights": weights_digest(name) if run else "frozen base",
|
| 172 |
+
**generation_cost(name+"-"+phase,backend.totals), "evidence_sources": evidence_sources, "profile": profile}
|
| 173 |
write_json(marker, result)
|
| 174 |
return result
|
src/study/learnability.py
CHANGED
|
@@ -9,7 +9,7 @@ from .evaluate import mechanisms, weights_digest
|
|
| 9 |
from .judging import chain
|
| 10 |
from .learnability_analysis import cell_metrics, changes_by_parse, choose_cell, confirmed, learning_result
|
| 11 |
from .records import expected, parse, render, solver_truth, sound, terminal
|
| 12 |
-
from .storage import RESULTS, Journal, append, read_json, rows, stamp, write_json
|
| 13 |
|
| 14 |
def directory():
|
| 15 |
return RESULTS/"learnability"
|
|
@@ -60,7 +60,7 @@ def screen():
|
|
| 60 |
return read_json(target)
|
| 61 |
backend=Backend(Journal("learnability-screen"))
|
| 62 |
cells=[measure(backend,family,style,"screen",16) for family in FAMILIES for style in STYLES]
|
| 63 |
-
outcome=dict(time=stamp(),cells=cells,selected=choose_cell(cells),
|
| 64 |
write_json(target,outcome)
|
| 65 |
return outcome
|
| 66 |
|
|
@@ -72,7 +72,7 @@ def confirm():
|
|
| 72 |
c=selected()
|
| 73 |
backend=Backend(Journal("learnability-confirm"))
|
| 74 |
measurement=measure(backend,c["family"],c["style"],"confirm",48)
|
| 75 |
-
outcome=dict(time=stamp(),cell=measurement,confirmed=confirmed(measurement),
|
| 76 |
write_json(target,outcome)
|
| 77 |
return outcome
|
| 78 |
|
|
@@ -119,7 +119,7 @@ def audit():
|
|
| 119 |
mechanisms(backend,None,"learnability-confirm",len(pool),twin_path,population=pool)
|
| 120 |
pairs=list(rows(twin_path))
|
| 121 |
result=dict(time=stamp(),judges=levels,pairs=len(pairs),visible=mean(r["visible_pair"] for r in pairs),
|
| 122 |
-
masked=mean(r["masked_pair"] for r in pairs),
|
| 123 |
write_json(target,result)
|
| 124 |
return result
|
| 125 |
|
|
@@ -150,7 +150,8 @@ def evaluate_pilot(name):
|
|
| 150 |
correct=solver_truth(p,t)[0],parsed=parse(t,len(p.values)) is not None))
|
| 151 |
records=list(rows(path))
|
| 152 |
result=dict(time=stamp(),n=len(records),correct=sum(r["correct"] for r in records),parsed=sum(r["parsed"] for r in records),
|
| 153 |
-
weights=weights_digest(name) if snapshot else "frozen base",
|
|
|
|
| 154 |
write_json(target,result)
|
| 155 |
return result
|
| 156 |
|
|
|
|
| 9 |
from .judging import chain
|
| 10 |
from .learnability_analysis import cell_metrics, changes_by_parse, choose_cell, confirmed, learning_result
|
| 11 |
from .records import expected, parse, render, solver_truth, sound, terminal
|
| 12 |
+
from .storage import RESULTS, Journal, append, generation_cost, read_json, rows, stamp, write_json
|
| 13 |
|
| 14 |
def directory():
|
| 15 |
return RESULTS/"learnability"
|
|
|
|
| 60 |
return read_json(target)
|
| 61 |
backend=Backend(Journal("learnability-screen"))
|
| 62 |
cells=[measure(backend,family,style,"screen",16) for family in FAMILIES for style in STYLES]
|
| 63 |
+
outcome=dict(time=stamp(),cells=cells,selected=choose_cell(cells),**generation_cost("learnability-screen",backend.totals))
|
| 64 |
write_json(target,outcome)
|
| 65 |
return outcome
|
| 66 |
|
|
|
|
| 72 |
c=selected()
|
| 73 |
backend=Backend(Journal("learnability-confirm"))
|
| 74 |
measurement=measure(backend,c["family"],c["style"],"confirm",48)
|
| 75 |
+
outcome=dict(time=stamp(),cell=measurement,confirmed=confirmed(measurement),**generation_cost("learnability-confirm",backend.totals))
|
| 76 |
write_json(target,outcome)
|
| 77 |
return outcome
|
| 78 |
|
|
|
|
| 119 |
mechanisms(backend,None,"learnability-confirm",len(pool),twin_path,population=pool)
|
| 120 |
pairs=list(rows(twin_path))
|
| 121 |
result=dict(time=stamp(),judges=levels,pairs=len(pairs),visible=mean(r["visible_pair"] for r in pairs),
|
| 122 |
+
masked=mean(r["masked_pair"] for r in pairs),**generation_cost("learnability-audit",backend.totals))
|
| 123 |
write_json(target,result)
|
| 124 |
return result
|
| 125 |
|
|
|
|
| 150 |
correct=solver_truth(p,t)[0],parsed=parse(t,len(p.values)) is not None))
|
| 151 |
records=list(rows(path))
|
| 152 |
result=dict(time=stamp(),n=len(records),correct=sum(r["correct"] for r in records),parsed=sum(r["parsed"] for r in records),
|
| 153 |
+
weights=weights_digest(name) if snapshot else "frozen base",
|
| 154 |
+
**generation_cost("learnability-"+name+"-evaluation",backend.totals))
|
| 155 |
write_json(target,result)
|
| 156 |
return result
|
| 157 |
|
src/study/storage.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
import json
|
| 4 |
import os
|
|
|
|
| 5 |
import time
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
from pathlib import Path
|
|
@@ -85,12 +86,33 @@ def retain(path, predicate):
|
|
| 85 |
atomic(path, "".join(line + "\n" for line in data))
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
class Journal:
|
| 89 |
"""Mirror complete public model inputs and outputs to a timestamped log and terminal."""
|
| 90 |
|
| 91 |
def __init__(self, run):
|
| 92 |
self.run = run
|
| 93 |
self.path = log_directory() / run / (stamp().replace(":", "-") + ".jsonl")
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
def event(self, event, **values):
|
| 96 |
record = {"time": stamp(), "run": self.run, "event": event, **values}
|
|
|
|
| 2 |
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
+
import sys
|
| 6 |
import time
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
from pathlib import Path
|
|
|
|
| 86 |
atomic(path, "".join(line + "\n" for line in data))
|
| 87 |
|
| 88 |
|
| 89 |
+
def generation_cost(run, fallback):
|
| 90 |
+
"""Include completed GPU generations from every attempt, including repeated evaluation batches."""
|
| 91 |
+
totals, unfinished = {}, 0
|
| 92 |
+
fields = ("calls", "input_tokens", "output_tokens", "gpu_seconds", "wall_seconds")
|
| 93 |
+
for path in sorted((log_directory()/run).glob("*.jsonl")):
|
| 94 |
+
started = finished = 0
|
| 95 |
+
for event in rows(path):
|
| 96 |
+
if event["event"] == "prompts":
|
| 97 |
+
started += 1
|
| 98 |
+
elif event["event"] == "outputs":
|
| 99 |
+
finished += 1
|
| 100 |
+
counts = totals.setdefault(event["role"], dict.fromkeys(fields, 0))
|
| 101 |
+
for field in fields:
|
| 102 |
+
counts[field] += event[field]
|
| 103 |
+
unfinished += max(0, started-finished)
|
| 104 |
+
return dict(usage=totals or fallback, unfinished_generation_batches=unfinished)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
class Journal:
|
| 108 |
"""Mirror complete public model inputs and outputs to a timestamped log and terminal."""
|
| 109 |
|
| 110 |
def __init__(self, run):
|
| 111 |
self.run = run
|
| 112 |
self.path = log_directory() / run / (stamp().replace(":", "-") + ".jsonl")
|
| 113 |
+
# A redirected Windows console can default to CP1252. Keep the terminal and UTF-8 file faithful.
|
| 114 |
+
if hasattr(sys.stdout,"reconfigure") and (sys.stdout.encoding or "").lower().replace("-","") != "utf8":
|
| 115 |
+
sys.stdout.reconfigure(encoding="utf-8")
|
| 116 |
|
| 117 |
def event(self, event, **values):
|
| 118 |
record = {"time": stamp(), "run": self.run, "event": event, **values}
|
src/study/training.py
CHANGED
|
@@ -19,7 +19,7 @@ from .design import matrix, permute_groups
|
|
| 19 |
from .domain import Problem, problems
|
| 20 |
from .judging import chain, make_example, majority, votes
|
| 21 |
from .records import approval, expected, solver_truth, sound, terminal
|
| 22 |
-
from .storage import RESULTS, STATE, Journal, adapter, append, read_json, retain, rows, stamp, write_json
|
| 23 |
|
| 24 |
|
| 25 |
def frozen_sources(run):
|
|
@@ -208,7 +208,7 @@ def train(run, steps):
|
|
| 208 |
raise RuntimeError("Frozen judge adapter changed during optimization")
|
| 209 |
backend.model.save_pretrained(adapter(run.name), selected_adapters=["default"])
|
| 210 |
result = dict(time=stamp(), run=asdict(run), updates=trainer.state.global_step,
|
| 211 |
-
elapsed_seconds=elapsed, resumed_at=last_step, frozen_checksum=after,
|
| 212 |
if run.name == "timing":
|
| 213 |
record_timing_budget(result)
|
| 214 |
write_json(out / "trained.json", result)
|
|
|
|
| 19 |
from .domain import Problem, problems
|
| 20 |
from .judging import chain, make_example, majority, votes
|
| 21 |
from .records import approval, expected, solver_truth, sound, terminal
|
| 22 |
+
from .storage import RESULTS, STATE, Journal, adapter, append, generation_cost, read_json, retain, rows, stamp, write_json
|
| 23 |
|
| 24 |
|
| 25 |
def frozen_sources(run):
|
|
|
|
| 208 |
raise RuntimeError("Frozen judge adapter changed during optimization")
|
| 209 |
backend.model.save_pretrained(adapter(run.name), selected_adapters=["default"])
|
| 210 |
result = dict(time=stamp(), run=asdict(run), updates=trainer.state.global_step,
|
| 211 |
+
elapsed_seconds=elapsed, resumed_at=last_step, frozen_checksum=after, **generation_cost(run.name,backend.totals))
|
| 212 |
if run.name == "timing":
|
| 213 |
record_timing_budget(result)
|
| 214 |
write_json(out / "trained.json", result)
|
tests/test_storage.py
CHANGED
|
@@ -11,8 +11,36 @@ def test_torn_unicode_record_is_repaired_before_the_next_observation(tmp_path):
|
|
| 11 |
assert list(rows(path))==[{"sample":"first"}]
|
| 12 |
append(path,{"sample":"next"})
|
| 13 |
assert list(rows(path))==[{"sample":"first"},{"sample":"next"}]
|
|
|
|
|
|
|
| 14 |
def test_published_text_uses_git_line_endings(tmp_path):
|
| 15 |
from study.storage import atomic
|
| 16 |
target = tmp_path / "receipt.json"
|
| 17 |
atomic(target, "first\nsecond\n")
|
| 18 |
assert target.read_bytes() == b"first\nsecond\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
assert list(rows(path))==[{"sample":"first"}]
|
| 12 |
append(path,{"sample":"next"})
|
| 13 |
assert list(rows(path))==[{"sample":"first"},{"sample":"next"}]
|
| 14 |
+
|
| 15 |
+
|
| 16 |
def test_published_text_uses_git_line_endings(tmp_path):
|
| 17 |
from study.storage import atomic
|
| 18 |
target = tmp_path / "receipt.json"
|
| 19 |
atomic(target, "first\nsecond\n")
|
| 20 |
assert target.read_bytes() == b"first\nsecond\n"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_redirected_windows_terminal_preserves_model_unicode(tmp_path):
|
| 24 |
+
import os
|
| 25 |
+
import subprocess
|
| 26 |
+
import sys
|
| 27 |
+
|
| 28 |
+
program = "from study.storage import Journal; Journal('utf8').event('output_chunk',text=chr(0x2212))"
|
| 29 |
+
result = subprocess.run([sys.executable,"-c",program],cwd=tmp_path,capture_output=True,
|
| 30 |
+
env={**os.environ,"PYTHONIOENCODING":"cp1252"},check=True)
|
| 31 |
+
assert "−" in result.stdout.decode("utf-8")
|
| 32 |
+
log = next((tmp_path/"logs/utf8").glob("*.jsonl"))
|
| 33 |
+
assert next(rows(log))["text"]=="−"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_generation_cost_includes_completed_attempts_before_evaluation_resume(tmp_path,monkeypatch):
|
| 37 |
+
from study import storage
|
| 38 |
+
monkeypatch.setattr(storage,"ROOT",tmp_path)
|
| 39 |
+
for name in ("first","resumed"):
|
| 40 |
+
path=tmp_path/"logs/run"/(name+".jsonl")
|
| 41 |
+
append(path, dict(event="prompts",role="j3"))
|
| 42 |
+
append(path, dict(event="outputs",role="j3",calls=8,input_tokens=20,output_tokens=16,gpu_seconds=4,wall_seconds=5))
|
| 43 |
+
append(tmp_path/"logs/run/first.jsonl",dict(event="prompts",role="j3"))
|
| 44 |
+
cost=storage.generation_cost("run",{})
|
| 45 |
+
assert cost["usage"]["j3"]==dict(calls=16,input_tokens=40,output_tokens=32,gpu_seconds=8,wall_seconds=10)
|
| 46 |
+
assert cost["unfinished_generation_batches"]==1
|