Spaces:
Running
Running
File size: 1,933 Bytes
1508879 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import sys
from pathlib import Path
import pytest
from mlip_arena.models import REGISTRY as MODELS
from mlip_arena.tasks import REGISTRY as TASKS
# Add serve directory to path to import ranks
serve_path = Path(__file__).parents[1] / "serve"
sys.path.append(str(serve_path))
# Get all tasks that have a rank page defined
RANK_TASKS = [
(meta["rank-page"], meta["rank-page"]) for task_name, meta in TASKS.items() if meta.get("rank-page") is not None
]
@pytest.mark.parametrize("rank_module_name, task_key", RANK_TASKS)
def test_rank_data_loading(rank_module_name, task_key):
"""
Validate that a rank leaderboard module exposes a non-empty `table` and includes all models registered for the given task.
Parameters:
rank_module_name (str): Name of the rank module under the `ranks` package to load.
task_key (str): Task identifier used to determine which models should appear in the leaderboard (looked up in the `MODELS` registry).
"""
# Import the rank module
import importlib
try:
module = importlib.import_module(f"ranks.{rank_module_name}")
except Exception as e:
pytest.fail(f"Failed to import rank module '{rank_module_name}': {e}")
# Check if the module has the 'table' attribute and it's not empty
assert hasattr(module, "table"), f"Module '{rank_module_name}' is missing 'table' attribute"
assert not module.table.empty, f"Leaderboard table for '{rank_module_name}' is empty"
# Identify expected models for this task from the registry
expected_models = [model for model, metadata in MODELS.items() if task_key in metadata.get("gpu-tasks", [])]
# Verify that all expected models are present in the table
loaded_models = set(module.table.index)
missing_models = [m for m in expected_models if m not in loaded_models]
assert not missing_models, f"Missing data for models in '{rank_module_name}': {missing_models}" |