Skip to content

Fix confusion matrices with integer-valued floating labels - #230

Draft
ktz03 wants to merge 1 commit into
meta-pytorch:mainfrom
ktz03:fix/floating-confusion-matrix-labels
Draft

ktz03 wants to merge 1 commit into
meta-pytorch:mainfrom
ktz03:fix/floating-confusion-matrix-labels

Conversation

@ktz03

@ktz03 ktz03 commented Oct 19, 2026

Copy link
Copy Markdown

Please read through our contribution guide prior to creating your pull request.

Summary:
Integer-valued floating targets (such as torch.tensor([0., 1.])) reach the scripted confusion-matrix helper with floating COO coordinates and raise RuntimeError: indices must be an int64 tensor. Convert the shared coordinates to int64 before constructing the sparse matrix, preserving count values and normalization. This covers binary and multiclass functional and metric APIs.

Add four regression methods covering float32/float64 targets, all normalization modes, and merging metric states before normalization. Thanks to @rafael-patronilo for reporting the binary case. Fractional class labels remain outside the supported label contract.

Test plan:

  • Windows CPU, Python 3.12.14, PyTorch 2.14.0+cpu, scikit-learn 1.9.1, released TorchTNT 0.2.4 (not the nightly development environment).
  • The same four new regression methods fail on upstream production and pass with this change. Both confusion-matrix modules: 12 passed; six existing distributed tests fail at Windows rendezvous because this Torch build lacks libuv, also reproduced on upstream production.
  • Full functional classification directory: 112 passed, 1 skipped, 2 failed. The same accuracy/AUROC failures occur on upstream production (110 passed, 1 skipped, 4 failed including the two new functional regressions). These test scopes overlap.
  • All pinned pre-commit hooks pass on the three changed files. pre-commit run --all-files reports the same existing unused unittest import and seven unrelated formatting differences on the baseline; unrelated automatic edits were restored.
  • No GPU, full-repository suite, or official Linux/Python dependency matrix was run.

Draft pending the required full-suite and all-files checks in a supported environment, and CLA verification.

Fixes #212

@meta-cla

meta-cla Bot commented Oct 19, 2026

Copy link
Copy Markdown

Hi @ktz03!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Oct 19, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 19, 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.

BinaryConfusionMatrix does not work with float target

1 participant