fix(data_utils): make GPQA answer permutation reproducible#2107
Open
AUTHENSOR wants to merge 1 commit into
Open
fix(data_utils): make GPQA answer permutation reproducible#2107AUTHENSOR wants to merge 1 commit into
AUTHENSOR wants to merge 1 commit into
Conversation
preprocess_gpqa used random.shuffle(letters) with the unseeded process-global RNG. Because the permutation runs inside dataset.map(num_proc=10), each worker has independent RNG state, and across separate 'python eval.py' invocations the global RNG is re-seeded fresh. The same GPQA question therefore gets a different A/B/C/D answer mapping on every run, breaking eval reproducibility: a model that is sensitive to answer-letter position receives a different score each time the eval is run. Fix: seed a per-question RNG from a stable hash (sha256) of the question text. The same question always maps to the same permutation (reproducible across interpreter invocations and num_proc workers), while different questions still get different permutations (preserving the position-bias mitigation the shuffle exists to provide). hashlib is used rather than built-in hash() because Python string hashing is randomized per-process via PYTHONHASHSEED.
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.
Summary
preprocess_gpqainverifiers/utils/data_utils.pypermutes the answer letters withrandom.shuffle(letters)using the unseeded process-global RNG. Because:dataset.map(preprocess_fn, num_proc=10)— each of the 10 worker processes has an independent unseeded RNG state, andpython eval.pyinvocation re-seeds the global RNG fresh,…the same GPQA question gets a different A/B/C/D answer mapping on every run. This breaks eval reproducibility: a model that is sensitive to answer-letter position receives a different score each time the eval is run.
The
seedparameter inpreprocess_dataset(line ~299) seeds the HuggingFace dataset's row-order shuffle (dataset.shuffle(seed=seed)), not this answer-letter permutation — so passing--seeddoes not fix this.Reproduction
In the real eval, this means the correct answer to a given GPQA question is at a different letter position each run.
The fix
Seed a per-question RNG from a stable hash of the question text:
Properties:
num_procworkers.hashlib.sha256is used, not built-inhash(), because Python string hashing is randomized per-process viaPYTHONHASHSEED. Verified stable acrossPYTHONHASHSEED=0/1/12345/random.Verification
Same question, same permutation regardless of interpreter hash seed.
ruff checkandruff format --checkboth pass.Scope
This PR is scoped to the GPQA preprocessing path only. I noticed a few other things while reviewing (the
RubricGroup.score_groupadvantage-dropping that PR #2009 partially addresses, and a cluster of sandbox-cleanup race issues tracked in #1992/#1994) — those are out of scope here and already have tracking PRs/issues.Note
Low Risk
Single-path dataset preprocessing change with no security or persistence impact; only affects how GPQA multiple-choice options are ordered.
Overview
GPQA preprocessing no longer uses unseeded
random.shufflefor A/B/C/D letter assignment.preprocess_gpqanow derives a per-question seed fromSHA256of the question text and shuffles with a dedicatedrandom.Randominstance, so the same question always gets the same answer-letter mapping across runs, workers (num_proc=10), andPYTHONHASHSEEDvalues.Per-question permutations are unchanged in intent—only reproducibility is fixed.
hashlibis added for stable hashing instead of built-inhash().Reviewed by Cursor Bugbot for commit 8b547f0. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Make GPQA answer permutation deterministic per question in
preprocess_gpqaPreviously, A/B/C/D option order in GPQA preprocessing used the process-global RNG (
random.shuffle), making results vary across runs and processes. Now, a per-question seed is derived from the SHA-256 hash of the question text, and a localrandom.Randominstance is used to shuffle options, making the order stable and reproducible. Behavioral Change: existing datasets or cached results may have a different answer ordering after this change.Macroscope summarized 8b547f0.