I found that there are two ways to change Tensor.requires_grad。
I can manually set x.requires_grad = flag or I can call the method x.requires_grad_(flag). I did a simple experiment, and found nothing difference.
In [14]: a = torch.tensor([2.0])

In [15]: a.requires_grad
Out[15]: False

In [16]: a.requires_grad_()
Out[16]: tensor([2.], requires_grad=True)

In [17]: a.requires_grad
Out[17]: True

In [18]: a.requires_grad = False

In [19]: a
Out[19]: tensor([2.])

I’m wondering that is there any detail difference between the aforementioned two ways? Dose the requires_grad_(flag) do any other things except self.requires_grad = flag?
I tried to read the source code of requires_grad_, while found nothing, it seems to be written in C code~~