Skip to content

Commit 34eba92

Browse files
author
alielfilali42
committed
chore: apply pre-commit fixes
1 parent d0cd4c9 commit 34eba92

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ extended_tasks = [
106106
]
107107
s3 = ["s3fs"]
108108
multilingual = [
109+
"langcodes",
109110
"stanza",
110111
"spacy[ja,ko,th]",
111112
"jieba", # for chinese tokenizer

src/lighteval/tasks/registry.py

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import importlib
2626
import logging
2727
import os
28+
import sys
2829
from functools import lru_cache
2930
from itertools import groupby
3031
from pathlib import Path
@@ -38,6 +39,41 @@
3839
from lighteval.utils.imports import CANNOT_USE_EXTENDED_TASKS_MSG, can_load_extended_tasks
3940

4041

42+
# Import community tasks
43+
AVAILABLE_COMMUNITY_TASKS_MODULES = []
44+
45+
46+
def load_community_tasks():
47+
"""Dynamically load community tasks, handling errors gracefully."""
48+
modules = []
49+
try:
50+
# Community tasks are in the lighteval directory, not under src
51+
community_path = Path(__file__).parent.parent.parent / "community_tasks"
52+
if not community_path.exists():
53+
return modules
54+
55+
# Ensure the parent directory is on sys.path so we can import `community_tasks.*`
56+
parent_dir = str(community_path.parent)
57+
if parent_dir not in sys.path:
58+
sys.path.insert(0, parent_dir)
59+
60+
# List all python files in community_tasks
61+
community_files = [p.stem for p in community_path.glob("*.py") if not p.name.startswith("_")]
62+
63+
for module_name in community_files:
64+
try:
65+
module = importlib.import_module(f"community_tasks.{module_name}")
66+
if hasattr(module, "TASKS_TABLE"):
67+
modules.append(module)
68+
logger.info(f"Successfully loaded community tasks from {module_name}")
69+
except Exception as e:
70+
logger.warning(f"Failed to load community tasks from {module_name}: {e}")
71+
except Exception as e:
72+
logger.warning(f"Error loading community tasks directory: {e}")
73+
74+
return modules
75+
76+
4177
logger = logging.getLogger(__name__)
4278

4379
# Helm, Bigbench, Harness are implementations following an evaluation suite setup
@@ -137,6 +173,24 @@ def task_registry(self) -> dict[str, LightevalTaskConfig]:
137173
else:
138174
logger.warning(CANNOT_USE_EXTENDED_TASKS_MSG)
139175

176+
# Load community tasks
177+
community_modules = load_community_tasks()
178+
for community_task_module in community_modules:
179+
custom_tasks_module.append(community_task_module)
180+
181+
# Load multilingual tasks
182+
MULTILINGUAL_TASKS_AVAILABLE = False
183+
multilingual_tasks = None
184+
try:
185+
import lighteval.tasks.multilingual.tasks as multilingual_tasks
186+
187+
MULTILINGUAL_TASKS_AVAILABLE = True
188+
except ImportError as e:
189+
logger.warning(f"Could not load multilingual tasks: {e}. You may need to install additional dependencies.")
190+
191+
if MULTILINGUAL_TASKS_AVAILABLE and multilingual_tasks is not None:
192+
custom_tasks_module.append(multilingual_tasks)
193+
140194
for module in custom_tasks_module:
141195
custom_task_configs.extend(module.TASKS_TABLE)
142196
logger.info(f"Found {len(module.TASKS_TABLE)} custom tasks in {module.__file__}")
@@ -285,13 +339,26 @@ def print_all_tasks(self):
285339
Print all the tasks in the task registry.
286340
"""
287341
tasks_names = list(self.task_registry.keys())
342+
343+
# Ensure all default suites are present
344+
suites_in_registry = {name.split("|")[0] for name in tasks_names}
345+
for suite in DEFAULT_SUITES:
346+
if suite not in suites_in_registry:
347+
# We add a dummy task to make sure the suite is printed
348+
tasks_names.append(f"{suite}|")
349+
288350
tasks_names.sort()
351+
289352
for suite, g in groupby(tasks_names, lambda x: x.split("|")[0]):
290-
tasks_names = list(g)
291-
tasks_names.sort()
353+
tasks_in_suite = [name for name in g if name.split("|")[1]] # Filter out dummy tasks
354+
tasks_in_suite.sort()
355+
292356
print(f"\n- {suite}:")
293-
for task_name in tasks_names:
294-
print(f" - {task_name}")
357+
if not tasks_in_suite:
358+
print(" (no tasks in this suite)")
359+
else:
360+
for task_name in tasks_in_suite:
361+
print(f" - {task_name}")
295362

296363
@staticmethod
297364
def create_custom_tasks_module(custom_tasks: str | Path | ModuleType) -> ModuleType:

0 commit comments

Comments
 (0)