Copy and override nn.Module parameters with other nn.Module parameters

Let’s say I have 2 instances of the same nn.Module architecture:
actor1 = ActorNN()
actor2 = ActorNN()

where ActorNN defined as:
class ActorNN(nn.Module):

Now, let’s say that I want to replace all weights and biases of actor2 with the weights and biases of actor1.
How can this be done easily?
Thanks

Hi,

You can do actor2.load_state_dict(actor1.state_dict()).

1 Like