You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
ProgressiveMultiPromptAttack.run in pyrit/executor/promptgen/gcg/attack/base/attack_manager.py spans roughly 130 lines with eight levels of nesting. It coordinates optimizer iteration state, candidate generation, filtering, batch scoring, loss computation, candidate selection, stopping conditions, and result bookkeeping in one loop.
The coupling makes algorithm changes difficult to test in isolation and increases parameter/state fan-out. This is especially relevant to the performance work tracked in #962: faster sampling or scoring strategies are harder to integrate safely while the iteration lifecycle remains implicit.
This issue is not a duplicate of #962. Issue #962 tracks faster GCG approaches; this issue tracks the internal structure needed to make optimization changes testable and maintainable. Implementations should coordinate with that issue.
Describe the solution you'd like
Introduce a typed optimization-iteration state object that captures the current suffix/candidates, losses, best result, counters, and stop reason. Separate the loop into explicit phases with stable contracts:
candidate generation;
candidate filtering and batching;
model scoring/loss computation;
candidate selection and state update;
stopping and final result construction.
Keep extension protocols and public attack behavior compatible. The goal is to reduce state fan-out and make each phase deterministic under seeded tests, not to redesign the GCG algorithm in the same change.
Describe alternatives you've considered, if relevant
A performance-only patch under #962 could modify the current loop directly, but that would compound special cases. Conversely, a broad class hierarchy for every phase would add unnecessary abstraction. Prefer typed data plus a small number of cohesive internal functions.
Additional context
Validation should include:
deterministic seeded optimizer tests;
candidate ordering and batch boundaries;
exact loss/selection behavior;
early-stop and retry/exhaustion paths;
extension protocol implementations;
device/dtype and tokenization boundaries;
result/status equivalence before and after the refactor;
Is your feature request related to a problem? Please describe.
ProgressiveMultiPromptAttack.runinpyrit/executor/promptgen/gcg/attack/base/attack_manager.pyspans roughly 130 lines with eight levels of nesting. It coordinates optimizer iteration state, candidate generation, filtering, batch scoring, loss computation, candidate selection, stopping conditions, and result bookkeeping in one loop.The coupling makes algorithm changes difficult to test in isolation and increases parameter/state fan-out. This is especially relevant to the performance work tracked in #962: faster sampling or scoring strategies are harder to integrate safely while the iteration lifecycle remains implicit.
This issue is not a duplicate of #962. Issue #962 tracks faster GCG approaches; this issue tracks the internal structure needed to make optimization changes testable and maintainable. Implementations should coordinate with that issue.
Describe the solution you'd like
Introduce a typed optimization-iteration state object that captures the current suffix/candidates, losses, best result, counters, and stop reason. Separate the loop into explicit phases with stable contracts:
Keep extension protocols and public attack behavior compatible. The goal is to reduce state fan-out and make each phase deterministic under seeded tests, not to redesign the GCG algorithm in the same change.
Describe alternatives you've considered, if relevant
A performance-only patch under #962 could modify the current loop directly, but that would compound special cases. Conversely, a broad class hierarchy for every phase would add unnecessary abstraction. Prefer typed data plus a small number of cohesive internal functions.
Additional context
Validation should include:
This is high-risk algorithmic code. Keep the refactor behavior-preserving and coordinate scope with #962.