-
Notifications
You must be signed in to change notification settings - Fork 323
fix tasks list #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alielfilali01
wants to merge
4
commits into
huggingface:main
Choose a base branch
from
alielfilali01:alielfilali01-patch-1-fixTasksList
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix tasks list #906
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,6 +37,36 @@ | |||||
from lighteval.tasks.lighteval_task import LightevalTask, LightevalTaskConfig | ||||||
from lighteval.utils.imports import CANNOT_USE_EXTENDED_TASKS_MSG, can_load_extended_tasks | ||||||
|
||||||
# Import community tasks | ||||||
AVAILABLE_COMMUNITY_TASKS_MODULES = [] | ||||||
def load_community_tasks(): | ||||||
"""Dynamically load community tasks, handling errors gracefully.""" | ||||||
modules = [] | ||||||
try: | ||||||
# Community tasks are in the lighteval directory, not under src | ||||||
import sys | ||||||
import os | ||||||
community_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "community_tasks") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if os.path.exists(community_path): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
sys.path.insert(0, os.path.dirname(community_path)) | ||||||
|
||||||
# List all python files in community_tasks | ||||||
community_files = [f[:-3] for f in os.listdir(community_path) | ||||||
if f.endswith('.py') and not f.startswith('_')] | ||||||
|
||||||
for module_name in community_files: | ||||||
try: | ||||||
module = importlib.import_module(f"community_tasks.{module_name}") | ||||||
if hasattr(module, 'TASKS_TABLE'): | ||||||
modules.append(module) | ||||||
logger.info(f"Successfully loaded community tasks from {module_name}") | ||||||
except Exception as e: | ||||||
logger.warning(f"Failed to load community tasks from {module_name}: {e}") | ||||||
except Exception as e: | ||||||
logger.warning(f"Error loading community tasks directory: {e}") | ||||||
|
||||||
return modules | ||||||
|
||||||
|
||||||
logger = logging.getLogger(__name__) | ||||||
|
||||||
|
@@ -137,6 +167,23 @@ def task_registry(self) -> dict[str, LightevalTaskConfig]: | |||||
else: | ||||||
logger.warning(CANNOT_USE_EXTENDED_TASKS_MSG) | ||||||
|
||||||
# Load community tasks | ||||||
community_modules = load_community_tasks() | ||||||
for community_task_module in community_modules: | ||||||
custom_tasks_module.append(community_task_module) | ||||||
|
||||||
# Load multilingual tasks | ||||||
MULTILINGUAL_TASKS_AVAILABLE = False | ||||||
multilingual_tasks = None | ||||||
try: | ||||||
import lighteval.tasks.multilingual.tasks as multilingual_tasks | ||||||
MULTILINGUAL_TASKS_AVAILABLE = True | ||||||
except ImportError as e: | ||||||
logger.warning(f"Could not load multilingual tasks: {e}. You may need to install additional dependencies.") | ||||||
|
||||||
if MULTILINGUAL_TASKS_AVAILABLE and multilingual_tasks is not None: | ||||||
custom_tasks_module.append(multilingual_tasks) | ||||||
|
||||||
for module in custom_tasks_module: | ||||||
custom_task_configs.extend(module.TASKS_TABLE) | ||||||
logger.info(f"Found {len(module.TASKS_TABLE)} custom tasks in {module.__file__}") | ||||||
|
@@ -285,13 +332,26 @@ def print_all_tasks(self): | |||||
Print all the tasks in the task registry. | ||||||
""" | ||||||
tasks_names = list(self.task_registry.keys()) | ||||||
|
||||||
# Ensure all default suites are present | ||||||
suites_in_registry = {name.split("|")[0] for name in tasks_names} | ||||||
for suite in DEFAULT_SUITES: | ||||||
if suite not in suites_in_registry: | ||||||
# We add a dummy task to make sure the suite is printed | ||||||
tasks_names.append(f"{suite}|") | ||||||
|
||||||
tasks_names.sort() | ||||||
|
||||||
for suite, g in groupby(tasks_names, lambda x: x.split("|")[0]): | ||||||
tasks_names = list(g) | ||||||
tasks_names.sort() | ||||||
tasks_in_suite = [name for name in g if name.split("|")[1]] # Filter out dummy tasks | ||||||
tasks_in_suite.sort() | ||||||
|
||||||
print(f"\n- {suite}:") | ||||||
for task_name in tasks_names: | ||||||
print(f" - {task_name}") | ||||||
if not tasks_in_suite: | ||||||
print(" (no tasks in this suite)") | ||||||
else: | ||||||
for task_name in tasks_in_suite: | ||||||
print(f" - {task_name}") | ||||||
|
||||||
@staticmethod | ||||||
def create_custom_tasks_module(custom_tasks: str | Path | ModuleType) -> ModuleType: | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they should be imported at the top of the file.