auto-sync 2026-07-04T04:28:21Z workspace (part 7)
Browse files
workspace/scripts/build_ctt_rollout_comparison.py
CHANGED
|
@@ -35,6 +35,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 35 |
parser.add_argument("--out-dir", type=Path, default=Path("runs/ctt_val_rollout_comparison"))
|
| 36 |
parser.add_argument("--k", type=int, default=8)
|
| 37 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
args = parser.parse_args(argv)
|
| 39 |
|
| 40 |
run_dirs = [
|
|
@@ -75,24 +80,29 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 75 |
}
|
| 76 |
combined_path = out_dir / "combined_measured_candidates.json"
|
| 77 |
combined_path.write_text(json.dumps(combined, indent=2, sort_keys=True) + "\n")
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 92 |
metrics = json.loads((out_dir / "measured_metrics" / "metrics.json").read_text())
|
| 93 |
(out_dir / "metrics.json").write_text(json.dumps(_summary_payload(combined, metrics), indent=2, sort_keys=True) + "\n")
|
| 94 |
(out_dir / "table.tex").write_text((out_dir / "measured_metrics" / "table.tex").read_text())
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
for filename in ("metrics_by_task.json", "metrics_by_seed.json"):
|
| 97 |
shutil.copyfile(out_dir / "measured_metrics" / filename, out_dir / filename)
|
| 98 |
(out_dir / "command.txt").write_text(
|
|
|
|
| 35 |
parser.add_argument("--out-dir", type=Path, default=Path("runs/ctt_val_rollout_comparison"))
|
| 36 |
parser.add_argument("--k", type=int, default=8)
|
| 37 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
| 38 |
+
parser.add_argument(
|
| 39 |
+
"--no-markdown-report",
|
| 40 |
+
action="store_true",
|
| 41 |
+
help="Do not write report.md; persistent prose lives in README.md.",
|
| 42 |
+
)
|
| 43 |
args = parser.parse_args(argv)
|
| 44 |
|
| 45 |
run_dirs = [
|
|
|
|
| 80 |
}
|
| 81 |
combined_path = out_dir / "combined_measured_candidates.json"
|
| 82 |
combined_path.write_text(json.dumps(combined, indent=2, sort_keys=True) + "\n")
|
| 83 |
+
metric_args = [
|
| 84 |
+
"--input",
|
| 85 |
+
str(combined_path),
|
| 86 |
+
"--out-dir",
|
| 87 |
+
str(out_dir / "measured_metrics"),
|
| 88 |
+
"--mode",
|
| 89 |
+
"measured",
|
| 90 |
+
"--k",
|
| 91 |
+
str(args.k),
|
| 92 |
+
"--bootstrap-samples",
|
| 93 |
+
str(args.bootstrap_samples),
|
| 94 |
+
]
|
| 95 |
+
if args.no_markdown_report:
|
| 96 |
+
metric_args.append("--no-markdown-report")
|
| 97 |
+
eval_metrics_main(metric_args)
|
| 98 |
metrics = json.loads((out_dir / "measured_metrics" / "metrics.json").read_text())
|
| 99 |
(out_dir / "metrics.json").write_text(json.dumps(_summary_payload(combined, metrics), indent=2, sort_keys=True) + "\n")
|
| 100 |
(out_dir / "table.tex").write_text((out_dir / "measured_metrics" / "table.tex").read_text())
|
| 101 |
+
report_path = out_dir / "report.md"
|
| 102 |
+
if args.no_markdown_report:
|
| 103 |
+
report_path.unlink(missing_ok=True)
|
| 104 |
+
else:
|
| 105 |
+
report_path.write_text(_report(combined, metrics) + "\n")
|
| 106 |
for filename in ("metrics_by_task.json", "metrics_by_seed.json"):
|
| 107 |
shutil.copyfile(out_dir / "measured_metrics" / filename, out_dir / filename)
|
| 108 |
(out_dir / "command.txt").write_text(
|
workspace/scripts/eval_ctt_generated_rollout.py
CHANGED
|
@@ -130,6 +130,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 130 |
)
|
| 131 |
parser.add_argument("--skip-metrics", action="store_true")
|
| 132 |
parser.add_argument("--bootstrap-samples", type=int, default=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
args = parser.parse_args(argv)
|
| 134 |
|
| 135 |
if args.k <= 0:
|
|
@@ -296,24 +301,29 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 296 |
}
|
| 297 |
measured_path = out_dir / "measured_candidates.json"
|
| 298 |
measured_path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n")
|
| 299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
metrics_dir = out_dir / "measured_metrics"
|
| 302 |
if not args.skip_metrics:
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
| 317 |
_write_required_artifacts(
|
| 318 |
out_dir,
|
| 319 |
payload,
|
|
|
|
| 130 |
)
|
| 131 |
parser.add_argument("--skip-metrics", action="store_true")
|
| 132 |
parser.add_argument("--bootstrap-samples", type=int, default=200)
|
| 133 |
+
parser.add_argument(
|
| 134 |
+
"--no-markdown-report",
|
| 135 |
+
action="store_true",
|
| 136 |
+
help="Do not write report.md files; persistent prose lives in README.md.",
|
| 137 |
+
)
|
| 138 |
args = parser.parse_args(argv)
|
| 139 |
|
| 140 |
if args.k <= 0:
|
|
|
|
| 301 |
}
|
| 302 |
measured_path = out_dir / "measured_candidates.json"
|
| 303 |
measured_path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n")
|
| 304 |
+
report_path = out_dir / "report.md"
|
| 305 |
+
if args.no_markdown_report:
|
| 306 |
+
report_path.unlink(missing_ok=True)
|
| 307 |
+
else:
|
| 308 |
+
report_path.write_text(_report(payload) + "\n")
|
| 309 |
|
| 310 |
metrics_dir = out_dir / "measured_metrics"
|
| 311 |
if not args.skip_metrics:
|
| 312 |
+
metric_args = [
|
| 313 |
+
"--input",
|
| 314 |
+
str(measured_path),
|
| 315 |
+
"--out-dir",
|
| 316 |
+
str(metrics_dir),
|
| 317 |
+
"--mode",
|
| 318 |
+
"measured",
|
| 319 |
+
"--k",
|
| 320 |
+
str(args.k),
|
| 321 |
+
"--bootstrap-samples",
|
| 322 |
+
str(args.bootstrap_samples),
|
| 323 |
+
]
|
| 324 |
+
if args.no_markdown_report:
|
| 325 |
+
metric_args.append("--no-markdown-report")
|
| 326 |
+
eval_metrics_main(metric_args)
|
| 327 |
_write_required_artifacts(
|
| 328 |
out_dir,
|
| 329 |
payload,
|
workspace/scripts/eval_ctt_rollout.py
CHANGED
|
@@ -25,24 +25,30 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 25 |
parser.add_argument("--k", type=int, default=16)
|
| 26 |
parser.add_argument("--epsilon", type=float, default=0.0)
|
| 27 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
args = parser.parse_args(argv)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
|
|
|
| 25 |
parser.add_argument("--k", type=int, default=16)
|
| 26 |
parser.add_argument("--epsilon", type=float, default=0.0)
|
| 27 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
| 28 |
+
parser.add_argument(
|
| 29 |
+
"--no-markdown-report",
|
| 30 |
+
action="store_true",
|
| 31 |
+
help="Do not write report.md in the metric output directory.",
|
| 32 |
+
)
|
| 33 |
args = parser.parse_args(argv)
|
| 34 |
|
| 35 |
+
forwarded = [
|
| 36 |
+
"--input",
|
| 37 |
+
str(args.measured_candidates),
|
| 38 |
+
"--out-dir",
|
| 39 |
+
str(args.out_dir),
|
| 40 |
+
"--mode",
|
| 41 |
+
"measured",
|
| 42 |
+
"--k",
|
| 43 |
+
str(args.k),
|
| 44 |
+
"--epsilon",
|
| 45 |
+
str(args.epsilon),
|
| 46 |
+
"--bootstrap-samples",
|
| 47 |
+
str(args.bootstrap_samples),
|
| 48 |
+
]
|
| 49 |
+
if args.no_markdown_report:
|
| 50 |
+
forwarded.append("--no-markdown-report")
|
| 51 |
+
return eval_metrics_main(forwarded)
|
| 52 |
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
workspace/scripts/eval_dominance_selector.py
CHANGED
|
@@ -69,6 +69,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 69 |
)
|
| 70 |
parser.add_argument("--k", type=int, default=8)
|
| 71 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
args = parser.parse_args(argv)
|
| 73 |
|
| 74 |
if not 0.0 < args.alpha < 1.0:
|
|
@@ -190,7 +195,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 190 |
+ "\n"
|
| 191 |
)
|
| 192 |
(out_dir / "table.tex").write_text(_table(metrics) + "\n")
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
(out_dir / "train.log").write_text(
|
| 195 |
"fit conformal residual quantile and tau on calibration measured rows only\n"
|
| 196 |
f"calibration_input={args.calibration_input}\n"
|
|
|
|
| 69 |
)
|
| 70 |
parser.add_argument("--k", type=int, default=8)
|
| 71 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
| 72 |
+
parser.add_argument(
|
| 73 |
+
"--no-markdown-report",
|
| 74 |
+
action="store_true",
|
| 75 |
+
help="Do not write report.md; persistent prose lives in README.md.",
|
| 76 |
+
)
|
| 77 |
args = parser.parse_args(argv)
|
| 78 |
|
| 79 |
if not 0.0 < args.alpha < 1.0:
|
|
|
|
| 195 |
+ "\n"
|
| 196 |
)
|
| 197 |
(out_dir / "table.tex").write_text(_table(metrics) + "\n")
|
| 198 |
+
report_path = out_dir / "report.md"
|
| 199 |
+
if args.no_markdown_report:
|
| 200 |
+
report_path.unlink(missing_ok=True)
|
| 201 |
+
else:
|
| 202 |
+
report_path.write_text(_report(metrics) + "\n")
|
| 203 |
(out_dir / "train.log").write_text(
|
| 204 |
"fit conformal residual quantile and tau on calibration measured rows only\n"
|
| 205 |
f"calibration_input={args.calibration_input}\n"
|
workspace/scripts/eval_metrics.py
CHANGED
|
@@ -2,8 +2,10 @@
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
import argparse
|
|
|
|
| 5 |
import json
|
| 6 |
import math
|
|
|
|
| 7 |
import sys
|
| 8 |
from collections import defaultdict
|
| 9 |
from pathlib import Path
|
|
@@ -52,6 +54,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 52 |
parser.add_argument("--thresholds", default="0.20,0.40")
|
| 53 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
| 54 |
parser.add_argument("--confidence", type=float, default=0.95)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
args = parser.parse_args(argv)
|
| 56 |
|
| 57 |
if args.k <= 0:
|
|
@@ -119,7 +126,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 119 |
+ "\n"
|
| 120 |
)
|
| 121 |
(out_dir / "table.tex").write_text(_latex_table(summary) + "\n")
|
| 122 |
-
(out_dir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
print(json.dumps({"out_dir": str(out_dir), "num_rows": len(metric_rows)}, indent=2))
|
| 124 |
return 0
|
| 125 |
|
|
@@ -435,6 +447,98 @@ def _group_means(
|
|
| 435 |
return output
|
| 436 |
|
| 437 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
def _latex_table(summary: dict[str, Any]) -> str:
|
| 439 |
lines = [
|
| 440 |
"% Auto-generated by scripts/eval_metrics.py",
|
|
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
import argparse
|
| 5 |
+
import hashlib
|
| 6 |
import json
|
| 7 |
import math
|
| 8 |
+
import subprocess
|
| 9 |
import sys
|
| 10 |
from collections import defaultdict
|
| 11 |
from pathlib import Path
|
|
|
|
| 54 |
parser.add_argument("--thresholds", default="0.20,0.40")
|
| 55 |
parser.add_argument("--bootstrap-samples", type=int, default=1000)
|
| 56 |
parser.add_argument("--confidence", type=float, default=0.95)
|
| 57 |
+
parser.add_argument(
|
| 58 |
+
"--no-markdown-report",
|
| 59 |
+
action="store_true",
|
| 60 |
+
help="Do not write report.md; use this when README.md is the only persistent Markdown file.",
|
| 61 |
+
)
|
| 62 |
args = parser.parse_args(argv)
|
| 63 |
|
| 64 |
if args.k <= 0:
|
|
|
|
| 126 |
+ "\n"
|
| 127 |
)
|
| 128 |
(out_dir / "table.tex").write_text(_latex_table(summary) + "\n")
|
| 129 |
+
_write_run_metadata(out_dir, args, payload, metric_names)
|
| 130 |
+
report_path = out_dir / "report.md"
|
| 131 |
+
if args.no_markdown_report:
|
| 132 |
+
report_path.unlink(missing_ok=True)
|
| 133 |
+
else:
|
| 134 |
+
report_path.write_text(_markdown_report(args.mode, args.k, summary) + "\n")
|
| 135 |
print(json.dumps({"out_dir": str(out_dir), "num_rows": len(metric_rows)}, indent=2))
|
| 136 |
return 0
|
| 137 |
|
|
|
|
| 447 |
return output
|
| 448 |
|
| 449 |
|
| 450 |
+
def _write_run_metadata(
|
| 451 |
+
out_dir: Path,
|
| 452 |
+
args: argparse.Namespace,
|
| 453 |
+
input_payload: Any,
|
| 454 |
+
metric_names: list[str],
|
| 455 |
+
) -> None:
|
| 456 |
+
data_hash = _payload_hash(input_payload)
|
| 457 |
+
split_hash = _extract_hash(
|
| 458 |
+
input_payload,
|
| 459 |
+
(
|
| 460 |
+
"split_hash",
|
| 461 |
+
"target_split_hash",
|
| 462 |
+
"eval_target_split_hash",
|
| 463 |
+
"selector_split_hash",
|
| 464 |
+
),
|
| 465 |
+
)
|
| 466 |
+
if split_hash is None:
|
| 467 |
+
split_hash = data_hash
|
| 468 |
+
|
| 469 |
+
(out_dir / "config.yaml").write_text(
|
| 470 |
+
"\n".join(
|
| 471 |
+
[
|
| 472 |
+
f"input: {args.input}",
|
| 473 |
+
f"mode: {args.mode}",
|
| 474 |
+
f"k: {args.k}",
|
| 475 |
+
f"epsilon: {args.epsilon}",
|
| 476 |
+
f"thresholds: {args.thresholds}",
|
| 477 |
+
f"bootstrap_samples: {args.bootstrap_samples}",
|
| 478 |
+
f"confidence: {args.confidence}",
|
| 479 |
+
f"no_markdown_report: {bool(args.no_markdown_report)}",
|
| 480 |
+
"metric_names:",
|
| 481 |
+
*[f" - {name}" for name in metric_names],
|
| 482 |
+
]
|
| 483 |
+
)
|
| 484 |
+
+ "\n"
|
| 485 |
+
)
|
| 486 |
+
(out_dir / "command.txt").write_text(
|
| 487 |
+
"python scripts/eval_metrics.py " + " ".join(sys.argv[1:]) + "\n"
|
| 488 |
+
)
|
| 489 |
+
(out_dir / "git_hash.txt").write_text(_git_hash() + "\n")
|
| 490 |
+
(out_dir / "data_hash.txt").write_text(data_hash + "\n")
|
| 491 |
+
(out_dir / "split_hash.txt").write_text(split_hash + "\n")
|
| 492 |
+
(out_dir / "train.log").write_text("metric evaluation artifact; no training\n")
|
| 493 |
+
(out_dir / "eval.log").write_text(
|
| 494 |
+
"\n".join(
|
| 495 |
+
[
|
| 496 |
+
f"input={args.input}",
|
| 497 |
+
f"mode={args.mode}",
|
| 498 |
+
f"k={args.k}",
|
| 499 |
+
f"num_metrics={len(metric_names)}",
|
| 500 |
+
f"markdown_report_written={not bool(args.no_markdown_report)}",
|
| 501 |
+
]
|
| 502 |
+
)
|
| 503 |
+
+ "\n"
|
| 504 |
+
)
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
def _payload_hash(payload: Any) -> str:
|
| 508 |
+
blob = json.dumps(payload, sort_keys=True, separators=(",", ":"), default=str).encode()
|
| 509 |
+
return hashlib.sha256(blob).hexdigest()
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
def _extract_hash(payload: Any, keys: tuple[str, ...]) -> str | None:
|
| 513 |
+
if isinstance(payload, dict):
|
| 514 |
+
for key in keys:
|
| 515 |
+
value = payload.get(key)
|
| 516 |
+
if isinstance(value, str) and value.strip():
|
| 517 |
+
return value.strip()
|
| 518 |
+
for value in payload.values():
|
| 519 |
+
nested = _extract_hash(value, keys)
|
| 520 |
+
if nested is not None:
|
| 521 |
+
return nested
|
| 522 |
+
elif isinstance(payload, list):
|
| 523 |
+
for value in payload:
|
| 524 |
+
nested = _extract_hash(value, keys)
|
| 525 |
+
if nested is not None:
|
| 526 |
+
return nested
|
| 527 |
+
return None
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
def _git_hash() -> str:
|
| 531 |
+
try:
|
| 532 |
+
return subprocess.check_output(
|
| 533 |
+
["git", "rev-parse", "HEAD"],
|
| 534 |
+
cwd=PROJECT_ROOT,
|
| 535 |
+
text=True,
|
| 536 |
+
stderr=subprocess.DEVNULL,
|
| 537 |
+
).strip()
|
| 538 |
+
except (OSError, subprocess.CalledProcessError):
|
| 539 |
+
return "unknown"
|
| 540 |
+
|
| 541 |
+
|
| 542 |
def _latex_table(summary: dict[str, Any]) -> str:
|
| 543 |
lines = [
|
| 544 |
"% Auto-generated by scripts/eval_metrics.py",
|