diff --git a/garak/generators/huggingface.py b/garak/generators/huggingface.py index d1418986..abfddc9c 100644 --- a/garak/generators/huggingface.py +++ b/garak/generators/huggingface.py @@ -80,6 +80,13 @@ def _load_client(self): pipeline_kwargs = self._gather_hf_params(hf_constructor=pipeline) self.generator = pipeline("text-generation", **pipeline_kwargs) + if self.generator.tokenizer is None: + # account for possible model without a stored tokenizer + from transformers import AutoTokenizer + + self.generator.tokenizer = AutoTokenizer.from_pretrained( + pipeline_kwargs["model"] + ) if not hasattr(self, "deprefix_prompt"): self.deprefix_prompt = self.name in models_to_deprefix if _config.loaded: