lm-evaluation-harness
49 строк · 1.8 Кб
1import os2from typing import List, Union3
4from lm_eval.utils import load_yaml_config5
6
7# {{{CI}}}
8# This is the path where the output for the changed files for the tasks folder is stored
9# FILE_PATH = file_path = ".github/outputs/tasks_all_changed_and_modified_files.txt"
10
11
12# reads a text file and returns a list of words
13# used to read the output of the changed txt from tj-actions/changed-files
14def load_changed_files(file_path: str) -> List[str]:15with open(file_path, "r") as f:16content = f.read()17words_list = [x for x in content.split()]18return words_list19
20
21# checks the txt file for list of changed files.
22# if file ends with .yaml then check yaml and load the config.
23# if the config task is a string, it's a task config.
24# if the config task is a list, it's a group config.
25def parser(full_path: List[str]) -> List[str]:26_output = set()27for x in full_path:28if os.path.exists(x) and x.endswith(".yaml"):29config = load_yaml_config(x, mode="simple")30if isinstance(config["task"], str):31_output.add(config["task"])32elif isinstance(config["task"], list):33_output.add(config["group"])34return list(_output)35
36
37def new_tasks() -> Union[List[str], None]:38FILENAME = ".github/outputs/tasks_all_changed_and_modified_files.txt"39if os.path.exists(FILENAME):40# If tasks folder has changed then we get the list of files from FILENAME41# and parse the yaml files to get the task names.42return parser(load_changed_files(FILENAME))43elif os.getenv("API") is not None:44# Or if API has changed then we set the ENV variable API to True45# and run given tasks.46return ["arc_easy", "hellaswag", "piqa", "wikitext"]47# if both not true just do arc_easy48else:49return50