My code:
ddpg_agent_actor = centralized_ddpg_agent_actor(num_actions, num_states)
ddpg_agent_target_actor = copy.deepcopy(ddpg_agent_actor) #assert fails
ddpg_agent_target_actor = pickle.loads(pickle.dumps(ddpg_agent_actor)) #assert fails
assert ddpg_agent_actor == ddpg_agent_target_actor
To give some context, I am working on implementing DDPG, and I need to initialize a target actor, which should have the same parameters as the actor.
Here is the torch.nn.Module
I am trying to copy.(nothing weird, just a standard torch.nn.Module)
class centralized_ddpg_agent_actor(torch.nn.Module):
def __init__(self, action_space_size, observation_state_size):
super().__init__()
self.linear1 = torch.nn.Linear(observation_state_size, 128)
self.linear2 = torch.nn.Linear(128, 256)
self.linear3 = torch.nn.Linear(256, action_space_size)
def forward(self, state):
output = torch.tanh(self.linear1(torch.tensor(state, dtype=torch.float32)))
output = torch.tanh(self.linear2(output))
output = torch.tanh(self.linear3(output))
return output
The copy needs to be a deep copy (i.e. the parameters being able to be updated independently).
It is possible I am asserting wrong.