Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replay.Repeat now preserves attempt when restoring generator max_tokens #409

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions garak/harnesses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import tqdm

from garak.attempt import *
import garak.attempt
from garak import _config
from garak import _plugins

Expand All @@ -31,7 +31,7 @@ class Harness:
active = True

def __init__(self):
logging.info(f"harness init: %s", self)
logging.info("harness init: %s", self)

def _load_buffs(self, buffs: List) -> None:
"""load buff instances into global config
Expand Down Expand Up @@ -90,6 +90,7 @@ def run(self, model, probes, detectors, evaluator, announce_probe=True) -> None:
if not probe:
continue
attempt_results = probe.probe(model)
assert isinstance(attempt_results, list)

eval_outputs, eval_results = [], defaultdict(list)
first_detector = True
Expand All @@ -109,7 +110,7 @@ def run(self, model, probes, detectors, evaluator, announce_probe=True) -> None:
first_detector = False

for attempt in attempt_results:
attempt.status = ATTEMPT_COMPLETE
attempt.status = garak.attempt.ATTEMPT_COMPLETE
_config.transient.reportfile.write(json.dumps(attempt.as_dict()) + "\n")

if len(attempt_results) == 0:
Expand Down
4 changes: 2 additions & 2 deletions garak/probes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def __init__(self):
print(
f"loading {Style.BRIGHT}{Fore.LIGHTYELLOW_EX}probe: {Style.RESET_ALL}{self.probename}"
)
logging.info(f"probe init: {self}")
logging.info("probe init: {self}")
if "description" not in dir(self):
if self.__doc__:
self.description = self.__doc__.split("\n")[0]
self.description = self.__doc__.split("\n", maxsplit=1)[0]
else:
self.description = ""

Expand Down
3 changes: 2 additions & 1 deletion garak/probes/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def _generator_precall_hook(self, generator, attempt=None):
self.generator_orig_tokens = self.generator.max_tokens
self.generator.max_tokens = self.new_max_tokens

def _postprocess_hook(self, attempt):
def _postprocess_hook(self, attempt) -> Attempt:
if self.override_maxlen and self.generator_orig_tokens is not None:
self.generator.max_tokens = self.generator_orig_tokens
return attempt


class RepeatExtended(Repeat):
Expand Down