fix(normalizations): guard against index out of range in LogProbToken…#1180
Open
inakiLakunza wants to merge 1 commit intohuggingface:mainfrom
Open
fix(normalizations): guard against index out of range in LogProbToken…#1180inakiLakunza wants to merge 1 commit intohuggingface:mainfrom
inakiLakunza wants to merge 1 commit intohuggingface:mainfrom
Conversation
…Norm ## Problem When running evaluations with cached predictions, `normalize_log_probs` crashes with an `IndexError: list index out of range` inside the `LogProbTokenNorm` case. This happens because the cached `output_tokens` list can be shorter than `choices_logprob`, for example when a task's choices change between runs but the cache is not invalidated. Affected path: `lighteval/metrics/normalizations.py` → `normalize_log_probs` → `LogProbTokenNorm` branch ## Fix - Use `min(len(choices_logprob), len(choices_tokens))` to safely cap the iteration range instead of blindly iterating over `len(choices_logprob)`. - Emit a `logger.warning` when truncation occurs so users are alerted to potential cache corruption and can take action (e.g. clearing the cache). - Add a module-level `logger = logging.getLogger(__name__)` for consistent logging. ## Changes - `src/lighteval/metrics/normalizations.py` - Added `import logging` and module-level logger - Replaced bare list comprehension in `LogProbTokenNorm` with length-guarded version ## How to reproduce the original bug 1. Run an evaluation that uses `LogProbTokenNorm` (e.g. `belebele_mkd_Cyrl_cf`). 2. Allow results to be cached. 3. Modify the number of choices for the task, or use a stale cache from a previous run. 4. Re-run, the pipeline crashes at the metric computation stage with `IndexError: list index out of range`.
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.
…Norm
Problem
When running evaluations with cached predictions,
normalize_log_probscrashes with anIndexError: list index out of rangeinside theLogProbTokenNormcase. This happens because the cachedoutput_tokenslist can be shorter thanchoices_logprob, for example when a task's choices change between runs but the cache is not invalidated.Affected path:
lighteval/metrics/normalizations.py→normalize_log_probs→LogProbTokenNormbranchFix
min(len(choices_logprob), len(choices_tokens))to safely cap the iteration range instead of blindly iterating overlen(choices_logprob).logger.warningwhen truncation occurs so users are alerted to potential cache corruption and can take action (e.g. clearing the cache).logger = logging.getLogger(__name__)for consistent logging.Changes
src/lighteval/metrics/normalizations.pyimport loggingand module-level loggerLogProbTokenNormwith length-guarded versionHow to reproduce the original bug
LogProbTokenNorm(e.g.belebele_mkd_Cyrl_cf).IndexError: list index out of range.