[MRG] Fix instantiation of `ValFunction` (which raises a warning with PyTorch) by Pseudomanifold · Pull Request #338 · PythonOT/POT

ValFunction should not be instantiated since autograd functions are
supposed to only ever use static methods. This solves a warning message
raised by PyTorch.

The warning message of PyTorch indicates that this behaviour may raise
an error in future versions.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Motivation and context / Related issue

With PyTorch 1.10.1+cu102, using OT on a tensor with a gradient, the following warning message is raised:

[....] valfunction should not be instantiated. Methods on autograd functions are all static, so you should
invoke them on the class itself. Instantiating an autograd function will raise an error in a future version
of PyTorch.

This pull request fixes the instantiation, thus also fixing issue #337.

How has this been tested (if it applies)

Used my own code with the fork of POT. The warning is not raised any more; further behaviour remains exactly the same.

PR checklist

  • I have read the CONTRIBUTING document.
  • The documentation is up-to-date with the changes I made (check build artifacts).
  • All tests passed, and additional code has been covered with new tests.
  • I have added the PR and Issue fix to the RELEASES.md file.