FIX Propagate GCG random_seed to all RNG sources for deterministic runs - #2502
Open
Amruth Vamshi (AmruthVamshi) wants to merge 3 commits into
Open
FIX Propagate GCG random_seed to all RNG sources for deterministic runs#2502Amruth Vamshi (AmruthVamshi) wants to merge 3 commits into
Amruth Vamshi (AmruthVamshi) wants to merge 3 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
Fixes #2490.
GCGAlgorithmConfig.random_seedonly seeded CSV row shuffling. The three RNG call sites in the optimization loop used unseeded global state, making runs non-reproducible even with the same seed.Replace global RNG calls with local seeded instances:
np.random.default_rng(seed)for target augmentationtorch.Generator(device=device).manual_seed(seed)for candidate samplingrandom.Random(seed)for annealing acceptanceThis ensures same seed = same results, concurrent runs are isolated, and custom extension points (via
SamplingStrategyprotocol) remain backward compatible.Builds on #2467 by upgrading its global
random.seed()stopgap to use the properrandom_seedparameter.Tests and Documentation
TestRandomSeedDeterminismclass (9 tests) intest_gcg_core.pycovering: determinism for each RNG source, different-seed divergence, concurrent isolation, torch generator threading, and custom sampler backward compatibility.test_run_state.pyto use therandom_seedparameter instead of globalrandom.seed()calls.random_seeddocstring already describes the intended behavior; this PR makes it truthful.Local GPU verification script
Local GPU verification output
GCG Determinism Test — GPU, GPT-2
[Test 1] Single-model, single-prompt — same seed (42)...
[transformers]
torch_dtypeis deprecated! Usedtypeinstead!Loading weights: 100%|████████████████| 148/148 [00:00<00:00, 2978.82it/s]
loss=3.1953: 100%|███████████████████| 1/1 [00:00<00:00, 2.51it/s]
loss=2.9805: 100%|███████████████████| 1/1 [00:00<00:00, 3.07it/s]
loss=2.8398: 100%|███████████████████| 1/1 [00:00<00:00, 3.23it/s]
Loading weights: 100%|████████████████| 148/148 [00:00<00:00, 2307.39it/s]
loss=3.1953: 100%|███████████████████| 1/1 [00:00<00:00, 3.09it/s]
loss=2.9805: 100%|███████████████████| 1/1 [00:00<00:00, 3.12it/s]
loss=2.8398: 100%|███████████████████| 1/1 [00:00<00:00, 3.32it/s]
Run 1: suffix='! ! ! ! ! ! !again ! !ational ! ! ! ! ! ! ! ! !' loss=2.8398
Run 2: suffix='! ! ! ! ! ! !again ! !ational ! ! ! ! ! ! ! ! !' loss=2.8398
PASS
[Test 2] Single-model, single-prompt — different seed (99)...
Loading weights: 100%|███████████████| 148/148 [00:00<00:00, 2337.70it/s]
loss=3.0156: 100%|██████████████████| 1/1 [00:00<00:00, 3.32it/s]
loss=2.8867: 100%|██████████████████| 1/1 [00:00<00:00, 3.18it/s]
loss=2.8184: 100%|██████████████████| 1/1 [00:00<00:00, 3.27it/s]
Run 3: suffix='! ! ! ! ! ! ! ! ! ! ! ! ! ! !mm !SG ! !' loss=2.8184
PASS