Differences between 'params.grad' and 'params.grad.data'

Hi everyone,
I’m trying to understand the difference between ‘params.grad’ and ‘params.grad.data’. I asked ChatGPT and searched for info, unfortunately no answer was satisfactory. Could someone explain it? Thanks!

Hi Karolina!

The short answer is that .data has been deprecated for public-facing use
(so don’t use it).

Having said that – and not really being knowledgeable about what .data
is currently used for – .data appears to give you a tensor that shares its
underlying data with the tensor it was called on. If called on a Parameter
(a subclass of Tensor), it returns an ordinary Tensor. It also gives you
a tensor with require_grad = False whether or not requires_grad
was True for the original tensor. I don’t think that any of this depends on
whether the tensor .data is called on is the .grad of some other tensor.

Best.

K. Frank