Solved by ptab in post #2 
              
              
                I think the issue here is that you are incorrectly passing torch.ones(3) to your .backward call, since y is a scalar value. 
On pytorch 0.41 your code gives an error but using either y.backward() or y.backward(torch.ones(1)) works. 
Pure speculation: Maybe your version of pytorch handles the tensor …