Skip to content

Optimize minDCF memory footprint #3037

Open
othman-istaiteh wants to merge 3 commits intospeechbrain:developfrom
othman-istaiteh:optimize-mindcf-memory
Open

Optimize minDCF memory footprint #3037
othman-istaiteh wants to merge 3 commits intospeechbrain:developfrom
othman-istaiteh:optimize-mindcf-memory

Conversation

@othman-istaiteh
Copy link

What does this PR do?

This PR refactors the minDCF evaluation metric to resolve Out-Of-Memory (OOM) errors during the evaluation of large datasets.

Due to the previous memory footprint, the original function crashed when attempting to compute minDCF for large trial lists, such as VoxCeleb1-H (Vox-H) and VoxCeleb1-E (Vox-E).

Complexity Improvements:
Where N is the total number of scores and T is the number of unique thresholds (typically T ≤ N_pos + N_neg):

Old Implementation:

  • Space: O(N * T)
  • Time: O(N * T)

New Implementation:

  • Space: O(N)
  • Time: O(N log N)

Algorithmic Details:

  1. Memory Optimization: Swapped the O(N * T) tensor expansion blocks for 1D torch.searchsorted operations to count False Acceptance and False Rejection rates.
  2. Removed Midpoints: The calculation of intermediate thresholds ((thresholds[0:-1] + thresholds[1:]) / 2) was removed. Because p_miss and p_fa are step functions that only change state at observed scores, evaluating midpoints is mathematically redundant.

Testing:

  • Empirical Parity: Evaluated on the VoxCeleb1-O (Vox-O) test set. The optimized function yields the exact same minDCF result as the original implementation.
  • Passes pytest tests/unittests/test_metrics.py.
  • Passes pytest --doctest-modules speechbrain/utils/metric_stats.py.

Fixes #<issue_number>

Breaking Changes:
No breaking changes. The function signature and return types remain identical.

Before submitting
  • Did you read the contributor guideline?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Does your code adhere to project-specific code style and conventions?

PR review

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory, and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified
  • Confirm that the changes adhere to compatibility requirements (e.g., Python version, platform)
  • Review the self-review checklist to ensure the code is ready for review

@othman-istaiteh othman-istaiteh marked this pull request as ready for review February 27, 2026 19:01
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.

1 participant