Skip to content

Use linear space in multiclass stats computation when n_classes>1000#3342

Open
barakugav wants to merge 1 commit intoLightning-AI:masterfrom
barakugav:multiclass-many
Open

Use linear space in multiclass stats computation when n_classes>1000#3342
barakugav wants to merge 1 commit intoLightning-AI:masterfrom
barakugav:multiclass-many

Conversation

@barakugav
Copy link
Copy Markdown

@barakugav barakugav commented Mar 21, 2026

What does this PR do?

Fixes: #3343

The PR changes multi-class accuracy to work with large number of classes, by changing its computation to use a linear amount of memory instead of quadratic.
The quadratic space is needed for the full confusion matrix, but for accuracy alone it is not required.

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?
PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.


📚 Documentation preview 📚: https://torchmetrics--3342.org.readthedocs.build/en/3342/

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 31%. Comparing base (5e8b01d) to head (c3835f2).
⚠️ Report is 7 commits behind head on master.

❌ Your project check has failed because the head coverage (31%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (5e8b01d) and HEAD (c3835f2). Click for more details.

HEAD has 742 uploads less than BASE
Flag BASE (5e8b01d) HEAD (c3835f2)
macOS 28 2
python3.10 152 11
cpu 200 15
torch2.0.1 14 1
torch2.8.0 14 1
python3.12 48 4
torch2.0.1+cpu 26 2
Windows 22 2
torch2.8.0+cpu 35 3
Linux 150 11
torch2.7.1+cpu 27 2
torch2.3.1+cpu 14 1
torch2.2.2+cpu 14 1
torch2.1.2+cpu 14 1
torch2.4.1+cpu 14 1
torch2.6.0+cpu 14 1
gpu 1 0
unittest 1 0
torch2.5.1+cpu 14 1
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #3342     +/-   ##
========================================
- Coverage      37%     31%     -6%     
========================================
  Files         364     349     -15     
  Lines       20096   19906    -190     
========================================
- Hits         7521    6169   -1352     
- Misses      12575   13737   +1162     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiclass accuracy requires num_classes**2 memory

1 participant