Fix rolled prompts for contrastive disc in ARC training#246
Open
cpvlordelo wants to merge 4 commits into
Open
Conversation
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.
The fix uses dict-unpacking to build fresh dicts — the current training_step pattern appends references to the original metadata dicts and mutates them in place, which (A) leaks side effects to subsequent code paths that still hold references to
metadata, and (b) makes the very last iteration readmetadata[0]["prompt"]after iteration 0 already overwrote it, so the last element of the rolled batch ends up with the wrong prompt.Problem (A):
Not affecting anywhere today since
metadata[i]is not used downstream insidetraining_step, so even though we are changing it in place, this is not affecting anything in downstream code. In the future, if any code usesmetadata[i]after the in-place modification is done, they would also receive rolled prompts, which we don't want. The fix will prevent this from happening.Problem (B)
Walkthrough with prompts
[A, B, C, D](n=4)The intended
rolled_metadatashould be[B, C, D, A]— each item gets thenext item's prompt, wrapping at the end.
imetadata[(i+1) % 4]["prompt"]metadata[i]["prompt"]metadataprompts after this iterationmetadata[1]→B(original)metadata[0]←B[B, B, C, D]metadata[2]→C(original)metadata[1]←C[B, C, C, D]metadata[3]→D(original)metadata[2]←D[B, C, D, D]metadata[0]→B← already mutated in iter 0! Should have beenA.metadata[3]←B[B, C, D, B]rolled_metadataends up as[B, C, D, B]instead of[B, C, D, A]— thelast element is wrong.
Where the bug lives
For any
n ≥ 2, only the last iteration reads a value that an earlier iteration already overwrote. That's because(n-1 + 1) % n == 0, and index 0 is the one iteration 0 wrote to. All earlier reads (metadata[i+1]fori = 0..n-2) hit indices that haven't been touched yet.There's also a degenerate case: with
n = 2 ([A, B]), iteration 0 setsmetadata[0] ← B, iteration 1 readsmetadata[0](alreadyB) and writesmetadata[1] ← B→rolled is[B, B]. The "wrong" element is still the last one, but it's a more visible 50%-of-the-batch corruption in that case.