Repository navigation
Expand file tree
/
Copy pathcombined_ppo.py
More file actions
66 lines (57 loc) · 1.98 KB
/
Copy pathcombined_ppo.py
File metadata and controls
66 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# from sb3_contrib.common.maskable.evaluation import evaluate_policy
from sb3_contrib.common.maskable.utils import get_action_masks
from ppo_mask_recurrent import RecurrentMaskablePPO
from common.evaluation import evaluate_policy
import gymnasium
import gymnasium_env
from bible import Bible
import torch
import torch.nn as nn
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
from sb3_contrib import MaskablePPO
import yaml
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
phases = {1: [(1, 3), 80_000],
2: [(4, 5), 500_000],
3: [(6, 9), 700_000],
4: [(10, 13), 1_000_000],
5: [(14, 17), 500_000],
6: [(18, 20), 100_000],
7: [(21, 23), 50_000],
8: [(24, 29), 1_000]
}
# bible = Bible(config['train_set'], phase=1)
bible = Bible(config['train_set'])
env = gymnasium.make('gymnasium_env/HangMan', bible=bible)
model = RecurrentMaskablePPO(
"MlpLstmPolicy",
env,
verbose=config['verbose'],
learning_rate=config['learning_rate'],
n_steps=config['n_steps'],
batch_size=config['batch_size'],
n_epochs=config['n_epochs'],
gamma=config['gamma'],
gae_lambda=config['gae_lambda'],
clip_range=config['clip_range'],
ent_coef=config['ent_coef'],
vf_coef=config['vf_coef'],
max_grad_norm=config['max_grad_norm'],
tensorboard_log=config['tensorboard_log'],
device=device,
policy_kwargs = dict(
activation_fn=nn.ReLU,
net_arch=dict(pi=[128, 64], vf=[128, 64]), # Increased network layers and units
lstm_hidden_size=64,
n_lstm_layers=1,
shared_lstm=True,
enable_critic_lstm=False)
)
for i in range(1, 9):
print(f"Phase {i} training started")
bible = Bible(config['train_set'], phase=i)
env = gymnasium.make('gymnasium_env/HangMan', bible=bible)
model.set_env(env)
model.learn(total_timesteps=phases[i][1], progress_bar=True, reset_num_timesteps=False)
model.save("100cents")