Skip to content

MAINT: Bring GCG under Ruff and ty checks - #2218

Merged
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-gcg-tooling-cleanup
Jul 17, 2026
Merged

MAINT: Bring GCG under Ruff and ty checks#2218
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-gcg-tooling-cleanup

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

GCG was excluded from repository-wide Ruff and ty enforcement, allowing its implementation to drift from current project standards. This change removes those exclusions and makes the GCG prompt generator pass the same formatting, linting, and type-checking gates as the rest of pyrit/.

The cleanup adds precise typing and documentation, replaces suppressed findings with explicit validation, and preserves the legacy LengthPreservingFilter(filter=...) keyword while introducing the clearer enabled name. It also fixes the non-verbose optimization loop so it iterates prompt indices consistently with the verbose path and adds fail-fast checks for invalid worker and gradient states.

The local ty hook now installs the all extra so optional GCG dependencies such as torch are available during checking.

Tests and Documentation

  • uv run --no-sync pre-commit run check-yaml --files .pre-commit-config.yaml
  • uv run --no-sync pre-commit run ruff-format --all-files
  • uv run --no-sync pre-commit run ruff-check --all-files
  • uv run --no-sync pre-commit run ty-check --all-files
  • uv run --no-sync pytest -q tests\unit\executor\promptgen\gcg (172 passed)

Updated GCG API and implementation docstrings as required by the newly enabled Ruff rules. JupyText was not run because no notebook or documentation sample changed.

Copilot AI added 2 commits July 16, 2026 11:00
Bring the GCG prompt generator under the repository Ruff and ty checks, clean up the implementation to satisfy those checks, and preserve compatibility for the candidate filter API.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e5f725f4-b97c-4fb9-b49c-a1db82f68399
Exercise the validation, logging, worker startup, annealing, and extension error paths added by the GCG tooling cleanup.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e5f725f4-b97c-4fb9-b49c-a1db82f68399
@jsong468 jsong468 self-assigned this Jul 17, 2026
Comment thread pyrit/executor/promptgen/gcg/default_implementations.py
Comment thread pyrit/executor/promptgen/gcg/default_implementations.py
Prevent the legacy filter keyword from silently overriding the enabled option when both are supplied.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e5f725f4-b97c-4fb9-b49c-a1db82f68399
@romanlutz
romanlutz added this pull request to the merge queue Jul 17, 2026
Merged via the queue into microsoft:main with commit 8af0e02 Jul 17, 2026
53 checks passed
@romanlutz
romanlutz deleted the romanlutz-gcg-tooling-cleanup branch July 17, 2026 23:01
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.

3 participants