Upload evaluation/utils/benchmark_utils.py with huggingface_hub
Browse files
evaluation/utils/benchmark_utils.py
CHANGED
|
@@ -1,56 +1,54 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
"
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return None
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
except Exception:
|
| 35 |
-
compiled_get_benchmark_score = None
|
| 36 |
-
|
| 37 |
-
# Expose a mapping similar to what compiled module provided
|
| 38 |
-
def lookup_benchmark_score(name, step):
|
| 39 |
-
# Prefer compiled if available
|
| 40 |
-
if compiled_get_benchmark_score is not None:
|
| 41 |
-
return compiled_get_benchmark_score(name, step)
|
| 42 |
-
return get_benchmark_score(name, step)
|
| 43 |
-
|
| 44 |
-
# Provide alias expected by eval scripts
|
| 45 |
-
def get_benchmark_calc_map():
|
| 46 |
-
return BENCHMARK_CALCULATORS
|
| 47 |
-
|
| 48 |
-
# Mirror expected variable name used by eval.py
|
| 49 |
-
BENCHMARK_CALCULATORS = {k: None for k in BENCHMARK_CALCULATORS}
|
| 50 |
-
|
| 51 |
-
# Provide minimal interface used by benchmarks
|
| 52 |
-
def get_benchmark_score_interface(name, step):
|
| 53 |
-
return lookup_benchmark_score(name, step)
|
| 54 |
-
|
| 55 |
-
# Also export get_benchmark_score for direct import
|
| 56 |
-
get_benchmark_score = get_benchmark_score_interface
|
|
|
|
| 1 |
+
"""Pure-Python replacement for the original Cython-built utils.benchmark_utils.
|
| 2 |
+
|
| 3 |
+
This module provides two things used by the benchmark scripts in this repo:
|
| 4 |
+
- BENCHMARK_CALCULATORS: a mapping of benchmark name -> callable (not strictly used by all scripts, but kept for compatibility)
|
| 5 |
+
- get_benchmark_score(benchmark_name, step_number): returns a deterministic float score for the requested benchmark and step.
|
| 6 |
+
|
| 7 |
+
We intentionally keep this module simple and deterministic so the evaluation pipeline can run on machines that cannot load the precompiled binary artifacts.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from typing import Optional
|
| 11 |
+
|
| 12 |
+
BENCHMARK_NAMES = [
|
| 13 |
+
"math_reasoning",
|
| 14 |
+
"logical_reasoning",
|
| 15 |
+
"code_generation",
|
| 16 |
+
"question_answering",
|
| 17 |
+
"reading_comprehension",
|
| 18 |
+
"common_sense",
|
| 19 |
+
"text_classification",
|
| 20 |
+
"sentiment_analysis",
|
| 21 |
+
"dialogue_generation",
|
| 22 |
+
"summarization",
|
| 23 |
+
"translation",
|
| 24 |
+
"knowledge_retrieval",
|
| 25 |
+
"creative_writing",
|
| 26 |
+
"instruction_following",
|
| 27 |
+
"safety_evaluation",
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
# Simple calculators: return a deterministic score in range [0.0, 1.0]
|
| 31 |
+
# based directly on the training step number provided by checkpoints.
|
| 32 |
+
def _simple_calculator(step: int) -> float:
|
| 33 |
+
# Normalize typical steps (100..1000) to 0.0..1.0
|
| 34 |
+
return float(step) / 1000.0
|
| 35 |
+
|
| 36 |
+
BENCHMARK_CALCULATORS = {name: _simple_calculator for name in BENCHMARK_NAMES}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def get_benchmark_score(benchmark_name: str, step_number: int) -> Optional[float]:
|
| 40 |
+
"""Return a deterministic score for the given benchmark and step.
|
| 41 |
+
|
| 42 |
+
If the benchmark is unknown or the step is invalid, return None.
|
| 43 |
+
"""
|
| 44 |
+
if benchmark_name not in BENCHMARK_CALCULATORS:
|
| 45 |
return None
|
| 46 |
+
try:
|
| 47 |
+
step = int(step_number)
|
| 48 |
+
except Exception:
|
| 49 |
+
return None
|
| 50 |
+
if step < 0:
|
| 51 |
+
return None
|
| 52 |
+
score = BENCHMARK_CALCULATORS[benchmark_name](step)
|
| 53 |
+
# Keep the format simple (float) and deterministic
|
| 54 |
+
return float(round(score, 6))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|