ziyuzhou02 commited on
Commit
5fe63cd
·
verified ·
1 Parent(s): 5936e76

UI-only mode: update scripts/run_online_daemon.py

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