Repository navigation
MAINT: Make promptgen GCG signatures keyword-only - #4693
Open
Roman Lutz (romanlutz) wants to merge 3 commits into
Open
Roman Lutz (romanlutz) wants to merge 3 commits into
Roman Lutz (romanlutz) wants to merge 3 commits into
Conversation
Clear all 39 pyrit.executor.promptgen.gcg entries from the keyword-only baseline. Each callable now declares at most one positional parameter: - attack_manager: AttackPrompt, PromptManager, MultiPromptAttack, ProgressiveMultiPromptAttack, IndividualPromptAttack, EvaluateAttack and ModelWorker methods/constructors, the nested acceptance_probability, and the module functions get_embeddings, get_nonascii_toks, get_workers - gcg_attack: token_gradients, GCGPromptManager.sample_control, GCGMultiPromptAttack.__init__ - experiments/run: _main_async The first parameter stays positional where a contract relies on it: ModelWorker._execute_task dispatches operations as method(model, ...), so worker-dispatched methods (generate, generate_str, test, logits, loss) keep model positional; ModelWorker.run goes fully keyword-only and is started via mp.Process(kwargs=...). Call sites updated throughout (managers["AP"/"PM"/"MPA"] factory calls, candidate_evaluator worker dispatch, generator, tests, stubs). Per microsoft#4216 the GCG module is experimental, so no deprecation shims even for public-looking names. No behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the GCG keyword-only migration.
No open issues 🎉
What changed in this PR
This PR advances the keyword-only migration in #4216 for PyRIT’s experimental GCG prompt generator. It changes signatures directly under the stated maintainer decision, while preserving positional model arguments required by worker dispatch.
Changes:
- Migrates GCG signatures and removes 39 entries from the keyword-only baseline.
- Updates factories, worker dispatch, process startup, and experiment callers to use keyword arguments.
- Aligns existing unit tests, integration tests, and trajectory stubs with the new call shapes.
| File | Description |
|---|---|
tests/unit/executor/promptgen/gcg/trajectory_stubs.py |
Forwards and consumes worker keyword arguments. |
tests/unit/executor/promptgen/gcg/test_run_state.py |
Updates logging assertions for keyword calls. |
tests/unit/executor/promptgen/gcg/test_multi_prompt_attack.py |
Allows keyword arguments in the attack factory stub. |
tests/unit/executor/promptgen/gcg/test_gcg_evaluation.py |
Updates loss, logits, and worker-dispatch expectations. |
tests/unit/executor/promptgen/gcg/test_gcg_core.py |
Aligns core calls, mocks, and assertions with migrated signatures. |
tests/unit/executor/promptgen/gcg/test_default_implementations.py |
Updates reference calls and related docstring examples. |
tests/unit/executor/promptgen/gcg/test_data_and_config.py |
Passes experiment paths by keyword. |
tests/integration/executor/promptgen/gcg/test_gcg_integration.py |
Updates gradient and embedding calls. |
pyrit/executor/promptgen/gcg/generator.py |
Constructs attacks with named arguments. |
pyrit/executor/promptgen/gcg/experiments/run.py |
Makes the async entry point keyword-only and updates its caller. |
pyrit/executor/promptgen/gcg/attack/gcg/gcg_attack.py |
Migrates GCG signatures and superclass forwarding. |
pyrit/executor/promptgen/gcg/attack/gcg/candidate_evaluator.py |
Sends loss and logits parameters as worker keyword arguments. |
pyrit/executor/promptgen/gcg/attack/base/attack_manager.py |
Migrates base signatures, internal calls, and process startup. |
build_scripts/keyword_only_baseline.txt |
Removes the 39 migrated GCG exceptions. |
Review effort: Balanced
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The diff-coverage gate flagged seven migrated lines with no executing test: AttackPrompt.test and test_loss, the PromptManager generate/generate_str/test forwarders, and ModelWorker.start's mp.Process(kwargs=...) spawn. Add unit tests for each. The if __name__ entry line in experiments/run.py is the AzureML job entry point, excluded with a pragma like other unexecutable lines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Roman Lutz (romanlutz)
added a commit
to Aadithya-kl/PyRIT
that referenced
this pull request
Nov 27, 2026
The keyword-only migration in microsoft#4693 makes control_cand keyword-only; using the keyword form now keeps these new tests valid in either merge order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Roman Lutz (romanlutz)
added a commit
to devangpratap/PyRIT
that referenced
this pull request
Nov 27, 2026
Matches the worker test in test_gcg_core.py and stays compatible with the keyword-only ModelWorker.__init__ proposed in microsoft#4693. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Part of the keyword-only migration campaign (#4216): makes every callable in the experimental promptgen GCG module comply with the keyword-only convention and clears all 39
pyrit.executor.promptgen.gcg.*entries frombuild_scripts/keyword_only_baseline.txt. Per maintainer decision on #4216, this experimental module gets no deprecation cycle even for public-looking names, so signatures change directly.*to the signatures inattack.base.attack_manager(AttackPrompt,PromptManager,MultiPromptAttackincluding the nestedacceptance_probability,ProgressiveMultiPromptAttack,IndividualPromptAttack,EvaluateAttack,ModelWorker, and the module functionsget_embeddings,get_nonascii_toks,get_workers),attack.gcg.gcg_attack(token_gradients,GCGPromptManager.sample_control,GCGMultiPromptAttack.__init__), andexperiments.run:_main_async.ModelWorker._execute_taskdispatches operations asmethod(model, *args, **kwargs), so the worker-dispatched methods (generate,generate_str,test,logits,loss) keepmodelpositional (the checker allows one positional parameter).ModelWorker.runis fully keyword-only and is now started viamp.Process(kwargs=...).managers["AP"/"PM"/"MPA"]factory calls, the worker LOSS/LOGITS dispatches incandidate_evaluator,generator._create_attack, the unit tests and trajectory stubs, and the integration tests.check_keyword_only_params.pypasses. No behavior change, no deprecation shims.Reviewer note: the GCG attack tests under
tests/unit/executor/promptgen/gcgare torch-dependent, so CI is the authoritative run for them; call-site consistency was additionally verified statically across the module and its tests.Related: #4216, #3960
🤖 Generated with Claude Code