baseball-engine / tools /register_sam_api_worker.py
github-actions[bot]
Automated Deploy: 006019bfd20b8e3208f90c1e8c91601248bd7447
3192171
Raw History Blame Contribute Delete
1.31 kB
"""Register installed SAM runtime/assets without downloading or loading weights."""
import argparse
from pathlib import Path
import subprocess
from baseball_batting.storage import atomic_json, sha256_file
from tools.setup_full_worker import SAM_REVISION
def main():
parser = argparse.ArgumentParser()
for argument in ("worker-python", "sam-repo", "sam-checkpoint", "sam-config", "mhr-path", "output"):
parser.add_argument("--"+argument, required=True)
args = parser.parse_args()
record = {key: str(Path(getattr(args, key)).resolve()) for key in
("worker_python", "sam_repo", "sam_checkpoint", "sam_config", "mhr_path")}
if not all(Path(value).exists() for value in record.values()): raise ValueError("Configured SAM files are missing")
revision = subprocess.check_output(["git", "-C", record["sam_repo"], "rev-parse", "HEAD"], text=True).strip()
if revision != SAM_REVISION: raise ValueError("SAM source revision differs from pinned adapter")
record.update(source_revision=revision, status="installed_requires_inference",
artifact_hashes={key: sha256_file(record[key]) for key in ("sam_checkpoint", "sam_config", "mhr_path")})
atomic_json(args.output, record)
print("Registered SAM:", args.output)
if __name__ == "__main__": main()