Skip to content

MAINT: Make promptgen GCG signatures keyword-only - #4693

Open
Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:claude/kwonly-promptgen-gcg-17b75a
Open

Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:claude/kwonly-promptgen-gcg-17b75a

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

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 from build_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.

  • Added * to the signatures in attack.base.attack_manager (AttackPrompt, PromptManager, MultiPromptAttack including the nested acceptance_probability, ProgressiveMultiPromptAttack, IndividualPromptAttack, EvaluateAttack, ModelWorker, and the module functions get_embeddings, get_nonascii_toks, get_workers), attack.gcg.gcg_attack (token_gradients, GCGPromptManager.sample_control, GCGMultiPromptAttack.__init__), and experiments.run:_main_async.
  • Kept the first parameter positional where a contract relies on it: ModelWorker._execute_task dispatches operations as method(model, *args, **kwargs), so the worker-dispatched methods (generate, generate_str, test, logits, loss) keep model positional (the checker allows one positional parameter). ModelWorker.run is fully keyword-only and is now started via mp.Process(kwargs=...).
  • Updated every call site: the managers["AP"/"PM"/"MPA"] factory calls, the worker LOSS/LOGITS dispatches in candidate_evaluator, generator._create_attack, the unit tests and trajectory stubs, and the integration tests.
  • Removed exactly the 39 migrated entries from the baseline; check_keyword_only_params.py passes. No behavior change, no deprecation shims.

Reviewer note: the GCG attack tests under tests/unit/executor/promptgen/gcg are 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

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>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 02:02

Copilot AI 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.

🟢 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

No deployments
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