MAINT GCG: extract candidate proposal phase (#2665) - #2671
Open
Vardhman Gupta (Kaap10) wants to merge 2 commits into
Open
Vardhman Gupta (Kaap10) wants to merge 2 commits into
Vardhman Gupta (Kaap10) wants to merge 2 commits into
Conversation
Author
|
@microsoft-github-policy-service agree |
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
This PR addresses Item 1 (Extract candidate proposal) of umbrella issue #2665, completing the first phase of the GCG optimization phase extraction following #2416 and merged PR #2467.
Tagging Roman Lutz (@romanlutz) as requested on #2665.
Key Changes:
GCGCandidateProposer: Extracted worker gradient dispatch, cross-device tensor migration tomain_device,CandidateProposalBatch: Introduced an immutable typed@dataclass(frozen=True, slots=True)encapsulatingcontrol_candidates_by_groupandgroup_worker_indices.GCGMultiPromptAttack.step(): Replaced ~50 lines of entangled inline gradient collection and sampling loop with clean delegation toGCGCandidateProposer._sample_control_candidates()and_filter_control_candidates()delegation shims onGCGMultiPromptAttackto guarantee zero regressions for existing tests and subclass overrides.Non-breaking change: Public API signatures and return values remain 100% backward-compatible.
Tests and Documentation
Tests Added & Executed:
tests/unit/executor/promptgen/gcg/test_gcg_proposal.py:test_num_groups_property: ValidatesCandidateProposalBatchattributes.test_empty_workers_raises_value_error: ValidatesValueErroron empty workers.test_worker_and_prompt_count_mismatch_raises_value_error: Validates worker/prompt count parity.test_single_worker_gradient_dispatch_and_normalization: Verifiestest_same_shape_multiple_workers_accumulate_into_single_group: Verifies gradient summation on matching shapes.test_mismatched_shapes_creates_multiple_candidate_groups: Verifies shape-mismatch grouping behavior.Verification Results:
pytest tests/unit/executor/promptgen/gcg/test_gcg_proposal.py: 6/6 passed (100%)pytest tests/unit/executor/promptgen/gcg/: 249/249 passed (100% GCG suite pass)pytest tests/integration/executor/promptgen/gcg/test_gcg_attack_wiring_integration.py: 4/4 passedty check: All checks passed (0 errors)ruff check&ruff format: Clean (0 errors)pre-commit run --all-files: All hooks passed (All Green)