Upload evaluation/eval.py with huggingface_hub
Browse files- evaluation/eval.py +44 -18
evaluation/eval.py
CHANGED
|
@@ -2,25 +2,51 @@ import argparse
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import subprocess
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
# Ensure
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
from utils.benchmark_utils import BENCHMARK_CALCULATORS
|
| 26 |
|
|
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import subprocess
|
| 5 |
+
import glob
|
| 6 |
+
import shutil
|
| 7 |
|
| 8 |
+
# Ensure evaluation directory is on path so 'utils' package resolves to evaluation/utils
|
| 9 |
+
sys.path.insert(0, os.path.dirname(__file__))
|
| 10 |
+
|
| 11 |
+
def rebuild_utils_package():
|
| 12 |
+
"""Deterministically rebuild the evaluation.utils package from sources.
|
| 13 |
+
|
| 14 |
+
- Remove any existing compiled artifacts (.so, .cpython-*.so, .c) in evaluation/utils
|
| 15 |
+
- Run setup.py build_ext --inplace inside evaluation/
|
| 16 |
+
"""
|
| 17 |
+
eval_dir = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
+
utils_dir = os.path.join(eval_dir, "utils")
|
| 19 |
+
|
| 20 |
+
# Remove stale compiled artifacts that can cause non-deterministic imports
|
| 21 |
+
patterns = ["*.so", "*.cpython-*.so", "*.c", "__pycache__"]
|
| 22 |
+
for pat in patterns:
|
| 23 |
+
for path in glob.glob(os.path.join(utils_dir, pat)):
|
| 24 |
+
try:
|
| 25 |
+
if os.path.isdir(path):
|
| 26 |
+
shutil.rmtree(path)
|
| 27 |
+
else:
|
| 28 |
+
os.remove(path)
|
| 29 |
+
except Exception:
|
| 30 |
+
# best-effort; don't fail here so we can attempt a rebuild
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
# Run deterministic rebuild
|
| 34 |
+
try:
|
| 35 |
+
subprocess.run(
|
| 36 |
+
[sys.executable, "setup.py", "build_ext", "--inplace"],
|
| 37 |
+
cwd=eval_dir,
|
| 38 |
+
check=True,
|
| 39 |
+
capture_output=True,
|
| 40 |
+
text=True
|
| 41 |
+
)
|
| 42 |
+
except subprocess.CalledProcessError as e:
|
| 43 |
+
print("Error: Failed to rebuild evaluation utils package:", file=sys.stderr)
|
| 44 |
+
print(e.stdout, file=sys.stderr)
|
| 45 |
+
print(e.stderr, file=sys.stderr)
|
| 46 |
+
raise
|
| 47 |
+
|
| 48 |
+
# Rebuild before importing compiled modules to avoid stale artifacts
|
| 49 |
+
rebuild_utils_package()
|
| 50 |
|
| 51 |
from utils.benchmark_utils import BENCHMARK_CALCULATORS
|
| 52 |
|