Skip to content

Fix RetrievalRecall denominator across updates and merges - #232

Open
akshitkhokhani wants to merge 1 commit into
meta-pytorch:mainfrom
akshitkhokhani:codex/fix-retrieval-recall-denominator
Open

akshitkhokhani wants to merge 1 commit into
meta-pytorch:mainfrom
akshitkhokhani:codex/fix-retrieval-recall-denominator

Conversation

@akshitkhokhani

Copy link
Copy Markdown

Summary:

RetrievalRecall(k) discards relevant labels outside the retained top-k before computing its denominator. For scores [0.9, 0.8, 0.7, 0.6], relevance [1, 0, 1, 1], and k=2, a single update returns 1.0 instead of 1/3. Splitting the same documents across metrics can produce a different result. Relevant documents below the cutoff also incorrectly trigger empty_target_action.

Track each query's total relevant-item count independently of its retained candidates. Use that count for the denominator and empty-target handling, and combine counts while selecting global top-k candidates during merges. The count uses int64, and donor iterables are consumed once. Candidate storage remains bounded by k when k is specified.

The additional registered state participates in reset and new checkpoint round trips. Old checkpoints do not contain the discarded positive count and cannot reconstruct it; default strict loading rejects them, so accumulated evaluation must be recomputed.

Test plan:

  • Public baseline reproduction confirms incorrect single/batched/grouped/merged results against the functional metric.
  • Regression coverage includes batching, multiple queries, macro averaging, list/generator merges, donor preservation, reset, checkpoint continuation, empty-target policies, and exact count increments above 2**24.
  • Ranking class/functional and base metric-state checks: 62 passed, 1 skipped, 17 subtests passed, including real CPU worker synchronization. Independent focused checks: 8 passed and 17 subtests, plus separate public-API controls.
  • Configured pre-commit hooks pass on both changed files. A full-repository hook attempt encountered existing unrelated lint/format issues; those files were restored unchanged. No full-library or GPU test claim.

This changes the stateful metric only; the functional metric and the unrelated Covariance/R2Score merge repair in #231 are unchanged.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant