Skip to content

Add Combination Attack - #3

Open
ishayyemini wants to merge 73 commits into
mainfrom
ishay-testing
Open

Add Combination Attack#3
ishayyemini wants to merge 73 commits into
mainfrom
ishay-testing

Conversation

@ishayyemini

Copy link
Copy Markdown

This PR adds the Combinatio Attack optimizer.

# Conflicts:
#	.github/workflows/deploy_docs.yml
#	README.md
#	docs/api/attack_zoo.rst
#	docs/api/loss.rst
#	docs/api/models.rst
#	docs/api/optimizer.rst
#	docs/build_docs.py
#	pyproject.toml
#	scripts/attack_evaluate/evaluate_jailbreakness.py
#	tests/models/huggingface/test_encoder.py
#	tests/models/huggingface/test_lm.py
#	tests/optimizer/test_base_optimizer.py
#	tests/optimizer/test_gaslite_optimizer.py
#	tests/optimizer/test_gcg_optimizer.py
#	tests/optimizer/test_rasliteplus_optimizer.py
#	tropt/attack_zoo/RASLITEPlus.py
#	tropt/common.py
#	tropt/loss/__init__.py
#	tropt/loss/base.py
#	tropt/models/__init__.py
#	tropt/models/google/encoder.py
#	tropt/models/huggingface/base.py
#	tropt/models/huggingface/encoder.py
#	tropt/models/huggingface/lm.py
#	tropt/models/inputs.py
#	tropt/models/model_mixins.py
#	tropt/models/openai/__init__.py
#	tropt/models/openai/encoder.py
#	tropt/optimizer/base.py
#	tropt/optimizer/beast_optimizer.py
#	tropt/optimizer/gaslite_optimizer.py
#	tropt/optimizer/gasliteplus_optimizer.py
#	tropt/optimizer/gcg_optimizer.py
#	tropt/optimizer/rasliteplus_optimizer.py
#	tropt/optimizer/utils/token_constraints.py

# Iteratively append tokens one by one to reach total_tokens. This is a greedy approach:
# once a token is selected for position N, it is fixed, and we optimize position N+1.
for n in range(self.total_tokens - len(tokens)):

@ishayyemini ishayyemini May 17, 2026

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.

Matan asked: so if we optimize a relatively short trigger we skip this step? isn't this limiting if we'd like to train more stealthy, short triggers?

This is just after the hot start, which generates 10-20 tokens. If you want a really short trigger, you can either still stay with the hot start, and let’s say the hot start “filled up” the trigger length. Then we randomize in square attack.

)
return result

def _p_selection(self, it: int) -> float:

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.

Matan asked: just out of curiosity - how did you converse to this very specific function?

It follows the original function from the original square attack: https://github.com/max-andr/square-attack/blob/ea95eebb5aca62ec790a927b5aa985ba4e87245c/attack.py#L12

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.

2 participants