Pytorch-lightning: Error in logging of Regression Metrics

Created on 20 Oct 2020  路  5Comments  路  Source: PyTorchLightning/pytorch-lightning

馃悰 Bug

When attempting to log a regression metric object as described here when training for more than one epoch, the following error occurs,

RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment

Interestingly, this error only occurs when using regression metrics. For example, Accuracy() works without any problems.

Boring Model Link

Link

Expected behavior

Logging should work for all metrics.

When comparing to metrics that work it seems that in the case of the regression metrics some of the variables (e.g. sum_squared_error) are still attached to the computational graph - which seems to be the cause of the problem. If I add the line,

preds = preds.detach()

to the update() method everything seems to work.

Environment

see colab.

Metrics bug / fix help wanted

All 5 comments

@SkafteNicki or @teddykoker

@pbmstrk mind sending in a PR with .detach fix?

@pbmstrk actually there are other issues with detaching or keeping attached metrics which are discussed here, so maybe wait for @SkafteNicki to send in a PR for the base class and see if that resolves the issue itself.

Discussion here: #4098.

@ananyahjha93 Ah okay, no worries!

@pbmstrk just pushed a commit to PR #4313 that solves the bug (confirmed by running colab model) :]
Basically had to call detach within the self.log code (only Metric objects did not automatically get detached, which is rectified now in the PR)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anthonytec2 picture anthonytec2  路  3Comments

polars05 picture polars05  路  3Comments

monney picture monney  路  3Comments

mmsamiei picture mmsamiei  路  3Comments

maxime-louis picture maxime-louis  路  3Comments