Freeze GINO two-keyword patch, CPU acceptance and runtime prerequisite

This commit is contained in:
NewMeltAssist committed 2026-11-19 14:50:32 +08:00
1 parent 1a9ebf278f
commit fa95ea8251
12 files changed
+2002

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
"""Add the reviewed CPU acceptance prerequisite to the fixed measurement entry."""
import argparse
import fcntl
from pathlib import Path
import os
import signal
from types import FunctionType
import track_b_gino_shapenet_entry as legacy
from track_b_gino_paper_keyword_patch import patch_identity
from track_b_gino_shapenet_entry import checked, read, save, sha, process_identity
ROOT = legacy.MEASUREMENT_ROOT.with_name("track-b-gino-shapenet611-import-checked-2026-11-19")
ORIGINAL_CONTRACT = "139fec49b7e4627b55ad12f3a129bec75ecc2446811c23a24f376dae207094aa"
WORKER = Path(__file__).with_name("track_b_gino_import_checked_worker.py").resolve()
def contract(path):
c = legacy.contract(path)
if c["mode"] != "measurement" or c["environment_ruling"] != "h-0d21f3bd":
raise PermissionError("Only the reviewed measurement environment delta is supported")
return c
def accepted_environment(c):
patch = patch_identity(c)
pin = c["environment_acceptance"]
receipt = read(checked(pin["path"], pin["sha256"]))
python = Path(c["environment"]["python"])
cfg = python.parent.parent / "pyvenv.cfg"
if (receipt["status"] != "PASS" or receipt["environment_ruling"] != c["environment_ruling"]
or receipt["original_contract_sha256"] != ORIGINAL_CONTRACT
or receipt["comparison_contract_sha256"] != c["comparison_contract_sha256"]
or receipt["paper_compatibility"] != c["paper_compatibility"]
or receipt["patched_decoder_file_sha256"] != patch["patched_file_sha256"]
or receipt["cuda_visible_devices"] != "" or receipt["scientific_training"] is not False
or receipt["heldout_target_reads"] != 0 or receipt["paper_decoder_cpu_forward"] is not True
or receipt["paper_loader_learning_only"] is not True or receipt["paper_metric_cpu"] is not True
or receipt["audited_learning_cases"] != [c["split"]["train"][0]]
or receipt["package_versions"] != c["environment"]["package_versions"]
or receipt["neuralop_commit"] != c["environment"]["neuralop_commit"]
or receipt["torch_cuda_build"] != c["environment"]["torch_cuda"]
or receipt["interpreter_path"] != str(python)
or receipt["interpreter_resolved_path"] != str(python.resolve(strict=True))
or receipt["interpreter_sha256"] != sha(python)
or receipt["pyvenv_cfg_sha256"] != sha(cfg)
or not os.access(python, os.X_OK)):
raise PermissionError("Matching CPU acceptance and isolated interpreter are required")
return receipt
def dispatch_guard(root, path):
def supervise(command, *args, **kwargs):
if Path(command[1]).name != "track_b_gino_shapenet_worker.py":
raise RuntimeError("Unexpected source worker route")
# The original guard's monitor closes over this exact command list.
# Select the checked wrapper before the shared supervisor can spawn.
command[1] = str(WORKER)
return legacy.supervise(command, *args, **kwargs)
namespace = dict(legacy.dispatch_guard.__globals__, contract=contract, supervise=supervise)
return FunctionType(legacy.dispatch_guard.__code__, namespace, legacy.dispatch_guard.__name__)(root, path)
def authorized_child(root):
root = Path(root).resolve()
if root != ROOT:
raise PermissionError("Only the new fixed measurement root")
c = contract(root / "contract.json")
accepted_environment(c)
namespace = dict(legacy.authorized_child.__globals__, MEASUREMENT_ROOT=ROOT, contract=contract)
return FunctionType(legacy.authorized_child.__code__, namespace, legacy.authorized_child.__name__)(root)
def run(root):
root = Path(root).resolve()
if root != ROOT:
raise PermissionError("Only the new fixed measurement root")
path = root / "contract.json"
c = contract(path)
accepted_environment(c)
legacy.validate_review(root)
authorization = read(root / "stage-authorization.json")
if (authorization["contract_sha256"] != sha(path) or authorization["decision"] != "APPROVED"
or authorization["mode"] != "measurement"):
raise PermissionError("Exact stage authorization is required")
with (root / "entry.lock").open("a") as lock:
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
if (root / "started.json").exists() or (legacy.MEASUREMENT_ROOT / "started.json").exists():
raise FileExistsError("The measurement attempt already has a start record")
environment = accepted_environment(c)
save(root / "started.json", dict(
coordinator=process_identity(os.getpid()), contract_sha256=sha(path),
cpu_acceptance_sha256=c["environment_acceptance"]["sha256"],
interpreter_path=environment["interpreter_path"], interpreter_sha256=environment["interpreter_sha256"]))
def request_stop(signum, _frame):
raise KeyboardInterrupt(signal.Signals(signum).name)
handler = signal.signal(signal.SIGTERM, request_stop)
try:
return dispatch_guard(root, path)
finally:
signal.signal(signal.SIGTERM, handler)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("root", type=Path)
args = parser.parse_args()
raise SystemExit(run(args.root))