Spaces:
Sleeping
Sleeping
Upload runner.py with huggingface_hub
Browse files
runner.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# /// script
|
| 3 |
+
# requires-python = ">=3.10"
|
| 4 |
+
# dependencies = [
|
| 5 |
+
# "inspect-ai",
|
| 6 |
+
# "datasets",
|
| 7 |
+
# "openai",
|
| 8 |
+
# "transformers",
|
| 9 |
+
# "accelerate",
|
| 10 |
+
# "huggingface_hub",
|
| 11 |
+
# "inspect_evals",
|
| 12 |
+
# ]
|
| 13 |
+
# ///
|
| 14 |
+
"""Runner that downloads an eval script and executes it using inspect CLI with HF filesystem logging."""
|
| 15 |
+
|
| 16 |
+
import os
|
| 17 |
+
import sys
|
| 18 |
+
import subprocess
|
| 19 |
+
import urllib.request
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
if len(sys.argv) < 4:
|
| 24 |
+
print(
|
| 25 |
+
"Usage: eval_runner.py <eval_ref> <model> <dataset_repo> [--inspect-evals] [extra_args...]"
|
| 26 |
+
)
|
| 27 |
+
sys.exit(1)
|
| 28 |
+
|
| 29 |
+
eval_ref = sys.argv[1]
|
| 30 |
+
model = sys.argv[2]
|
| 31 |
+
dataset_repo = sys.argv[3] # Changed from space_id to dataset_repo
|
| 32 |
+
|
| 33 |
+
# Check if this is an inspect_evals path
|
| 34 |
+
is_inspect_evals = "--inspect-evals" in sys.argv
|
| 35 |
+
extra_args = [arg for arg in sys.argv[4:] if arg != "--inspect-evals"]
|
| 36 |
+
|
| 37 |
+
# Construct log directory path for HF filesystem
|
| 38 |
+
if not dataset_repo.startswith("datasets/"):
|
| 39 |
+
dataset_repo = f"datasets/{dataset_repo}"
|
| 40 |
+
log_dir = f"hf://{dataset_repo}/logs"
|
| 41 |
+
|
| 42 |
+
if is_inspect_evals:
|
| 43 |
+
# Use inspect_evals path directly
|
| 44 |
+
print(f"Using inspect_evals: {eval_ref}")
|
| 45 |
+
eval_target = eval_ref
|
| 46 |
+
cleanup_file = None
|
| 47 |
+
else:
|
| 48 |
+
# Download custom eval script
|
| 49 |
+
print(f"Downloading eval from {eval_ref}...")
|
| 50 |
+
with urllib.request.urlopen(eval_ref) as response:
|
| 51 |
+
eval_code = response.read().decode("utf-8")
|
| 52 |
+
|
| 53 |
+
eval_filename = "downloaded_eval.py"
|
| 54 |
+
with open(eval_filename, "w") as f:
|
| 55 |
+
f.write(eval_code)
|
| 56 |
+
|
| 57 |
+
eval_target = eval_filename
|
| 58 |
+
cleanup_file = eval_filename
|
| 59 |
+
|
| 60 |
+
try:
|
| 61 |
+
print(f"Running inspect eval with model {model}...")
|
| 62 |
+
print(f"Logs will be written to: {log_dir}")
|
| 63 |
+
|
| 64 |
+
# Build command with HF filesystem logging parameters
|
| 65 |
+
cmd = [
|
| 66 |
+
"inspect",
|
| 67 |
+
"eval",
|
| 68 |
+
eval_target,
|
| 69 |
+
"--model",
|
| 70 |
+
model,
|
| 71 |
+
"--log-dir",
|
| 72 |
+
log_dir,
|
| 73 |
+
"--log-shared", # Enable shared logging for remote filesystems
|
| 74 |
+
"--log-buffer",
|
| 75 |
+
"100", # Buffer size for stable ZIP files
|
| 76 |
+
]
|
| 77 |
+
cmd.extend(extra_args)
|
| 78 |
+
|
| 79 |
+
print(f"Command: {' '.join(cmd)}")
|
| 80 |
+
subprocess.run(cmd, check=True)
|
| 81 |
+
|
| 82 |
+
print(f"\n✓ Eval completed!")
|
| 83 |
+
print(
|
| 84 |
+
f"Logs are available at: https://huggingface.co/{dataset_repo}/tree/main/logs"
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
finally:
|
| 88 |
+
if cleanup_file and os.path.exists(cleanup_file):
|
| 89 |
+
os.unlink(cleanup_file)
|