Skip to content

[DRAFT ] - Simple Adaptive Jailbreaking - #537

Closed
Dan Jones (donebydan) wants to merge 7 commits into
microsoft:mainfrom
donebydan:adaptive-jailbreaking
Closed

Dan Jones (donebydan) wants to merge 7 commits into
microsoft:mainfrom
donebydan:adaptive-jailbreaking

Conversation

@donebydan

Copy link
Copy Markdown

Description

#266
Roman Lutz (@romanlutz) @rlundeen2

Tests and Documentation

TODO

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be converted into a notebook for documentation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should live under doc/code/orchestrators

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or auxiliary_attacks instead of orchestrators. The more I think about it the more I feel like it's more like GCG than other orchestrators.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prompt not used but could be later. It is from the paper directly.

model=self._deployment_name,
max_completion_tokens=self._max_completion_tokens,
max_tokens=self._max_tokens,
max_tokens=self._max_tokens, # TODO: this is given as NOT_GIVEN?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO comes from inability to alter prompt target max tokens from orchestrator. I need to test.

frequency_penalty=self._frequency_penalty,
presence_penalty=self._presence_penalty,
logprobs=self._logprobs,
top_logprobs=self._top_logprobs, # TODO: when called and logprobs is False, this param is not passed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO is a bit trickier. When logprobs is None, we shouldn't pass top_logprobs

@romanlutz Roman Lutz (romanlutz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Thanks for putting in all this work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should live under doc/code/orchestrators

# Original prompt id defaults to id (assumes that this is the original prompt, not a duplicate)
self.original_prompt_id = original_prompt_id or self.id

self.logprobs = logprobs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for @rlundeen2 / Raja Sekhar Rao Dheekonda (@rdheekonda) : We can create a follow-up task to add this to the DB schema

response_type: PromptDataType = "text",
prompt_metadata: Optional[str] = None,
error: PromptResponseError = "none",
logprobs: Optional[dict] = None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logprobs: Optional[dict] = None,
logprobs: Optional[Dict[str, float]] = None,

Is that right?

attacker_suggested_prompt = json_response["prompt"]
except (json.JSONDecodeError, KeyError):
# This forces the @pyrit_json_retry decorator to retry the function
breakpoint()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will have to go 😄


class SimpleAdaptiveOrchestrator(Orchestrator):
"""
This orchestrator implements the Prompt Automatic Iterative Refinement (PAIR) algorithm

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect your notebook will elaborate but a paragraph on the intuition behind the algorithm wouldn't hurt 🙂


def _adjust_adversarial_suffix(self) -> str:
"""
Randomly changes the adversarial suffix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be more similar to the method name 😆 _change_suffix_randomly

if "Sure" in message:
breakpoint()

if self._desired_target_response_prefix in message[:len(self._desired_target_response_prefix)]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be == or in?

self._best_logprobs = sum(logprob_dict.values())
self._best_logprobs_dict = logprob_dict
self._best_adversarial_suffix = self._adversarial_suffix
elif " " + self._desired_target_response_prefix in message:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this all about? Seems identical except for a leading space?!

if self._best_logprobs == -np.inf:
breakpoint()
logger.info(f"No improvement in logprobs after {self._number_of_iterations} iterations.")
return jailbreaks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multi-turn orchestrators we've added MultiTurnAttackResult just becaue every orchestrator was returning something custom and that's super annoying. Maybe we can use something similar?

return float(score_value) >= self._scorer_sensitivity


async def run(self) -> list[PromptRequestResponse]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly standardized yet but we seem to be converging towards run_attack_async as the name for this thing.

@richlundeen

Copy link
Copy Markdown
Contributor

Closing for now but please feel free to re-open when you're ready for us to look again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants