Repository navigation
TEST: Add opt-in GPU smoke test for GCG on a real checkpoint - #4167
Merged
Roman Lutz (romanlutz) merged 3 commits intoNov 11, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 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]>
Roman Lutz (romanlutz)
approved these changes
Nov 11, 2026
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.

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_checkpointrunsGCGGeneratorfor 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_changetakes the token gradient fromGCGAttackPrompt.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:
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 afterexecute_asyncreturns.Contributes to #2489.