Skip to content

Defer TorchScript compilation until metrics are used - #240

Open
harshal-prozone wants to merge 1 commit into
meta-pytorch:mainfrom
harshal-prozone:fix/eager-metrics-import-226
Open

harshal-prozone wants to merge 1 commit into
meta-pytorch:mainfrom
harshal-prozone:fix/eager-metrics-import-226

Conversation

@harshal-prozone

Copy link
Copy Markdown

Summary

  • Defer scripting of private classification and regression metric helpers until they are first used. Importing torcheval.metrics no longer runs the deprecated TorchScript decorator.
  • Cache compilation at the Python call boundary. Keep recursively scripted helpers as regular functions so TorchScript can still resolve their original globals. Calls to affected metrics can still emit PyTorch's deprecation warning when they compile.
  • Test a fresh-process import with TorchScript deprecation warnings treated as errors.

Fixes #226

Validation

  • The import regression failed on upstream with a PyTorch FutureWarning and passed with the patch. A separate import probe counted 30 warnings on upstream and zero with the patch.
  • Affected functional tests on PyTorch 2.15 recorded 99 passed, two failed and one skipped on upstream. With the import test added, the patch recorded 100 passed, the same two failures and one skip. The failures involved an AUROC reference dtype mismatch and scikit-learn rejecting an empty array in an accuracy reference.
  • Nine metric classes returned identical values and dtypes in a two-update comparison. Independent review matched outputs across nine warm multilabel benchmark cases, including recursively scripted recall, and checked concurrent cold calls.
  • Flake8, ufmt, and git diff --check passed.
  • Linux ARM64 on PyTorch 2.10.0 and scikit-learn 1.5.2 passed 121 functional classification, regression, and import tests with one skip. The import regression failed on unchanged upstream and passed with the patch. Both prior functional failures also passed on unchanged upstream in this environment.
  • The full Linux ARM64 suite ran with Python 3.11, PyTorch and TorchAudio 2.7.1, TorchVision 0.22.1, and scikit-learn 1.5.2. python -m pytest -n 2 --dist loadfile --timeout=120 -v --tb=short -p no:cacheprovider tests/ finished with 474 passed, seven skipped, and no failures. This includes the distributed class tests and all four VGGish tests. TorchAudio 2.7.1 provides the VGGish pipeline with the working weight loader required by this suite.

OpenAI Codex assisted with investigation, implementation, testing, and independent review.

@meta-cla

meta-cla Bot commented Nov 22, 2026

Copy link
Copy Markdown

Hi @harshal-prozone!

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 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 Nov 22, 2026
@meta-cla

meta-cla Bot commented Nov 22, 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!

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.

Deprecation warning upon import of torcheval.metrics

1 participant