text
stringlengths 0
15.3k
|
---|
(group_name, subtask_list) = _get_group_and_subtask_from_config(group_config) |
elif self._name_is_tag(name_or_config): |
fn = partial(self._load_individual_task_or_group, update_config=name_or_config if isinstance(name_or_config, dict) else None) |
return dict(collections.ChainMap(*map(fn, reversed(subtask_list)))) |
else: |
group_name = ConfigurableGroup(config={'group': name_or_config, 'task': subtask_list}) |
if isinstance(name_or_config, dict): |
if self._config_is_task(name_or_config): |
name = name_or_config.pop('task') |
if update_config is not None: |
name_or_config = {**name_or_config, **update_config} |
if self._name_is_group(name): |
group_config = self._get_config(name) |
(group_config, update_config) = _process_group_config(group_config, name_or_config) |
(group_name, subtask_list) = _get_group_and_subtask_from_config(group_config) |
elif self._name_is_tag(name): |
subtask_list = self._get_tasklist(name) |
fn = partial(self._load_individual_task_or_group, update_config=name_or_config) |
return dict(collections.ChainMap(*map(fn, reversed(subtask_list)))) |
else: |
if self._name_is_registered(name): |
base_task_config = self._get_config(name) |
if parent_name is not None: |
num_duplicate = len(list(filter(lambda x: x.startswith(name), self.task_group_map[parent_name]))) |
if num_duplicate > 0: |
name = f'{name}-{num_duplicate}' |
self.task_group_map[parent_name].append(name) |
task_config = {**base_task_config, **name_or_config} |
else: |
task_config = name_or_config |
return _load_task(task_config, task=name) |
else: |
(group_config, update_config) = _process_group_config(name_or_config) |
(group_name, subtask_list) = _get_group_and_subtask_from_config(group_config) |
fn = partial(self._load_individual_task_or_group, parent_name=group_name, update_config=update_config) |
return {group_name: dict(collections.ChainMap(*map(fn, reversed(subtask_list))))} |
def load_task_or_group(self, task_list: Optional[Union[str, list]]=None) -> dict: |
if isinstance(task_list, str): |
task_list = [task_list] |
all_loaded_tasks = dict(collections.ChainMap(*map(self._load_individual_task_or_group, task_list))) |
return all_loaded_tasks |
def load_config(self, config: Dict): |
return self._load_individual_task_or_group(config) |
def _get_task_and_group(self, task_dir: str): |
print_info = True |
ignore_dirs = ['__pycache__', '.ipynb_checkpoints'] |
tasks_and_groups = collections.defaultdict() |
for (root, dirs, file_list) in os.walk(task_dir): |
dirs[:] = [d for d in dirs if d not in ignore_dirs] |
for f in file_list: |
if f.endswith('.yaml'): |
yaml_path = os.path.join(root, f) |
config = utils.load_yaml_config(yaml_path, mode='simple') |
if self._config_is_python_task(config): |
tasks_and_groups[config['task']] = {'type': 'python_task', 'yaml_path': yaml_path} |
elif self._config_is_group(config): |
tasks_and_groups[config['group']] = {'type': 'group', 'task': -1, 'yaml_path': yaml_path} |
elif self._config_is_task(config): |
task = config['task'] |
tasks_and_groups[task] = {'type': 'task', 'yaml_path': yaml_path} |
for attr in ['tag', 'group']: |
if attr in config: |
if attr == 'group' and print_info: |
self.logger.info("`group` and `group_alias` keys in tasks' configs will no longer be used in the next release of lm-eval. `tag` will be used to allow to call a collection of tasks just like `group`. `group` will be removed in order to not cause confusion with the new ConfigurableGroup which will be the offical way to create groups with addition of group-wide configuations.") |
print_info = False |
attr_list = config[attr] |
if isinstance(attr_list, str): |
attr_list = [attr_list] |
for tag in attr_list: |
if tag not in tasks_and_groups: |
tasks_and_groups[tag] = {'type': 'tag', 'task': [task], 'yaml_path': -1} |
elif tasks_and_groups[tag]['type'] != 'tag': |
self.logger.info(f'The tag {tag} is already registered as a group, this tag will not be registered. This may affect tasks you want to call.') |
break |
else: |
tasks_and_groups[tag]['task'].append(task) |
else: |
self.logger.debug(f'File {f} in {root} could not be loaded') |
return tasks_and_groups |
def get_task_name_from_config(task_config: Dict[str, str]) -> str: |
if 'task' in task_config: |
return task_config['task'] |
if 'dataset_name' in task_config: |
return '{dataset_path}_{dataset_name}'.format(**task_config) |
else: |
return '{dataset_path}'.format(**task_config) |
def get_task_name_from_object(task_object): |
if hasattr(task_object, 'config'): |
return task_object._config['task'] |
return task_object.EVAL_HARNESS_NAME if hasattr(task_object, 'EVAL_HARNESS_NAME') else type(task_object).__name__ |
def _check_duplicates(task_dict: dict) -> List[str]: |
subtask_names = [] |
for (key, value) in task_dict.items(): |
subtask_names.extend(value) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.