fix: prevent IndexError in Doc.get_golds() for out-of-bounds gold_index#1236
Open
AmSach wants to merge 1 commit into
Open
fix: prevent IndexError in Doc.get_golds() for out-of-bounds gold_index#1236AmSach wants to merge 1 commit into
AmSach wants to merge 1 commit into
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.
Fixed the bug described in issue #1162. Here's what was wrong and how I fixed it:
Root Cause: In
Doc.get_golds(), thegold_indexvalue was used directly to indexself.choiceswithout bounds checking. Whengold_indexexceededlen(choices) - 1, it raised an unhelpfulIndexError: list index out of range.The Fix: Added a bounds check before accessing
self.choices[gold_ix]. Now ifgold_ix >= num_choices, a descriptiveValueErroris raised with the offending index and the actual size of choices.Changes:
src/lighteval/tasks/requests.py: Added bounds validation inget_golds()methodValueErrorwith a clear message instead of a crypticIndexErrorTesting: Syntax check passed. The fix correctly converts the
IndexErrorinto aValueErrorwith actionable error message.Closes #1162