MAINT GCG: make optimization iteration state explicit and typed - #2467
Open
fei (feiiiiii5) wants to merge 1 commit into
Open
MAINT GCG: make optimization iteration state explicit and typed#2467fei (feiiiiii5) wants to merge 1 commit into
fei (feiiiiii5) wants to merge 1 commit into
Conversation
Implements the structural half of microsoft#2416 while keeping public attack behavior and extension protocols unchanged. - add StopReason enum plus typed OptimizationRunState and ProgressiveScheduleState dataclasses capturing suffix, losses, best result, counters, and stop reason - MultiPromptAttack.run now tracks state through the typed object and exposes it as last_run_state; stopping and periodic logging phases are extracted into _all_training_prompts_jailbroken and _log_best_checkpoint with stable contracts - ProgressiveMultiPromptAttack.run tracks admission scheduling through ProgressiveScheduleState (exposed as last_schedule_state) and moves final evaluation into _finalize_progressive_run - GCGMultiPromptAttack extracts the candidate-selection phase into _select_best_candidate; candidate batches intentionally remain step-local to bound VRAM - add deterministic seeded regression tests covering stop reasons, best tracking under annealing rejection, checkpoint restore, argmin decomposition across worker groups, and progressive finalize path
fei (feiiiiii5)
force-pushed
the
issue2416/typed-optimization-run-state
branch
from
August 22, 2026 20:37
181851a to
b718775
Compare
Contributor
Author
|
Rebased onto current
|
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.
Purpose
Implements the structural refactor requested in #2416: a typed optimization-iteration state for the GCG loop, with the iteration lifecycle made explicit — while keeping public attack behavior and extension protocols unchanged.
Closes #2416
What changed
Typed state (
attack_manager.py)StopReasonenum:MAX_STEPS_REACHED,ALL_PROMPTS_JAILBROKENOptimizationRunStatedataclass: current suffix, best suffix, current/best loss, step counter, step runtime, stop reason. Exposed asMultiPromptAttack.last_run_stateafterrun(), so callers and tests can programmatically inspect why/when optimization stoppedProgressiveScheduleStatedataclass: goals/workers admitted so far, shared step counter, loss carry-over, inner stop flag. Exposed asProgressiveMultiPromptAttack.last_schedule_stateExplicit phases with stable contracts
MultiPromptAttack.run: stopping phase extracted to_all_training_prompts_jailbroken(); periodic logging phase extracted to_log_best_checkpoint()(same best-suffix swap-and-restore semantics as before, now with afinallyguarantee)ProgressiveMultiPromptAttack.run: scheduling counters moved intoProgressiveScheduleState; final evaluation extracted to_finalize_progressive_run()GCGMultiPromptAttack.step: selection phase (flat argmin → group/in-batch decomposition) extracted to_select_best_candidate(). Candidate batches intentionally remain step-local to preserve the existing VRAM-bounding behavior noted in the loop commentCompatibility
run()still returns(control, loss, steps)/(control, steps)); the new attributes are additiveValidation
tests/unit/executor/promptgen/gcg/test_run_state.py(12 tests): stop-reason assignment (incl. that the final success check does not count as an executed step), best tracking under annealing rejection, periodic checkpoint restore contract, seeded identical trajectories, argmin decomposition across worker groups, progressive finalize path with call-through assertions on the inner attack logruff check+ruff format --checkclean with the repo-pinned ruff v0.16.0AI usage disclosure
Human verification: I reviewed the diff hunk-by-hunk against the pre-refactor control flow, confirmed the annealing acceptance rule, admission ordering, weight bump threshold (
<= 0.09), and return semantics are preserved, and re-derived the argmin index decomposition used in the selection tests.