Skip to content

Commit

Permalink
access config_root not _config
Browse files Browse the repository at this point in the history
  • Loading branch information
leondz committed Feb 26, 2025
1 parent 02d202a commit 7310811
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion garak/probes/continuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, config_root=_config):

if self.follow_prompt_cap:
num_ids_to_delete = max(
0, len(self.prompts) - _config.run.soft_probe_prompt_cap
0, len(self.prompts) - config_root.run.soft_probe_prompt_cap
)
ids_to_rm = random.sample(range(len(self.prompts)), num_ids_to_delete)
# delete in descending order
Expand Down
2 changes: 1 addition & 1 deletion garak/probes/dan.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,5 +661,5 @@ class DanInTheWild(DanInTheWildFull):
def __init__(self, config_root=_config):
super().__init__(config_root=config_root)
self.prompts = random.sample(self.prompts, len(self.prompts))[
: _config.run.soft_probe_prompt_cap
: config_root.run.soft_probe_prompt_cap
]
2 changes: 1 addition & 1 deletion garak/probes/glitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,4 @@ class Glitch(GlitchFull):

def __init__(self, config_root=_config):
super().__init__(config_root)
self.max_prompts = _config.run.soft_probe_prompt_cap
self.max_prompts = config_root.run.soft_probe_prompt_cap
22 changes: 10 additions & 12 deletions garak/probes/latentinjection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LatentInjectionMixin:
injection_sep_pairs = [("", "")] # optional attrib get a default
follow_prompt_cap = False

def _build_prompts_triggers(self) -> None:
def _build_prompts_triggers(self, cap=None) -> None:
self.prompts = []
self.triggers = []

Expand Down Expand Up @@ -63,10 +63,8 @@ def _build_prompts_triggers(self) -> None:
self.prompts.append(complete_prompt)
self.triggers.append(payload_trigger)

if self.follow_prompt_cap:
num_ids_to_delete = max(
0, len(self.prompts) - _config.run.soft_probe_prompt_cap
)
if self.follow_prompt_cap and cap is not None:
num_ids_to_delete = max(0, len(self.prompts) - cap)
ids_to_rm = random.sample(range(len(self.prompts)), num_ids_to_delete)
# delete in descending order
ids_to_rm = sorted(ids_to_rm, reverse=True)
Expand Down Expand Up @@ -114,7 +112,7 @@ class LatentInjectionTranslationEnFrFull(Probe, LatentInjectionMixin):
def __init__(self, config_root=_config):
super().__init__(config_root)
self.payload_triggers += garak.payloads.load(self.payload_name).payloads
self._build_prompts_triggers()
self._build_prompts_triggers(cap=config_root.run.soft_probe_prompt_cap)

def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:
return LatentInjectionMixin._attempt_prestore_hook(self, attempt, seq)
Expand Down Expand Up @@ -278,7 +276,7 @@ class LatentInjectionReportFull(Probe, LatentInjectionMixin):
def __init__(self, config_root=_config):
super().__init__(config_root)
self.payload_triggers = garak.payloads.load(self.payload_name).payloads
self._build_prompts_triggers()
self._build_prompts_triggers(cap=config_root.run.soft_probe_prompt_cap)

def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:
return LatentInjectionMixin._attempt_prestore_hook(self, attempt, seq)
Expand Down Expand Up @@ -386,7 +384,7 @@ class LatentInjectionResumeFull(Probe, LatentInjectionMixin):

def __init__(self, config_root=_config):
super().__init__(config_root)
self._build_prompts_triggers()
self._build_prompts_triggers(cap=config_root.run.soft_probe_prompt_cap)

def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:
return LatentInjectionMixin._attempt_prestore_hook(self, attempt, seq)
Expand Down Expand Up @@ -449,7 +447,7 @@ def __init__(self, config_root=_config):
+ "\n".join(self.paragraphs[i:])
)

self._build_prompts_triggers()
self._build_prompts_triggers(cap=config_root.run.soft_probe_prompt_cap)

def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:
return LatentInjectionMixin._attempt_prestore_hook(self, attempt, seq)
Expand Down Expand Up @@ -547,7 +545,7 @@ class LatentJailbreakFull(LatentInjectionMixin, Probe):

def __init__(self, config_root=_config):
super().__init__(config_root)
self._build_prompts_triggers()
self._build_prompts_triggers(cap=config_root.run.soft_probe_prompt_cap)

def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:
return LatentInjectionMixin._attempt_prestore_hook(self, attempt, seq)
Expand Down Expand Up @@ -602,7 +600,7 @@ class LatentWhois(Probe, LatentInjectionMixin):

def __init__(self, config_root=_config):
super().__init__(config_root)
self._build_prompts_triggers()
self._build_prompts_triggers(cap=config_root.run.soft_probe_prompt_cap)

def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:
return LatentInjectionMixin._attempt_prestore_hook(self, attempt, seq)
Expand Down Expand Up @@ -659,7 +657,7 @@ def __init__(self, config_root=_config):
context = context.replace("{INJECTION_MARKER}", self.non_injection_text)
self.contexts.append(context)

self._build_prompts_triggers()
self._build_prompts_triggers(cap=config_root.run.soft_probe_prompt_cap)

def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:
return LatentInjectionMixin._attempt_prestore_hook(self, attempt, seq)
Expand Down
11 changes: 6 additions & 5 deletions garak/probes/phrasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@


class TenseMini:
def _minify_prompts(self):
random.shuffle(self.prompts)
self.prompts = self.prompts[: _config.run.soft_probe_prompt_cap]
def _minify_prompts(self, cap=None):
if cap is not None:
random.shuffle(self.prompts)
self.prompts = self.prompts[:cap]


class PastTenseFull(Probe):
Expand Down Expand Up @@ -61,7 +62,7 @@ class PastTense(PastTenseFull, TenseMini):

def __init__(self, config_root=_config):
super().__init__(config_root=config_root)
self._minify_prompts()
self._minify_prompts(cap=config_root.run.soft_probe_prompt_cap)


class FutureTenseFull(Probe):
Expand Down Expand Up @@ -107,4 +108,4 @@ class FutureTense(FutureTenseFull, TenseMini):

def __init__(self, config_root=_config):
super().__init__(config_root=config_root)
self._minify_prompts()
self._minify_prompts(cap=config_root.run.soft_probe_prompt_cap)
2 changes: 1 addition & 1 deletion garak/probes/promptinject.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def constructor(self, config_root=_config):
prompt_data,
)

self.max_prompts = _config.run.soft_probe_prompt_cap
self.max_prompts = config_root.run.soft_probe_prompt_cap
if self.__class__.__name__.endswith("Full"):
self.max_prompts = None

Expand Down

0 comments on commit 7310811

Please sign in to comment.