Formatted all files

This commit is contained in:
Noah Dormann 2019-11-28 15:38:04 +01:00
parent 751ccf85e7
commit e95858784a
6 changed files with 13 additions and 31 deletions

View file

@ -10,6 +10,7 @@ from torchy_baselines.common.vec_env import DummyVecEnv
from torchy_baselines.common.identity_env import IdentityEnvBox from torchy_baselines.common.identity_env import IdentityEnvBox
MODEL_LIST = [ MODEL_LIST = [
CEMRL,
PPO, PPO,
A2C, A2C,
TD3, TD3,
@ -37,7 +38,6 @@ def test_save_load(model_class):
observations = np.array([env.step(env.action_space.sample())[0] for _ in range(10)]) observations = np.array([env.step(env.action_space.sample())[0] for _ in range(10)])
observations = np.squeeze(observations) observations = np.squeeze(observations)
# Get dictionary of current parameters # Get dictionary of current parameters
params = deepcopy(model.get_policy_parameters()) params = deepcopy(model.get_policy_parameters())
opt_params = deepcopy(model.get_opt_parameters()) opt_params = deepcopy(model.get_opt_parameters())
@ -55,8 +55,7 @@ def test_save_load(model_class):
params = new_params params = new_params
# get selected actions
#get selected actions
selected_actions = [model.predict(observation, deterministic=True) for observation in observations] selected_actions = [model.predict(observation, deterministic=True) for observation in observations]
# Check # Check

View file

@ -78,7 +78,8 @@ class CEMRL(TD3):
# set params # set params
self.actor.load_from_vector(self.es_params[i]) self.actor.load_from_vector(self.es_params[i])
self.actor_target.load_from_vector(self.es_params[i]) self.actor_target.load_from_vector(self.es_params[i])
self.actor.optimizer = th.optim.Adam(self.actor.parameters(), lr=self.learning_rate(self._current_progress)) self.actor.optimizer = th.optim.Adam(self.actor.parameters(),
lr=self.learning_rate(self._current_progress))
# In the paper: 2 * actor_steps // self.n_grad # In the paper: 2 * actor_steps // self.n_grad
# In the original implementation: actor_steps // self.n_grad # In the original implementation: actor_steps // self.n_grad

View file

@ -292,8 +292,6 @@ class BaseRLModel(object):
model.__dict__.update(kwargs) model.__dict__.update(kwargs)
model.set_env(env) model.set_env(env)
model.load_parameters(params, opt_params) model.load_parameters(params, opt_params)
# resetup modul after load
# model._setup_model()
return model return model
@staticmethod @staticmethod
@ -519,14 +517,6 @@ class BaseRLModel(object):
""" """
return ["replay_buffer"] return ["replay_buffer"]
def _resetup_model(self):
"""
Function will be called at the end of load and should resetup anything that might not have been saved
warning: this function should always be in compliance with excluded_save_params
:return:
"""
pass
def save(self, path, include=None): def save(self, path, include=None):
""" """
saves all the params from init and pytorch params in a file for continuous learning saves all the params from init and pytorch params in a file for continuous learning

View file

@ -227,7 +227,6 @@ class PPO(BaseRLModel):
# Value loss using the TD(gae_lambda) target # Value loss using the TD(gae_lambda) target
value_loss = F.mse_loss(return_batch, values_pred) value_loss = F.mse_loss(return_batch, values_pred)
# Entropy loss favor exploration # Entropy loss favor exploration
entropy_loss = -th.mean(entropy) entropy_loss = -th.mean(entropy)

View file

@ -52,6 +52,7 @@ class SAC(BaseRLModel):
Setting it to auto, the code will be run on the GPU if possible. Setting it to auto, the code will be run on the GPU if possible.
:param _init_setup_model: (bool) Whether or not to build the network at the creation of the instance :param _init_setup_model: (bool) Whether or not to build the network at the creation of the instance
""" """
def __init__(self, policy, env, learning_rate=3e-4, buffer_size=int(1e6), def __init__(self, policy, env, learning_rate=3e-4, buffer_size=int(1e6),
learning_starts=100, batch_size=64, learning_starts=100, batch_size=64,
tau=0.005, ent_coef='auto', target_update_interval=1, tau=0.005, ent_coef='auto', target_update_interval=1,
@ -281,7 +282,8 @@ class SAC(BaseRLModel):
:return: (Dict) of optimizer names and their state_dict :return: (Dict) of optimizer names and their state_dict
""" """
if self.ent_coef_optimizer is not None: if self.ent_coef_optimizer is not None:
return {"actor": self.actor.optimizer.state_dict(), "critic": self.critic.optimizer.state_dict(),"ent_coef_optimizer": self.ent_coef_optimizer.state_dict()} return {"actor": self.actor.optimizer.state_dict(), "critic": self.critic.optimizer.state_dict(),
"ent_coef_optimizer": self.ent_coef_optimizer.state_dict()}
else: else:
return {"actor": self.actor.optimizer.state_dict(), "critic": self.critic.optimizer.state_dict()} return {"actor": self.actor.optimizer.state_dict(), "critic": self.critic.optimizer.state_dict()}

View file

@ -85,15 +85,6 @@ class TD3(BaseRLModel):
self.policy = self.policy.to(self.device) self.policy = self.policy.to(self.device)
self._create_aliases() self._create_aliases()
def _resetup_model(self):
"""
method used to resetup anything that was not saved
:return:
"""
if self.replay_buffer is None:
obs_dim, action_dim = self.observation_space.shape[0], self.action_space.shape[0]
self.replay_buffer = ReplayBuffer(self.buffer_size, obs_dim, action_dim, self.device)
def _create_aliases(self): def _create_aliases(self):
self.actor = self.policy.actor self.actor = self.policy.actor
self.actor_target = self.policy.actor_target self.actor_target = self.policy.actor_target