Can you print x just before calling y = f(x) and check that its value is tensor([20]) ? If the value of x is correct then I think the problem comes from function f. Could you provide the code of function f ?