fix(metrics): slice to n on the cache-hit path in the MMLU/GSM8K loaders#15
Merged
Merged
Conversation
On a cache hit, both loaders returned every row in the cache file without checking the count against n. n is part of the cache key so this was invisible in normal use, but a stale or hand-edited cache file made load_*_slice(n=1) return however many rows the file happened to hold, silently violating the loader's contract. Slice rows to [:n] on the cache-hit path in both loaders. Adds a too-many-rows fixture test for each loader that seeds a cache file with more rows than n and asserts exactly n come back. Closes bamdadd#14. Follow-up to bamdadd#13. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Owner
|
Reproduced the mutation check locally — reverting the |
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 #14 — the follow-up you asked for in #13's merge note:
The change
Both loaders returned every row in the cache file on a cache hit, never checking the count against
n:One line each in
load_mmlu_sliceandload_gsm8k_slice. Sincenis part of the cache key this is invisible in normal use — but a stale or hand-edited cache file madeload_*_slice(n=1)return however many rows the file held, silently violating the contract the accept-path tests from #13 assert.Tests — the too-many-rows fixture you specified
test_load_mmlu_slice_cache_hit_slices_to_ntest_load_gsm8k_slice_cache_hit_slices_to_nEach seeds a cache file with 2 rows, calls the loader with
n=1, and asserts exactly one comes back. They reuse the existing_block_networkhelper and the same tmpcache_dirpattern as the #13 accept-path tests, and sit directly after them in the same section.They bite: against
main'smetrics.pywith these tests in place, both fail withassert 2 == 1; with the fix, both pass. (Verified by checking the production file out fromupstream/main, running, then restoring — not just by watching them go green.)Gates
ruff format --check .→ 0 ·ruff check src tests→ 0 ·mypy src→ 0 ·pytest→ 0 (58 passed, 2 skipped — your 56/2 baseline plus these two).uv.lockchurn fromuv runwas reverted and is not in the diff. Diff is 2 files, +46/−2.Implemented with AI assistance (Claude Sonnet 4.5), and independently mutation-verified by me against
upstream/mainbefore submitting.