Skip to content

fix(retrieval): validate top_k parameter for RetrievalMAP and RetrievalMRR#3418

Open
jlaportebot wants to merge 13 commits into
Lightning-AI:masterfrom
jlaportebot:fix/retrieval-map-mrr-top-k-validation
Open

fix(retrieval): validate top_k parameter for RetrievalMAP and RetrievalMRR#3418
jlaportebot wants to merge 13 commits into
Lightning-AI:masterfrom
jlaportebot:fix/retrieval-map-mrr-top-k-validation

Conversation

@jlaportebot

Copy link
Copy Markdown
Contributor

Summary

  • Fix validation logic in RetrievalMAP and RetrievalMRR class constructors
  • Fix validation logic in retrieval_average_precision and retrieval_reciprocal_rank functional APIs
  • Change condition from 'not isinstance(top_k, int) and top_k <= 0' to 'not (isinstance(top_k, int) and top_k > 0)' to correctly reject non-positive integers and non-integer values
  • Add regression tests for invalid top_k values (-10, 4.0) in class and functional APIs

Testing

  • All existing tests pass
  • New regression tests added for invalid top_k values
  • Manual verification confirms validation now works correctly

Fixes #3378

…alMRR

- Fix validation logic in RetrievalMAP and RetrievalMRR class constructors
- Fix validation logic in retrieval_average_precision and retrieval_reciprocal_rank functional APIs
- Change condition from 'not isinstance(top_k, int) and top_k <= 0' to
  'not (isinstance(top_k, int) and top_k > 0)' to correctly reject
  non-positive integers and non-integer values
- Add regression tests for invalid top_k values (-10, 4.0) in class and functional APIs

Fixes Lightning-AI#3378
@jlaportebot jlaportebot force-pushed the fix/retrieval-map-mrr-top-k-validation branch from 7b55b79 to 4fab1c2 Compare June 17, 2026 02:40
…ll retrieval metrics

- Update error message format from '`top_k` has to be a positive integer or None' to
  'Argument ``top_k`` has to be a positive integer or None, but got {top_k}' for consistency
- Applied to class metrics: FallOut, NDCG, AUROC, Recall, Precision, HitRate
- Applied to functional metrics: retrieval_fall_out, retrieval_normalized_dcg, retrieval_auroc,
  retrieval_recall, retrieval_precision, retrieval_hit_rate
- Fixes test failures in PR Lightning-AI#3418 where test expectations were updated but validation code was not
- Follows the pattern established in RetrievalMAP and RetrievalMRR (commit 4fab1c2)

Fixes Lightning-AI#3378
@jlaportebot jlaportebot force-pushed the fix/retrieval-map-mrr-top-k-validation branch from 35d3496 to be03c64 Compare June 17, 2026 12:46
@codecov-commenter

codecov-commenter commented Jun 17, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 7.84314% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 36%. Comparing base (d184220) to head (e34936f).
⚠️ Report is 7 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #3418   +/-   ##
======================================
- Coverage      37%     36%   -0%     
======================================
  Files         349     349           
  Lines       19901   19928   +27     
======================================
+ Hits         7264    7265    +1     
- Misses      12637   12663   +26     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add [dependency-groups] section to pyproject.toml for modern uv-based development
dependency management. This enables 'uv sync --group dev' for installing
development tooling like pytest and pytest-cov.

Follows PEP 735 standard for dependency groups.
Regenerate uv.lock after adding [dependency-groups] for dev tooling (PEP 735).
The lock file now correctly resolves pytest and pytest-cov for the dev group.
@jlaportebot jlaportebot force-pushed the fix/retrieval-map-mrr-top-k-validation branch from 0bca73b to 00ffb26 Compare June 20, 2026 02:15
pre-commit-ci Bot and others added 7 commits June 20, 2026 02:17
Lightning-AI#2846)

- Update _generalized_dice_update to return support tracking for per-class computation
- Update _generalized_dice_compute to handle per_class=True with NaN for absent classes
- Update GeneralizedDiceScore class to track support and compute per-class scores correctly
- Add test for absent classes handling (TestGeneralizedDiceScoreAbsentClasses)

Classes not present in any sample now return NaN. Classes present in only
some samples average over present samples only.
- Fix _generalized_dice_compute support parameter type annotation (Tensor | None)
- Add class attribute type annotations for score, support, samples state variables
…ed_dice_score doctests

Doctests using torch.randint produce non-deterministic output, causing CI failures
across platforms (observed on Windows/macOS/Linux with different PyTorch versions).
Replace with fixed literal tensors that produce deterministic results.

Fixes CI failures in pytester jobs across all platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RetrievalMAP and RetrievalMRR do not validate invalid top_k values

2 participants