Skip to content

Commit

Permalink
make sure temp files are deleted w finally
Browse files Browse the repository at this point in the history
Signed-off-by: Roni Friedman-Melamed <[email protected]>
  • Loading branch information
Roni-Friedman committed Nov 7, 2024
1 parent 777132a commit d918732
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/instructlab/eval/unitxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
self.unitxt_recipe = unitxt_recipe

def assign_tasks_dir(self, task_name):
return f"{TEMP_DIR_PREFIX}_{task_name}"
return os.path.join("eval_output", f"{TEMP_DIR_PREFIX}_{task_name}")

def assign_task_name(self):
return str(uuid4())
Expand Down Expand Up @@ -90,28 +90,30 @@ def run(self, server_url: str | None = None) -> tuple:
self.prepare_unitxt_files()
logger.debug(locals())
os.environ["TOKENIZERS_PARALLELISM"] = "true"
results = self._run_mmlu(server_url=server_url)
taskname = self.tasks[0]
global_scores = results["results"][taskname]
global_scores.pop("alias")
try:
instances = results["samples"][taskname]
instance_scores = {}
metrics = [
metric.replace("metrics.", "")
for metric in instances[0]["doc"]["metrics"]
]
for i, instance in enumerate(instances):
scores = {}
for metric in metrics:
scores[metric] = instance[metric][0]
instance_scores[i] = scores
except KeyError as e:
logger.error("Error in extracting single instance scores")
logger.error(e)
logger.error(e.__traceback__)
instance_scores = None
self.remove_unitxt_files()
results = self._run_mmlu(server_url=server_url)
taskname = self.tasks[0]
global_scores = results["results"][taskname]
global_scores.pop("alias")
try:
instances = results["samples"][taskname]
instance_scores = {}
metrics = [
metric.replace("metrics.", "")
for metric in instances[0]["doc"]["metrics"]
]
for i, instance in enumerate(instances):
scores = {}
for metric in metrics:
scores[metric] = instance[metric][0]
instance_scores[i] = scores
except KeyError as e:
logger.error("Error in extracting single instance scores")
logger.error(e)
logger.error(e.__traceback__)
instance_scores = None
finally:
self.remove_unitxt_files()
return global_scores, instance_scores


Expand Down

0 comments on commit d918732

Please sign in to comment.