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

Add ConversationalPipeline for huggingface models #539

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions garak/generators/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def __init__(self, name, do_sample=True, generations=10, device=0):
do_sample=do_sample,
device=device,
)
self.device = device
self.conversation = Conversation()
self.deprefix_prompt = name in models_to_deprefix
if _config.loaded:
Expand Down
6 changes: 3 additions & 3 deletions garak/resources/tap/generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Union

from garak.generators.openai import chat_models, OpenAIGenerator
from garak.generators.huggingface import Model
from garak.generators.huggingface import ConversationalPipeline

erickgalinkin marked this conversation as resolved.
Show resolved Hide resolved
supported_openai = chat_models
supported_huggingface = [
Expand Down Expand Up @@ -51,15 +51,15 @@ def load_generator(
generations=generations,
)
elif model_name in supported_huggingface:
generator = Model(model_name, generations=generations, device=device)
generator = ConversationalPipeline(model_name, generations=generations, device=device)
else:
msg = (
f"{model_name} is not currently supported for TAP generation. Support is available for the following "
f"OpenAI and HuggingFace models:\nOpenAI: {supported_openai}\nHuggingFace: {supported_huggingface}\n"
f"Your jailbreaks will *NOT* be saved."
)
print(msg)
generator = Model(model_name, generations=generations, device=device)
generator = ConversationalPipeline(model_name, generations=generations, device=device)

generator.max_tokens = max_tokens
if temperature is not None:
Expand Down
2 changes: 1 addition & 1 deletion garak/resources/tap/tap_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_attack(self, convs, prompts):
continue

for full_prompt in full_prompts_subset[left:right]:
outputs_list.append(self.attack_generator.generate(full_prompt)[0])
outputs_list.append(self.attack_generator.generate(full_prompt))
erickgalinkin marked this conversation as resolved.
Show resolved Hide resolved

# Check for valid outputs and update the list
new_indices_to_regenerate = []
Expand Down
Loading