25
25
import importlib
26
26
import logging
27
27
import os
28
+ import sys
28
29
from functools import lru_cache
29
30
from itertools import groupby
30
31
from pathlib import Path
@@ -44,24 +45,26 @@ def load_community_tasks():
44
45
modules = []
45
46
try :
46
47
# Community tasks are in the lighteval directory, not under src
47
- import sys
48
- import os
49
- community_path = os .path .join (os .path .dirname (__file__ ), ".." , ".." , ".." , "community_tasks" )
50
- if os .path .exists (community_path ):
51
- sys .path .insert (0 , os .path .dirname (community_path ))
52
-
53
- # List all python files in community_tasks
54
- community_files = [f [:- 3 ] for f in os .listdir (community_path )
55
- if f .endswith ('.py' ) and not f .startswith ('_' )]
56
-
57
- for module_name in community_files :
58
- try :
59
- module = importlib .import_module (f"community_tasks.{ module_name } " )
60
- if hasattr (module , 'TASKS_TABLE' ):
61
- modules .append (module )
62
- logger .info (f"Successfully loaded community tasks from { module_name } " )
63
- except Exception as e :
64
- logger .warning (f"Failed to load community tasks from { module_name } : { e } " )
48
+ community_path = Path (__file__ ).parent .parent .parent / "community_tasks"
49
+ if not community_path .exists ():
50
+ return modules
51
+
52
+ # Ensure the parent directory is on sys.path so we can import `community_tasks.*`
53
+ parent_dir = str (community_path .parent )
54
+ if parent_dir not in sys .path :
55
+ sys .path .insert (0 , parent_dir )
56
+
57
+ # List all python files in community_tasks
58
+ community_files = [p .stem for p in community_path .glob ("*.py" ) if not p .name .startswith ('_' )]
59
+
60
+ for module_name in community_files :
61
+ try :
62
+ module = importlib .import_module (f"community_tasks.{ module_name } " )
63
+ if hasattr (module , 'TASKS_TABLE' ):
64
+ modules .append (module )
65
+ logger .info (f"Successfully loaded community tasks from { module_name } " )
66
+ except Exception as e :
67
+ logger .warning (f"Failed to load community tasks from { module_name } : { e } " )
65
68
except Exception as e :
66
69
logger .warning (f"Error loading community tasks directory: { e } " )
67
70
@@ -218,7 +221,9 @@ def taskinfo_selector(self, tasks: str) -> dict[str, list[dict]]:
218
221
219
222
220
223
Returns:
221
- dict[str, list[dict]]: A dictionary mapping each task name to a list of tuples representing the few_shot and truncate_few_shots values.
224
+ tuple[list[str], dict[str, list[tuple[int, bool]]]]: A tuple containing:
225
+ - A sorted list of unique task names in the format "suite|task".
226
+ - A dictionary mapping each task name to a list of tuples representing the few_shot and truncate_few_shots values.
222
227
"""
223
228
few_shot_dict = collections .defaultdict (list )
224
229
0 commit comments