Hi,
For your example, this will not work if you actually make a require gradients. It will show you that you can’t modify a inplace in a differentiable manner. And so, if you change it in a non-differentiable manner with torch.no_grad(),  it will compute the gradient wrt the original value of a (the one used in the forward).
For the nn.Module version, note that the optimizer step and model state dict loading are both done in a non-differentiable manner. So these ops will be ignored by the autograd.
When you call backward, you will get the gradient wrt to the Parameter that was used in the forward.