Fingerprint Frontier source snapshots
This commit is contained in:
@@ -90,7 +90,36 @@ def sha256_bytes(payload: bytes) -> str:
|
|||||||
return hashlib.sha256(payload).hexdigest()
|
return hashlib.sha256(payload).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def frontier_source_fingerprint(source: Path) -> dict[str, Any]:
|
def frontier_source_fingerprint(
|
||||||
|
source: Path, declared_commit: str
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
model_config = source / "data" / "config" / "models" / f"{MODEL}.json"
|
||||||
|
if not model_config.is_file():
|
||||||
|
raise FileNotFoundError(f"Frontier model config is missing: {model_config}")
|
||||||
|
device_config = source / "data" / "config" / "device" / "h20.json"
|
||||||
|
files = sorted((source / "frontier").glob("**/*.py")) + [
|
||||||
|
model_config,
|
||||||
|
device_config,
|
||||||
|
]
|
||||||
|
missing = [str(path) for path in files if not path.is_file()]
|
||||||
|
if missing:
|
||||||
|
raise FileNotFoundError(f"Frontier fingerprint inputs are missing: {missing}")
|
||||||
|
digest = hashlib.sha256()
|
||||||
|
for path in files:
|
||||||
|
relative = path.relative_to(source).as_posix()
|
||||||
|
digest.update(relative.encode() + b"\0")
|
||||||
|
digest.update(bytes.fromhex(sha256(path)))
|
||||||
|
fingerprint = {
|
||||||
|
"declared_upstream_commit": declared_commit,
|
||||||
|
"python_and_config_tree_sha256": digest.hexdigest(),
|
||||||
|
"fingerprinted_file_count": len(files),
|
||||||
|
"model_config": {
|
||||||
|
"path": str(model_config.resolve()),
|
||||||
|
"sha256": sha256(model_config),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
git_dir = source / ".git"
|
||||||
|
if git_dir.exists():
|
||||||
commit = subprocess.run(
|
commit = subprocess.run(
|
||||||
["git", "rev-parse", "HEAD"],
|
["git", "rev-parse", "HEAD"],
|
||||||
cwd=source,
|
cwd=source,
|
||||||
@@ -111,18 +140,16 @@ def frontier_source_fingerprint(source: Path) -> dict[str, Any]:
|
|||||||
check=True,
|
check=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
).stdout
|
).stdout
|
||||||
model_config = source / "data" / "config" / "models" / f"{MODEL}.json"
|
fingerprint.update(
|
||||||
if not model_config.is_file():
|
{
|
||||||
raise FileNotFoundError(f"Frontier model config is missing: {model_config}")
|
"git_commit": commit,
|
||||||
return {
|
|
||||||
"commit": commit,
|
|
||||||
"status_porcelain": status.splitlines(),
|
"status_porcelain": status.splitlines(),
|
||||||
"tracked_diff_sha256": sha256_bytes(diff),
|
"tracked_diff_sha256": sha256_bytes(diff),
|
||||||
"model_config": {
|
|
||||||
"path": str(model_config.resolve()),
|
|
||||||
"sha256": sha256(model_config),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
fingerprint["git_metadata"] = "absent_source_snapshot"
|
||||||
|
return fingerprint
|
||||||
|
|
||||||
|
|
||||||
def anchor_key(anchor: float) -> str:
|
def anchor_key(anchor: float) -> str:
|
||||||
@@ -550,7 +577,9 @@ def run_grid(args: argparse.Namespace) -> None:
|
|||||||
"frontier": {
|
"frontier": {
|
||||||
"source": str(args.frontier_source.resolve()),
|
"source": str(args.frontier_source.resolve()),
|
||||||
"python": str(args.python.resolve()),
|
"python": str(args.python.resolve()),
|
||||||
"fingerprint": frontier_source_fingerprint(args.frontier_source),
|
"fingerprint": frontier_source_fingerprint(
|
||||||
|
args.frontier_source, args.frontier_commit
|
||||||
|
),
|
||||||
},
|
},
|
||||||
"trace_manifest": {
|
"trace_manifest": {
|
||||||
"path": str(args.trace_manifest.resolve()),
|
"path": str(args.trace_manifest.resolve()),
|
||||||
@@ -675,6 +704,10 @@ def parse_args() -> argparse.Namespace:
|
|||||||
|
|
||||||
run = subparsers.add_parser("run")
|
run = subparsers.add_parser("run")
|
||||||
run.add_argument("--frontier-source", type=Path, required=True)
|
run.add_argument("--frontier-source", type=Path, required=True)
|
||||||
|
run.add_argument(
|
||||||
|
"--frontier-commit",
|
||||||
|
default="d9cfeb6d8791fbf2f295dd9744c56a666171776e",
|
||||||
|
)
|
||||||
run.add_argument("--python", type=Path, required=True)
|
run.add_argument("--python", type=Path, required=True)
|
||||||
run.add_argument("--profile-root", type=Path, required=True)
|
run.add_argument("--profile-root", type=Path, required=True)
|
||||||
run.add_argument("--trace-manifest", type=Path, required=True)
|
run.add_argument("--trace-manifest", type=Path, required=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user