text
stringlengths
0
15.3k
all_paths = []
if include_path is not None:
if isinstance(include_path, str):
include_path = [include_path]
all_paths.extend(include_path)
task_index = {}
for task_dir in all_paths:
tasks = self._get_task_and_group(task_dir)
task_index = {**tasks, **task_index}
return task_index
@property
def all_tasks(self):
return self._all_tasks
@property
def all_groups(self):
return self._all_groups
@property
def all_subtasks(self):
return self._all_subtasks
@property
def all_tags(self):
return self._all_tags
@property
def task_index(self):
return self._task_index
def list_all_tasks(self, list_groups=True, list_tags=True, list_subtasks=True) -> str:
from pytablewriter import MarkdownTableWriter
def sanitize_path(path):
if 'lm_eval/tasks/' in path:
return 'lm_eval/tasks/' + path.split('lm_eval/tasks/')[-1]
else:
return path
group_table = MarkdownTableWriter()
group_table.headers = ['Group', 'Config Location']
gt_values = []
for g in self.all_groups:
path = self.task_index[g]['yaml_path']
if path == -1:
path = '---'
else:
path = sanitize_path(path)
gt_values.append([g, path])
group_table.value_matrix = gt_values
tag_table = MarkdownTableWriter()
tag_table.headers = ['Tag']
tag_table.value_matrix = [[t] for t in self.all_tags]
subtask_table = MarkdownTableWriter()
subtask_table.headers = ['Task', 'Config Location', 'Output Type']
st_values = []
for t in self.all_subtasks:
path = self.task_index[t]['yaml_path']
output_type = ''
if path != -1:
config = utils.load_yaml_config(path, mode='simple')
if 'output_type' in config:
output_type = config['output_type']
elif 'include' in config:
include_path = path.split('/')[:-1] + config['include']
include_config = utils.load_yaml_config(include_path, mode='simple')
if 'output_type' in include_config:
output_type = include_config['output_type']
if path == -1:
path = '---'
else:
path = sanitize_path(path)
st_values.append([t, path, output_type])
subtask_table.value_matrix = st_values
result = '\n'
if list_groups:
result += group_table.dumps() + '\n\n'
if list_tags:
result += tag_table.dumps() + '\n\n'
if list_subtasks:
result += subtask_table.dumps() + '\n\n'
return result
def match_tasks(self, task_list):
return utils.pattern_match(task_list, self.all_tasks)
def _name_is_registered(self, name) -> bool:
if name in self.all_tasks:
return True
return False
def _name_is_task(self, name) -> bool:
if self._name_is_registered(name) and self.task_index[name]['type'] == 'task':
return True
return False
def _name_is_tag(self, name) -> bool:
if self._name_is_registered(name) and self.task_index[name]['type'] == 'tag':
return True
return False