Repository navigation
PERF: Speed up GCG candidate evaluation - #2884
Merged
Roman Lutz (romanlutz) merged 4 commits intoSep 28, 2026
Merged
Roman Lutz (romanlutz) merged 4 commits into
Roman Lutz (romanlutz) merged 4 commits into
Conversation
Jayanth Yarlagadda (JayYarlagadda)
force-pushed
the
jay/issue-962-prefix-cache
branch
from
September 26, 2026 23:32
02a7556 to
d752b62
Compare
Contributor
Author
|
@microsoft-github-policy-service agree |
Roman Lutz (romanlutz)
requested changes
Sep 28, 2026
Jayanth Yarlagadda (JayYarlagadda)
force-pushed
the
jay/issue-962-prefix-cache
branch
from
September 28, 2026 04:40
d752b62 to
01b092f
Compare
Roman Lutz (romanlutz)
approved these changes
Sep 28, 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.
Hey Roman Lutz (@romanlutz) — I profiled the candidate-evaluation path and found that most of its time and memory were spent creating full-vocabulary logits for every candidate and then passing those tensors back to the parent process.
This PR keeps the existing multi-prompt and multi-worker design, but avoids doing that unnecessary work:
logits_to_keeponly project the positions needed for the target and control losses.Custom loss implementations still use the existing full-logits path. Prefix caching is disabled by default and can be enabled with
GCGAlgorithmConfig.use_prefix_cache.I benchmarked this on an NVIDIA A40 with
Qwen/Qwen2.5-7B-Instruct, using a batch size of 512, top-k 256, and 10 GCG steps. I ran the baseline and changed version three times each and excluded the first two steps of every run from the timing summary.With one prompt, the median step time went from 7.61s to 5.25s, a 31% improvement. With two prompts and transfer enabled, it went from 13.55s to 8.44s, a 37.7% improvement. Peak GPU memory dropped from roughly 40.5 GiB to 24.9 GiB in both cases.
The baseline and optimized versions selected the same final suffix and completed the same number of optimization steps in all six paired runs. The largest difference in the fp16 loss histories was 0.0022, which is why prefix caching remains opt-in.
Validation:
typassedWould appreciate your thoughts on the approach, especially the decision to keep prefix caching opt-in.
Addresses #962.