Skip to content
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: 5 additions & 2 deletions garak/buffs/paraphrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class PegasusT5(Buff, HFCompatible):
DEFAULT_PARAMS = Buff.DEFAULT_PARAMS | {
"para_model_name": "garak-llm/pegasus_paraphrase",
"hf_args": {
"device": "cpu"
"device": "cpu",
"trust_remote_code": False,
}, # torch_dtype doesn't have standard support in Pegasus
"max_length": 60,
"temperature": 1.5,
Expand All @@ -39,7 +40,9 @@ def _load_model(self):
self.para_model = PegasusForConditionalGeneration.from_pretrained(
self.para_model_name
).to(self.device)
self.tokenizer = PegasusTokenizer.from_pretrained(self.para_model_name)
self.tokenizer = PegasusTokenizer.from_pretrained(
self.para_model_name, trust_remote_code=self.hf_args["trust_remote_code"]
)

def _get_response(self, input_text):
if self.para_model is None:
Expand Down
6 changes: 1 addition & 5 deletions garak/generators/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,11 @@ def _load_client(self):
if _config.run.seed is not None:
transformers.set_seed(_config.run.seed)

trust_remote_code = self.name.startswith("mosaicml/mpt-")

model_kwargs = self._gather_hf_params(
hf_constructor=transformers.AutoConfig.from_pretrained
) # will defer to device_map if device map was `auto` may not match self.device

self.config = transformers.AutoConfig.from_pretrained(
self.name, trust_remote_code=trust_remote_code, **model_kwargs
)
self.config = transformers.AutoConfig.from_pretrained(self.name, **model_kwargs)

self._set_hf_context_len(self.config)
self.config.init_device = self.device # determined by Pipeline `__init__``
Expand Down
8 changes: 7 additions & 1 deletion garak/resources/api/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class HFCompatible:

"""Mixin class providing private utility methods for using Huggingface
transformers within garak"""

Expand Down Expand Up @@ -79,6 +78,13 @@ def _gather_hf_params(self, hf_constructor: Callable):
del args["device"]
args["device_map"] = self.device

# trust_remote_code reset to default disabled unless unlocked in garak HF item config
if (
"trust_remote_code" in params_to_process
and "trust_remote_code" not in params
):
args["trust_remote_code"] = False

return args

def _select_hf_device(self):
Expand Down
Loading