josipd / torch-two-sample

A PyTorch library for two-sample tests
Other
237 stars 33 forks source link

Fix PyTorch 1.5.0 RuntimeError about non-static forward methods #6

Closed bradyneal closed 4 years ago

bradyneal commented 4 years ago

PyTorch error message: RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)

I fix this by simply adding the @staticmethod decorator to the forward methods of classes that inherit from torch.autograd.Function and then changing the calling of these forward methods to be used via the "apply" function as in the above linked example in the PyTorch docs.