Hello everyone, I’m trying to use an implemented layer that uses torch.autograd.Function.
I get the error mentioned in the headline:
“RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method.”
I tried to update with the @staticmethod
The layer is implemented as follows:
class SparseMM(torch.autograd.Function):

@staticmethod
def forward(self, sparse, dense):
    self.sparse = sparse
    # self.save_for_backward(torch.mm(self.sparse, dense))
    return torch.mm(self.sparse, dense)

@staticmethod
def backward(self, grad_output):
    grad_input = None
    if self.needs_input_grad[0]:
        grad_input = torch.mm(self.sparse.t(), grad_output)
    return grad_input

and using it as follows:
x = self.SparseMM.apply(self, D, x.t())
I still get the error. I’m not sure why. I looked at the example they turn to, and looked at some other threads here around the same problem, but couldn’t fix this.
Anyone has an idea why?
thanks