FuryAssassin commited on
Commit
ff019c5
·
verified ·
1 Parent(s): 295a180

Upload evaluation/eval.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. 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 we import the fresh source package instead of any pre-built compiled extension.
7
- # Add the evaluation directory to sys.path so `import utils` loads evaluation/utils/*.py
8
- eval_dir = os.path.dirname(__file__)
9
- if eval_dir not in sys.path:
10
- sys.path.insert(0, eval_dir)
11
- # Invalidate import caches and prefer source .py files over compiled extensions
12
- import importlib, importlib.util, pkgutil
13
- # If a compiled extension is present, remove it from sys.modules so Python will import the source package
14
- for mod in list(sys.modules.keys()):
15
- if mod.startswith('utils'):
16
- del sys.modules[mod]
17
-
18
- # Force import from source files in evaluation/utils
19
- spec = importlib.util.spec_from_file_location('utils', os.path.join(eval_dir, 'utils', '__init__.py'))
20
- utils = importlib.util.module_from_spec(spec)
21
- spec.loader.exec_module(utils)
22
- import sys as _sys
23
- _sys.modules['utils'] = utils
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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