Skip to content

Conversation

maxxgx
Copy link
Contributor

@maxxgx maxxgx commented Oct 10, 2025

📝 Description

Bug: on Mac, the optimal threshold index is out of range.

Torchmetrics returns NaN values when computing the f1 score with device=mps.

Solution: use CPU instead of mps

@ashwinvaidya17 thanks for the suggestion.

✨ Changes

Select what type of change your PR is:

  • 🚀 New feature (non-breaking change which adds functionality)
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔄 Refactor (non-breaking change which refactors the code base)
  • ⚡ Performance improvements
  • 🎨 Style changes (code style/formatting)
  • 🧪 Tests (adding/modifying tests)
  • 📚 Documentation update
  • 📦 Build system changes
  • 🚧 CI/CD configuration
  • 🔧 Chore (general maintenance)
  • 🔒 Security update
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).
  • 🏷️ My PR title follows conventional commit format.

For more information about code review checklists, see the Code Review Checklist.

Signed-off-by: Ma, Xiangxiang <xiangxiang.ma@intel.com>
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where the optimal threshold index was out of range on Mac by aligning the precision/recall curve shape with thresholds tensor. The issue was caused by torchmetrics using sklearn-style precision/recall format where the last elements are padding values without corresponding thresholds.

  • Adds shape alignment check for precision/recall tensors with thresholds
  • Removes last element from precision/recall when they have one extra element
  • Includes documentation explaining the sklearn precision/recall curve format

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Signed-off-by: Ma, Xiangxiang <xiangxiang.ma@intel.com>
@maxxgx maxxgx force-pushed the max/fix-f1-threshold branch from 4e9ecf4 to 9648d51 Compare October 10, 2025 13:02
@maxxgx maxxgx changed the title 🐛 fix(metrics): align precision/recall curve shape with thresholds 🐛 fix(metrics): disable mps for torch metrics Oct 10, 2025
@maxxgx maxxgx merged commit f6ae55f into open-edge-platform:feature/geti-inspect Oct 10, 2025
11 checks passed
Copy link
Contributor

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a super minor thing, we need to update the year range at the top

maxxgx added a commit to maxxgx/anomalib that referenced this pull request Oct 10, 2025
* align shape of precision/recall to thresholds

Signed-off-by: Ma, Xiangxiang <xiangxiang.ma@intel.com>

* move to cpu when device is mps

Signed-off-by: Ma, Xiangxiang <xiangxiang.ma@intel.com>

---------

Signed-off-by: Ma, Xiangxiang <xiangxiang.ma@intel.com>
maxxgx added a commit that referenced this pull request Oct 10, 2025
🐛 fix(metrics): disable mps for torch metrics (#3018)


* move to cpu when device is mps



---------

Signed-off-by: Ma, Xiangxiang <xiangxiang.ma@intel.com>
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.

2 participants