Parameterize hidden layer size of policy, add some candidates to grid search

This commit is contained in:
ebuehrle
2022-02-23 18:14:23 +01:00
parent 7f64ec7bb0
commit 336cf02278
2 changed files with 8 additions and 7 deletions

View File

@@ -48,7 +48,7 @@ def training_function(config):
env_fn = lambda i: envs[i]
policy = SetMaskedDiscretePolicy(env_fn(0).action_space.n) # config net architecture
policy = SetMaskedDiscretePolicy(env_fn(0).action_space.n, hidden_layer_size=config['policy']['hidden_layer_size']) # config net architecture
pi_opt = torch.optim.Adam(policy.parameters(), lr=config['policy']['learning_rate'])
pi_lr_scheduler = torch.optim.lr_scheduler.ExponentialLR(pi_opt, gamma=config['policy']['learning_rate_decay'])
@@ -91,10 +91,11 @@ analysis = tune.run(
training_function,
config={
'policy': {
'learning_rate': tune.grid_search([3e-4]),
'learning_rate_decay': tune.grid_search([1.0]),
'clip_ratio': tune.grid_search([0.2]),
'learning_rate': tune.grid_search([1e-5, 7e-5, 3e-4]),
'learning_rate_decay': tune.grid_search([1.0, 0.98]),
'clip_ratio': tune.grid_search([0.2, 0.1]),
'iterations_per_epoch': tune.grid_search([100]),
'hidden_layer_size': tune.grid_search([10, 25, 50])
},
'value': {
'learning_rate': tune.grid_search([1e-3]),

View File

@@ -51,12 +51,12 @@ class Policy(BasePolicy):
class DiscretePolicy(BasePolicy):
def __init__(self, *args, **kwargs):
def __init__(self, *args, hidden_layer_size=50, **kwargs):
super().__init__(*args, **kwargs)
self.nn = nn.Sequential(
nn.LazyLinear(50),
nn.LazyLinear(hidden_layer_size),
nn.Tanh(),
nn.LazyLinear(50),
nn.LazyLinear(hidden_layer_size),
nn.Tanh(),
nn.LazyLinear(self.action_dim),
)