Repository navigation
fix: pass the scorer's rng when highlighting the default intruder - #198
Merged
Merged
Conversation
IntruderScorer(type="default") picked the intruder's random highlights with the global random module, because its _prepare_text call did not pass rng=self.rng. Two scorers built with the same seed could build different batches. Pass the scorer's rng, as the rest of _prepare_and_batch already does.
Contributor
Author
|
@SrGonao when you have a moment, could you take a look? In short: Pass the scorer's rng when highlighting the default intruder. Happy to change anything. |
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.
Problem
IntruderScorer(seed=...)buildsself.rngand_prepare_and_batchuses it for sampling examples and choosing the intruder position. The one exception is thetype="default"intruder: its_prepare_textcall does not passrng, so its random highlights fall back to the globalrandommodule.Two scorers built with
seed=42therefore build different batches whenever anything else has touchedrandomin between. In a CPU repro with synthetic data (no model calls), seeding the globalrandomwith 1 and then 2 before building each scorer gave different intruder text in 6 of 6 batches. In the new test below, the first intruder came out asABCD<<E>>FGHIJKLMNOPin one run andA<<B>>CDEFGHIJKLMNOPin the other.Change
Pass
rng=self.rngto that_prepare_textcall, as the other random choices in_prepare_and_batchalready do. The existing test'sfake_prepare_textstub gains anrng=Noneparameter to accept it.Checks
test_intruder_default_batches_are_reproducible_with_seedintests/test_scorers/test_intruder_example_embedding.py(CPU, synthetic data, no model calls). It fails onmain(the intruder's highlight differs between the two runs) and passes on this branch.pytest tests --ignore=tests/client_test.py(that file needs vllm): 349 passed.ruff checkandblack --checkpass on the changed files.Related: #197 fixes how many highlights the same intruder gets, a few lines above. The two PRs merge cleanly in either order.