How to set manually parameters to model

i want to set manually parameters to model, i tried to do something like:

        for name, p in updated_model.all_named_parameters():
            p = result_params[name]
            p.retain_grad()

but it seems that it’s only changes p, but not the network.
i need the grad inside result_params for the network, so i don’t want to use something like “p.data = …” .

thanks a lot.
yoav

Could you explain a bit more about your use case?
If you would like to play around with the gradients, have a look at backward_hooks.