Skip to content

TEST: Add opt-in GPU smoke test for GCG on a real checkpoint - #4167

Merged
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
devangpratap:feat-gcg-gpu-smoke-test
Nov 11, 2026
Merged

Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
devangpratap:feat-gcg-gpu-smoke-test

Conversation

@devangpratap

Copy link
Copy Markdown
Contributor

PR 8 of the #2489 series: an opt-in GPU smoke test for GCG on a real checkpoint.

Adds test_gcg_gpu_smoke_integration.py, which runs the full Qwen2.5-0.5B-Instruct checkpoint on a CUDA GPU:

  • test_gcg_lowers_target_loss_on_real_checkpoint runs GCGGenerator for five steps with real worker subprocesses. It checks that the loss goes down, then recomputes the target loss for the final suffix with the model directly and checks it matches the logged loss. A short run lowers the loss even with a random gradient, so the second check is what ties the result to real candidate scoring.
  • test_gradient_predicts_loss_change takes the token gradient from GCGAttackPrompt.grad, makes 2048 random single-token swaps, and checks that the Spearman correlation between the gradient's predicted change and the actual loss is above 0.1.

To make sure the tests catch broken code, I patched main on a Kaggle T4:

  • unchanged: correlation 0.141, recomputed loss 0.5813 vs logged 0.5815, both pass
  • random gradient: correlation 0.000, 0.057, -0.003 over three runs, fails
  • negated gradient: -0.141, fails
  • picking the worst candidate instead of the best: the loss stops going down, fails
  • random candidate scores: recomputed 0.880 vs logged 0.001, fails

Both tests are marked run_only_if_all_tests, skip without a GPU, and take about two minutes on a T4. Loading a second copy of the model in the test process before the run hung the workers, so the model is loaded only after execute_async returns.

Contributes to #2489.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 18:52

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.

🟡 Changes recommended

The smoke test’s double-argsort ranking mishandles ties, allowing constant vectors to report perfect correlation and no-signal regressions to pass.

1 open issue
What changed in this PR

Adds opt-in GPU integration coverage for GCG on Qwen2.5-0.5B-Instruct, supporting the modern-model compatibility work in #2489.

Changes:

  • Exercises five optimization steps with real workers and compares the final logged loss with a direct model calculation.
  • Checks whether token gradients predict loss changes across random single-token swaps.
  • Documents CUDA requirements, opt-in configuration, and expected runtime.
File Description
tests/​integration/​executor/​promptgen/​gcg/​test_gcg_gpu_smoke_integration.py Adds end-to-end optimization and gradient-correlation GPU tests.
pyrit/​executor/​promptgen/​gcg/​experiments/​README.md Documents the smoke tests, requirements, and runtime.

Review effort: Balanced

- Use tie-aware scipy.stats.spearmanr for the gradient correlation check:
  a constant vector (e.g. an all-zeros gradient) now yields nan and fails
  instead of relying on double-argsort tie breaking (Copilot review comment).
  Identical to the previous formula on tie-free data, so the 0.1 threshold
  keeps its calibration.
- Add a 900s timeout to test_gradient_predicts_loss_change so a standalone
  run with a hung checkpoint download cannot hang the suite.
- Document the ordering constraint on the module-scoped model fixture
  (must not load before the full run's worker subprocesses start).

Co-Authored-By: Claude Fable 5 <[email protected]>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 11, 2026
Merged via the queue into microsoft:main with commit 78fb997 Nov 11, 2026
62 checks passed
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