Solved by InnovArul in post #11 
              
              
                Here G does not have requires_grad=True. I think, thats the reason for the error. 
Probably, you wanted to do this: 
x = torch.Tensor([3])
x = Variable(x,requires_grad=True)
G = torch.eye(2) * x # compute matrix