Skip to content

Commit

Permalink
update hitlog writing to reopen as append if hitlogfile is a closed f…
Browse files Browse the repository at this point in the history
…ile object (NVIDIA#665)

Co-authored-by: Leon Derczynski <[email protected]>
  • Loading branch information
leondz and leondz authored May 9, 2024
1 parent e3bac0c commit 53ab860
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions garak/evaluators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ def evaluate(self, attempts: List[garak.attempt.Attempt]) -> None:
all_outputs += attempt.outputs
for idx, score in enumerate(attempt.detector_results[detector]):
if not self.test(score): # if we don't pass
if not _config.transient.hitlogfile:
if (
_config.transient.hitlogfile is None
or _config.transient.hitlogfile.closed
):
hitlog_mode = (
"w" if _config.transient.hitlogfile is None else "a"
)
if not _config.reporting.report_prefix:
hitlog_filename = f"{_config.reporting.report_dir}/garak.{_config.transient.run_id}.hitlog.jsonl"
else:
Expand All @@ -72,7 +78,7 @@ def evaluate(self, attempts: List[garak.attempt.Attempt]) -> None:
logging.info("hit log in %s", hitlog_filename)
_config.transient.hitlogfile = open(
hitlog_filename,
"w",
hitlog_mode,
buffering=1,
encoding="utf-8",
)
Expand Down

0 comments on commit 53ab860

Please sign in to comment.