Reset a model's certain parameters using .data.clone() or .data.detach().clone()?

Hello, may I consult about the difference in the effects of and

My goal is to interpolate between two parameters (of two models, respectively) and then assign the result to a new parameter (of a new model). My attempt is = 0.1 * + 0.9 *

I expect that new_param has no history of operations or gradients of the old parameters, and the modification of the new parameter or old parameters does not affect each other. Is my attempt correct?

Additionally, what if I do = 0.1 * + 0.9 *

Is it necessary to add .detach()?

Thank you in advance!

Hi @JaneChen,

If you want the new_params to have no history of the previous operation you will need to detach those values in order to get that behavior.

Also, don’t call the .data attribute of a tensor as you’ll ignore some of the metadata of the tensor, you should call .detach().clone() directly on the tensor itself rather than the .data attribute.