Hello! I have this simple (part of a) code:
a = torch.tensor(0.5)
a.requires_grad=True
lr = 1e-3
for i in range(20):
    yy = torch.cos(a*x) 
    loss = torch.mean((yy-y)**2)
    loss.backward()
    a = a-a.grad.data

Where x and y are fixed numbers, generated using y=(0.538*x). Basically I want to make a go from 0.5 to 0.538 using gradient descent.
The first loop works fine and a goes in the right direction, but at the second loop I am getting this error at the a = a-a.grad.data line: AttributeError: 'NoneType' object has no attribute 'data'. What am I doing wrong? What changes from the first to second iteration? Thank you!