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.
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.
see colab.
@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)