Greetings!
Suppose I want to write my own optimizer, eg. modify torch.optim.sgd.
In the step function of SGD, the parameters p get updated in-place, eg:
            for p in group['params']:
                
                ## SOME CODE

                p.add_(d_p, alpha=-group['lr'])

My first question is why it does not use p.data.add_(d_p, alpha=-group['lr']) as the actual parameter tensor is the data object, is it not?
Also suppose I want to change my parameter p with a computed value x. Is the following correct?
#### compute x
p.data = x

I would still be in the step( ) function, so gradient storage should be turned off due to a line @torch.no_grad() before the step( ) function definition.
Best,
PiF