Oh, I could start using git...
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
policy:
|
||||
input_dim: 4
|
||||
output_dim: 2
|
||||
hidden_sizes: [64, 64]
|
||||
|
||||
ppo:
|
||||
learning_rate: 3e-4
|
||||
n_steps: 2048
|
||||
batch_size: 64
|
||||
n_epochs: 10
|
||||
gamma: 0.99
|
||||
gae_lambda: 0.95
|
||||
clip_range: 0.2
|
||||
total_timesteps: 1000000
|
||||
eval_interval: 2048
|
||||
eval_deterministic: true
|
||||
eval_episodes: 10
|
||||
seed: 42
|
||||
|
||||
loggers:
|
||||
- type: terminal
|
||||
- type: wandb
|
||||
project: "PPO_project"
|
||||
entity: "your_entity"
|
||||
push_interval: 10
|
||||
@@ -0,0 +1,37 @@
|
||||
import yaml
|
||||
import torch
|
||||
from fancy_rl.ppo import PPO
|
||||
from fancy_rl.policy import Policy
|
||||
from fancy_rl.loggers import TerminalLogger, WandbLogger
|
||||
import gymnasium as gym
|
||||
|
||||
def main(config_file):
|
||||
with open(config_file, 'r') as file:
|
||||
config = yaml.safe_load(file)
|
||||
|
||||
env_fn = lambda: gym.make("CartPole-v1")
|
||||
env = env_fn()
|
||||
|
||||
policy_config = config['policy']
|
||||
policy = Policy(env=env, hidden_sizes=policy_config['hidden_sizes'])
|
||||
|
||||
ppo_config = config['ppo']
|
||||
loggers_config = config['loggers']
|
||||
|
||||
loggers = []
|
||||
for logger_config in loggers_config:
|
||||
logger_type = logger_config.pop('type')
|
||||
if logger_type == 'terminal':
|
||||
loggers.append(TerminalLogger(**logger_config))
|
||||
elif logger_type == 'wandb':
|
||||
loggers.append(WandbLogger(**logger_config))
|
||||
|
||||
ppo = PPO(policy=policy,
|
||||
env_fn=env_fn,
|
||||
loggers=loggers,
|
||||
**ppo_config)
|
||||
|
||||
ppo.train()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main("example/config.yaml")
|
||||
Reference in New Issue
Block a user