Hi,
Few things:

Do not use .data, it’s not a thing anymore and causes a lot of bugs. If you want to make a weight update here, do :

with torch.no_grad():
  a -=  a.grad


And your real issue is that when you do a = xxx. Then you re-assign a in a differentiable manner. Meaning that your new a is not a leaf anymore. Using the code in the point above will change a inplace and it will thus remain a leaf.
(EDIT) Also a.grad.zero_() inside the no_grad block as @crowsonkb mentioned below