ElleryL:

x = Variable(x,requires_grad=True) G = torch.eye(2)*3 # compute matrix


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