Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when using .clone on MetricCollection with MatthewsCorrCoef #1292

Closed
arroqc opened this issue Oct 25, 2022 · 2 comments
Closed

Crash when using .clone on MetricCollection with MatthewsCorrCoef #1292

arroqc opened this issue Oct 25, 2022 · 2 comments
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@arroqc
Copy link

arroqc commented Oct 25, 2022

🐛 Bug

When building a MetricCollection with MatthewsCorrCoef as part of the list, the use of .clone method raises an error.
This happens only in 0.10.0. The same code in 0.9.3 will work.

To Reproduce

  1. Install torchmetrics 0.10.0
  2. Use code sample below

This will lead to the following issue when .clone tries to deepcopy:

>>> metrics.clone(prefix='train')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./anaconda3/envs/pytorch/lib/python3.8/site-packages/torchmetrics/collections.py", line 300, in clone
    mc = deepcopy(self)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 270, in _reconstruct
    state = deepcopy(state, memo)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 296, in _reconstruct
    value = deepcopy(value, memo)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "./anaconda3/envs/pytorch/lib/python3.8/copy.py", line 264, in _reconstruct
    y = func(*args)
  File "./anaconda3/envs/pytorch/lib/python3.8/copyreg.py", line 91, in __newobj__
    return cls.__new__(cls, *args)
TypeError: __new__() missing 1 required positional argument: 'num_classes'

Code sample

import torchmetrics
metrics = torchmetrics.MetricCollection([torchmetrics.MatthewsCorrCoef(num_classes=2, threshold=0.5)])
metrics.clone(prefix='train')

Expected behavior

Clone doesn't crash :)

Environment

pip install torchmetrics==0.10.0

  • Python & PyTorch Version (e.g., 1.0): Python 3.8. torch 1.12.1
  • Any other relevant information such as OS (e.g., Linux): Tested on local mac and inside linux docker
@arroqc arroqc added bug / fix Something isn't working help wanted Extra attention is needed labels Oct 25, 2022
@github-actions
Copy link

Hi! thanks for your contribution!, great first issue!

@SkafteNicki
Copy link
Member

Hi @arroqc, this is a similar issue to #1274, which has been resolved in #1250 after #1249. Please update to version v0.10.1 that was released 5 days ago (https://github.com/Lightning-AI/metrics/releases/tag/v0.10.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants