Repository navigation
Conversation
…ested n When `len(predictions) < n`, `compute` only logs a warning and `pass_at_k` still evaluates the estimator at `self.n`, so the missing generations are counted as failures and pass@k is a lower bound rather than an estimate. `all_scores` holds exactly the samples that were passed to `compute`, so the estimator now uses `len(all_scores)`. A `n == 0 -> 0.0` guard keeps the "no samples at all" case at 0.0 instead of flipping it to 1.0. The `n >= samples` path and `compute` itself are unchanged.
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.
Closes #1483.
What
PassAtK.pass_at_kevaluated the unbiased estimator atself.n— the number of samples that was requested — whilecomputeonly passes the samples that actually exist (predictions[: self.n]). Every missing generation was therefore counted as a failure, sopass@kwas a lower bound instead of an estimate whenever the backend returned fewer thanngenerations.computeonly logged a warning for that case.Fix
src/lighteval/metrics/metrics_sample.py,pass_at_konly:n >= samplesis untouched:all_scoresalready has at mostself.nentries, solen(all_scores) == self.nwhenever enough samples came back.n == 0guard keeps "no samples at all" at0.0(with the naive rewrite it would flip to1.0because0 - 0 < k).compute, the warning, andnum_samples()are unchanged, so anything that reads the configurednstill sees it.If you disagree and consider "missing samples are failures" to be the intended contract, please say so on the issue and I'll drop this in favour of a docs/warning-only change — the numbers then remain a lower bound and should be documented as such.
Before / after
n=10requested, 5 generations returned, 3 correct (c=3), measured throughPassAtK.computewith a realDoc/ModelResponse:b97a653)0.300000000000000040.60.53333333333333320.90.70833333333333331.0(
0.6 / 0.9 / 1.0are1 - C(5-3, k) / C(5, k), i.e. the estimator over the five samples that exist.)Tests
tests/test_unit_base_metrics.py:test_pass_at_k_with_fewer_samples_than_n— the table above.test_pass_at_k_with_n_samples_is_unchanged— same scores withn=5, plus a 10-sample case, both unchanged.test_pass_at_k_without_any_sample_is_zero—pass_at_k([]) == 0.0.ruff checkandruff format --checkpass on both files.Local note: this checkout has no
torch/transformers, sopytest tests/test_unit_base_metrics.pycannot be collected here (unrelated to this change — the module importslighteval.models.model_output); the same three assertions were run through a standalone script that loads the untouchedmetrics_sample.pyand prints the table above. CI will run the real file.Out of scope
GPassAtK.g_pass_at_k(metrics_sample.py:1418) doesn = self.nas well and has the same short-sample mismatch. It is not touched here to keep this PR toPassAtK; happy to follow up once this one settles. #1410 (k > nreturning1.0for all-wrong samples) is a separate issue and is also left alone.