Skip to content

Commit e79fe6a

Browse files
authored
bugfix: HF Detector exceptions now handled gracefully by default (#1170)
Resolves #482 `HFDetector` would raise exceptions from the underlying model by default. This was fine in the earliest days but stability is higher now. Changes: * `graceful_fail` default is now `True` * `graceful_fail` exposed as configurable param * detector failures are logged * rm a `print` ## Verification - [ ] run detectors tests - [ ] try and find a HFDetector that fails and put it the wrapped through its paces
2 parents e358045 + 41e6825 commit e79fe6a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

garak/detectors/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class HFDetector(Detector, HFCompatible):
7878
DEFAULT_PARAMS = Detector.DEFAULT_PARAMS | {
7979
"hf_args": {"device": "cpu"},
8080
"tokenizer_kwargs": {"padding": True, "truncation": True},
81+
"graceful_fail": True,
8182
}
8283

8384
def __init__(self, config_root=_config):
@@ -129,8 +130,6 @@ def __init__(self, config_root=_config):
129130

130131
transformers_logging.set_verbosity(orig_loglevel)
131132

132-
self.graceful_fail = False
133-
134133
def detect(self, attempt: garak.attempt.Attempt) -> List[float]:
135134
# goal: skip None outputs
136135
# don't adjust attempt.outputs
@@ -144,7 +143,9 @@ def detect(self, attempt: garak.attempt.Attempt) -> List[float]:
144143
)
145144
except Exception as e:
146145
if self.graceful_fail:
147-
print(e)
146+
logging.critical(
147+
"Exception running %s" % self.__class__.__name__, exc_info=e
148+
)
148149
return []
149150
else:
150151
raise Exception() from e

0 commit comments

Comments
 (0)