Solved by albanD in post #5 
              
              
                I edited you message with ``` to do a code block and make it easier to read  
It would be slightly different: 
class dWdx(Function):
    @staticmethod
    def forward(ctx, x, p, t):
        np_x = x.detach().numpy() # The detach should not be needed here, will be in a future version of pytorch
     …