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

convert mutation_generator to use load_plugin #795

Merged
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
11 changes: 7 additions & 4 deletions garak/resources/autodan/autodan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

import gc

from garak.generators import Generator, load_generator
from garak._plugins import load_plugin
from garak.generators import Generator
from garak.generators.huggingface import Model
import garak._config
from garak.resources.autodan.genetic import (
Expand Down Expand Up @@ -133,10 +134,12 @@ def autodan_generate(
crit = nn.CrossEntropyLoss(reduction="mean")

config_root = {
{mutation_generator_type: {"name": mutation_generator_name, "generations": 1}}
"generators": {
mutation_generator_type: {"name": mutation_generator_name, "generations": 1}
}
}
mutation_generator = load_generator(
model_type=mutation_generator_type, config=config_root
mutation_generator = load_plugin(
"generators." + mutation_generator_type, config_root=config_root
)

# Feel like this could just be text instead of storing it as tensors.
Expand Down
2 changes: 1 addition & 1 deletion garak/resources/autodan/genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def get_score_autodan(
losses = []
input_ids_list = []
target_slices = []
device = generator.device if generator.device >= 0 else "cpu"
device = generator.device
for item in test_controls:
prefix_manager = AutoDanPrefixManager(
generator=generator,
Expand Down
Loading