Relative Content

Tag Archive for pythonpytorchgradienttensor

Set torch.nn.Parameter’s data, including the gradient

I have an existing nn.Parameter, and a tensor with a gradient. I want to set the tensor to the parameter in a way that the parameter will have the same gradient (including perhaps .grad_fn and so on). The data of the parameter may be in a different shape than the new tensor.