Spaces:
Running
Running
File size: 2,623 Bytes
5063745 5fe63cd 5063745 5fe63cd 5063745 5fe63cd 5063745 5fe63cd 5063745 5fe63cd 5063745 5fe63cd 5063745 5fe63cd 5063745 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #!/usr/bin/env python3
"""Local 1-hour loop: run eval locally, then push results to HF Space."""
from __future__ import annotations
import argparse
import logging
import os
import subprocess
import sys
import time
from pathlib import Path
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
logger = logging.getLogger(__name__)
SPACE_ROOT = Path(__file__).resolve().parents[1]
EVAL_SCRIPT = SPACE_ROOT / "scripts" / "run_space_eval.py"
PUSH_SCRIPT = SPACE_ROOT / "scripts" / "push_results_to_hf.py"
DEFAULT_INTERVAL_SECONDS = int(
os.getenv(
"TSFM_BENCH_INTERVAL_SECONDS",
os.getenv("TSFM_EVAL_INTERVAL_SECONDS", "3600"),
)
)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--interval-minutes",
type=int,
default=max(1, DEFAULT_INTERVAL_SECONDS // 60),
help="Minutes between collect + eval + push cycles (default: 60)",
)
parser.add_argument(
"--once",
action="store_true",
help="Run a single evaluation (+ push) and exit",
)
parser.add_argument(
"--no-push",
action="store_true",
help="Skip pushing results to Hugging Face",
)
parser.add_argument(
"--hf-endpoint",
default=os.getenv("HF_ENDPOINT", "https://huggingface.co"),
help="HF API endpoint for upload",
)
return parser.parse_args()
def run_eval() -> int:
cmd = [sys.executable, str(EVAL_SCRIPT)]
logger.info("Running: %s", " ".join(cmd))
return subprocess.run(cmd, cwd=str(SPACE_ROOT), check=False).returncode
def push_results(endpoint: str) -> int:
cmd = [
sys.executable,
str(PUSH_SCRIPT),
"--endpoint",
endpoint,
]
logger.info("Pushing results to HF Space")
return subprocess.run(cmd, cwd=str(SPACE_ROOT), check=False).returncode
def run_cycle(args: argparse.Namespace) -> int:
code = run_eval()
if code != 0:
logger.error("Evaluation failed with exit code %s", code)
return code
if args.no_push:
return 0
push_code = push_results(args.hf_endpoint)
if push_code != 0:
logger.error("HF push failed with exit code %s", push_code)
return push_code
def main() -> None:
args = parse_args()
if args.once:
raise SystemExit(run_cycle(args))
while True:
run_cycle(args)
logger.info("Sleeping %s minutes until next cycle", args.interval_minutes)
time.sleep(args.interval_minutes * 60)
if __name__ == "__main__":
main()
|