pushing model
Browse files- .gitattributes +1 -0
- README.md +80 -0
- dqn_atari.cleanrl_model +3 -0
- dqn_atari.py +288 -0
- events.out.tfevents.1699103868.3090-172.2510710.0 +3 -0
- poetry.lock +0 -0
- pyproject.toml +108 -0
- replay.mp4 +0 -0
- videos/MsPacmanNoFrameskip-v4__dqn_atari__1__1699103863-eval/rl-video-episode-0.mp4 +0 -0
- videos/MsPacmanNoFrameskip-v4__dqn_atari__1__1699103863-eval/rl-video-episode-1.mp4 +0 -0
- videos/MsPacmanNoFrameskip-v4__dqn_atari__1__1699103863-eval/rl-video-episode-8.mp4 +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
dqn_atari.cleanrl_model filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- MsPacmanNoFrameskip-v4
|
4 |
+
- deep-reinforcement-learning
|
5 |
+
- reinforcement-learning
|
6 |
+
- custom-implementation
|
7 |
+
library_name: cleanrl
|
8 |
+
model-index:
|
9 |
+
- name: DQN
|
10 |
+
results:
|
11 |
+
- task:
|
12 |
+
type: reinforcement-learning
|
13 |
+
name: reinforcement-learning
|
14 |
+
dataset:
|
15 |
+
name: MsPacmanNoFrameskip-v4
|
16 |
+
type: MsPacmanNoFrameskip-v4
|
17 |
+
metrics:
|
18 |
+
- type: mean_reward
|
19 |
+
value: 2585.00 +/- 842.17
|
20 |
+
name: mean_reward
|
21 |
+
verified: false
|
22 |
+
---
|
23 |
+
|
24 |
+
# (CleanRL) **DQN** Agent Playing **MsPacmanNoFrameskip-v4**
|
25 |
+
|
26 |
+
This is a trained model of a DQN agent playing MsPacmanNoFrameskip-v4.
|
27 |
+
The model was trained by using [CleanRL](https://github.com/vwxyzjn/cleanrl) and the most up-to-date training code can be
|
28 |
+
found [here](https://github.com/vwxyzjn/cleanrl/blob/master/cleanrl/dqn_atari.py).
|
29 |
+
|
30 |
+
## Get Started
|
31 |
+
|
32 |
+
To use this model, please install the `cleanrl` package with the following command:
|
33 |
+
|
34 |
+
```
|
35 |
+
pip install "cleanrl[dqn_atari]"
|
36 |
+
python -m cleanrl_utils.enjoy --exp-name dqn_atari --env-id MsPacmanNoFrameskip-v4
|
37 |
+
```
|
38 |
+
|
39 |
+
Please refer to the [documentation](https://docs.cleanrl.dev/get-started/zoo/) for more detail.
|
40 |
+
|
41 |
+
|
42 |
+
## Command to reproduce the training
|
43 |
+
|
44 |
+
```bash
|
45 |
+
curl -OL https://huggingface.co/cleanrl/MsPacmanNoFrameskip-v4-dqn_atari-seed1/raw/main/dqn_atari.py
|
46 |
+
curl -OL https://huggingface.co/cleanrl/MsPacmanNoFrameskip-v4-dqn_atari-seed1/raw/main/pyproject.toml
|
47 |
+
curl -OL https://huggingface.co/cleanrl/MsPacmanNoFrameskip-v4-dqn_atari-seed1/raw/main/poetry.lock
|
48 |
+
poetry install --all-extras
|
49 |
+
python dqn_atari.py --save-model --upload-model --hf-entity cleanrl --env-id MsPacmanNoFrameskip-v4 --track
|
50 |
+
```
|
51 |
+
|
52 |
+
# Hyperparameters
|
53 |
+
```python
|
54 |
+
{'batch_size': 32,
|
55 |
+
'buffer_size': 1000000,
|
56 |
+
'capture_video': False,
|
57 |
+
'cuda': True,
|
58 |
+
'end_e': 0.01,
|
59 |
+
'env_id': 'MsPacmanNoFrameskip-v4',
|
60 |
+
'exp_name': 'dqn_atari',
|
61 |
+
'exploration_fraction': 0.1,
|
62 |
+
'gamma': 0.99,
|
63 |
+
'hf_entity': 'cleanrl',
|
64 |
+
'learning_rate': 0.0001,
|
65 |
+
'learning_starts': 80000,
|
66 |
+
'num_envs': 1,
|
67 |
+
'save_model': True,
|
68 |
+
'seed': 1,
|
69 |
+
'start_e': 1,
|
70 |
+
'target_network_frequency': 1000,
|
71 |
+
'tau': 1.0,
|
72 |
+
'torch_deterministic': True,
|
73 |
+
'total_timesteps': 10000000,
|
74 |
+
'track': True,
|
75 |
+
'train_frequency': 4,
|
76 |
+
'upload_model': True,
|
77 |
+
'wandb_entity': None,
|
78 |
+
'wandb_project_name': 'cleanRL'}
|
79 |
+
```
|
80 |
+
|
dqn_atari.cleanrl_model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5454274f7777db8011f3fac2174c67ad249cce3ab213931a09f198821daf02a8
|
3 |
+
size 6758559
|
dqn_atari.py
ADDED
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# docs and experiment results can be found at https://docs.cleanrl.dev/rl-algorithms/dqn/#dqn_ataripy
|
2 |
+
import argparse
|
3 |
+
import os
|
4 |
+
import random
|
5 |
+
import time
|
6 |
+
from distutils.util import strtobool
|
7 |
+
|
8 |
+
import gymnasium as gym
|
9 |
+
import numpy as np
|
10 |
+
import torch
|
11 |
+
import torch.nn as nn
|
12 |
+
import torch.nn.functional as F
|
13 |
+
import torch.optim as optim
|
14 |
+
from stable_baselines3.common.atari_wrappers import (
|
15 |
+
ClipRewardEnv,
|
16 |
+
EpisodicLifeEnv,
|
17 |
+
FireResetEnv,
|
18 |
+
MaxAndSkipEnv,
|
19 |
+
NoopResetEnv,
|
20 |
+
)
|
21 |
+
from stable_baselines3.common.buffers import ReplayBuffer
|
22 |
+
from torch.utils.tensorboard import SummaryWriter
|
23 |
+
|
24 |
+
|
25 |
+
def parse_args():
|
26 |
+
# fmt: off
|
27 |
+
parser = argparse.ArgumentParser()
|
28 |
+
parser.add_argument("--exp-name", type=str, default=os.path.basename(__file__).rstrip(".py"),
|
29 |
+
help="the name of this experiment")
|
30 |
+
parser.add_argument("--seed", type=int, default=1,
|
31 |
+
help="seed of the experiment")
|
32 |
+
parser.add_argument("--torch-deterministic", type=lambda x: bool(strtobool(x)), default=True, nargs="?", const=True,
|
33 |
+
help="if toggled, `torch.backends.cudnn.deterministic=False`")
|
34 |
+
parser.add_argument("--cuda", type=lambda x: bool(strtobool(x)), default=True, nargs="?", const=True,
|
35 |
+
help="if toggled, cuda will be enabled by default")
|
36 |
+
parser.add_argument("--track", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
37 |
+
help="if toggled, this experiment will be tracked with Weights and Biases")
|
38 |
+
parser.add_argument("--wandb-project-name", type=str, default="cleanRL",
|
39 |
+
help="the wandb's project name")
|
40 |
+
parser.add_argument("--wandb-entity", type=str, default=None,
|
41 |
+
help="the entity (team) of wandb's project")
|
42 |
+
parser.add_argument("--capture-video", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
43 |
+
help="whether to capture videos of the agent performances (check out `videos` folder)")
|
44 |
+
parser.add_argument("--save-model", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
45 |
+
help="whether to save model into the `runs/{run_name}` folder")
|
46 |
+
parser.add_argument("--upload-model", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
47 |
+
help="whether to upload the saved model to huggingface")
|
48 |
+
parser.add_argument("--hf-entity", type=str, default="",
|
49 |
+
help="the user or org name of the model repository from the Hugging Face Hub")
|
50 |
+
|
51 |
+
# Algorithm specific arguments
|
52 |
+
parser.add_argument("--env-id", type=str, default="BreakoutNoFrameskip-v4",
|
53 |
+
help="the id of the environment")
|
54 |
+
parser.add_argument("--total-timesteps", type=int, default=10000000,
|
55 |
+
help="total timesteps of the experiments")
|
56 |
+
parser.add_argument("--learning-rate", type=float, default=1e-4,
|
57 |
+
help="the learning rate of the optimizer")
|
58 |
+
parser.add_argument("--num-envs", type=int, default=1,
|
59 |
+
help="the number of parallel game environments")
|
60 |
+
parser.add_argument("--buffer-size", type=int, default=1000000,
|
61 |
+
help="the replay memory buffer size")
|
62 |
+
parser.add_argument("--gamma", type=float, default=0.99,
|
63 |
+
help="the discount factor gamma")
|
64 |
+
parser.add_argument("--tau", type=float, default=1.,
|
65 |
+
help="the target network update rate")
|
66 |
+
parser.add_argument("--target-network-frequency", type=int, default=1000,
|
67 |
+
help="the timesteps it takes to update the target network")
|
68 |
+
parser.add_argument("--batch-size", type=int, default=32,
|
69 |
+
help="the batch size of sample from the reply memory")
|
70 |
+
parser.add_argument("--start-e", type=float, default=1,
|
71 |
+
help="the starting epsilon for exploration")
|
72 |
+
parser.add_argument("--end-e", type=float, default=0.01,
|
73 |
+
help="the ending epsilon for exploration")
|
74 |
+
parser.add_argument("--exploration-fraction", type=float, default=0.10,
|
75 |
+
help="the fraction of `total-timesteps` it takes from start-e to go end-e")
|
76 |
+
parser.add_argument("--learning-starts", type=int, default=80000,
|
77 |
+
help="timestep to start learning")
|
78 |
+
parser.add_argument("--train-frequency", type=int, default=4,
|
79 |
+
help="the frequency of training")
|
80 |
+
args = parser.parse_args()
|
81 |
+
# fmt: on
|
82 |
+
assert args.num_envs == 1, "vectorized envs are not supported at the moment"
|
83 |
+
|
84 |
+
return args
|
85 |
+
|
86 |
+
|
87 |
+
def make_env(env_id, seed, idx, capture_video, run_name):
|
88 |
+
def thunk():
|
89 |
+
if capture_video and idx == 0:
|
90 |
+
env = gym.make(env_id, render_mode="rgb_array")
|
91 |
+
env = gym.wrappers.RecordVideo(env, f"videos/{run_name}")
|
92 |
+
else:
|
93 |
+
env = gym.make(env_id)
|
94 |
+
env = gym.wrappers.RecordEpisodeStatistics(env)
|
95 |
+
|
96 |
+
env = NoopResetEnv(env, noop_max=30)
|
97 |
+
env = MaxAndSkipEnv(env, skip=4)
|
98 |
+
env = EpisodicLifeEnv(env)
|
99 |
+
if "FIRE" in env.unwrapped.get_action_meanings():
|
100 |
+
env = FireResetEnv(env)
|
101 |
+
env = ClipRewardEnv(env)
|
102 |
+
env = gym.wrappers.ResizeObservation(env, (84, 84))
|
103 |
+
env = gym.wrappers.GrayScaleObservation(env)
|
104 |
+
env = gym.wrappers.FrameStack(env, 4)
|
105 |
+
|
106 |
+
env.action_space.seed(seed)
|
107 |
+
return env
|
108 |
+
|
109 |
+
return thunk
|
110 |
+
|
111 |
+
|
112 |
+
# ALGO LOGIC: initialize agent here:
|
113 |
+
class QNetwork(nn.Module):
|
114 |
+
def __init__(self, env):
|
115 |
+
super().__init__()
|
116 |
+
self.network = nn.Sequential(
|
117 |
+
nn.Conv2d(4, 32, 8, stride=4),
|
118 |
+
nn.ReLU(),
|
119 |
+
nn.Conv2d(32, 64, 4, stride=2),
|
120 |
+
nn.ReLU(),
|
121 |
+
nn.Conv2d(64, 64, 3, stride=1),
|
122 |
+
nn.ReLU(),
|
123 |
+
nn.Flatten(),
|
124 |
+
nn.Linear(3136, 512),
|
125 |
+
nn.ReLU(),
|
126 |
+
nn.Linear(512, env.single_action_space.n),
|
127 |
+
)
|
128 |
+
|
129 |
+
def forward(self, x):
|
130 |
+
return self.network(x / 255.0)
|
131 |
+
|
132 |
+
|
133 |
+
def linear_schedule(start_e: float, end_e: float, duration: int, t: int):
|
134 |
+
slope = (end_e - start_e) / duration
|
135 |
+
return max(slope * t + start_e, end_e)
|
136 |
+
|
137 |
+
|
138 |
+
if __name__ == "__main__":
|
139 |
+
import stable_baselines3 as sb3
|
140 |
+
|
141 |
+
if sb3.__version__ < "2.0":
|
142 |
+
raise ValueError(
|
143 |
+
"""Ongoing migration: run the following command to install the new dependencies:
|
144 |
+
|
145 |
+
poetry run pip install "stable_baselines3==2.0.0a1" "gymnasium[atari,accept-rom-license]==0.28.1" "ale-py==0.8.1"
|
146 |
+
"""
|
147 |
+
)
|
148 |
+
args = parse_args()
|
149 |
+
run_name = f"{args.env_id}__{args.exp_name}__{args.seed}__{int(time.time())}"
|
150 |
+
if args.track:
|
151 |
+
import wandb
|
152 |
+
|
153 |
+
wandb.init(
|
154 |
+
project=args.wandb_project_name,
|
155 |
+
entity=args.wandb_entity,
|
156 |
+
sync_tensorboard=True,
|
157 |
+
config=vars(args),
|
158 |
+
name=run_name,
|
159 |
+
monitor_gym=True,
|
160 |
+
save_code=True,
|
161 |
+
)
|
162 |
+
writer = SummaryWriter(f"runs/{run_name}")
|
163 |
+
writer.add_text(
|
164 |
+
"hyperparameters",
|
165 |
+
"|param|value|\n|-|-|\n%s" % ("\n".join([f"|{key}|{value}|" for key, value in vars(args).items()])),
|
166 |
+
)
|
167 |
+
|
168 |
+
# TRY NOT TO MODIFY: seeding
|
169 |
+
random.seed(args.seed)
|
170 |
+
np.random.seed(args.seed)
|
171 |
+
torch.manual_seed(args.seed)
|
172 |
+
torch.backends.cudnn.deterministic = args.torch_deterministic
|
173 |
+
|
174 |
+
device = torch.device("cuda" if torch.cuda.is_available() and args.cuda else "cpu")
|
175 |
+
|
176 |
+
# env setup
|
177 |
+
envs = gym.vector.SyncVectorEnv(
|
178 |
+
[make_env(args.env_id, args.seed + i, i, args.capture_video, run_name) for i in range(args.num_envs)]
|
179 |
+
)
|
180 |
+
assert isinstance(envs.single_action_space, gym.spaces.Discrete), "only discrete action space is supported"
|
181 |
+
|
182 |
+
q_network = QNetwork(envs).to(device)
|
183 |
+
optimizer = optim.Adam(q_network.parameters(), lr=args.learning_rate)
|
184 |
+
target_network = QNetwork(envs).to(device)
|
185 |
+
target_network.load_state_dict(q_network.state_dict())
|
186 |
+
|
187 |
+
rb = ReplayBuffer(
|
188 |
+
args.buffer_size,
|
189 |
+
envs.single_observation_space,
|
190 |
+
envs.single_action_space,
|
191 |
+
device,
|
192 |
+
optimize_memory_usage=True,
|
193 |
+
handle_timeout_termination=False,
|
194 |
+
)
|
195 |
+
start_time = time.time()
|
196 |
+
|
197 |
+
# TRY NOT TO MODIFY: start the game
|
198 |
+
obs, _ = envs.reset(seed=args.seed)
|
199 |
+
for global_step in range(args.total_timesteps):
|
200 |
+
# ALGO LOGIC: put action logic here
|
201 |
+
epsilon = linear_schedule(args.start_e, args.end_e, args.exploration_fraction * args.total_timesteps, global_step)
|
202 |
+
if random.random() < epsilon:
|
203 |
+
actions = np.array([envs.single_action_space.sample() for _ in range(envs.num_envs)])
|
204 |
+
else:
|
205 |
+
q_values = q_network(torch.Tensor(obs).to(device))
|
206 |
+
actions = torch.argmax(q_values, dim=1).cpu().numpy()
|
207 |
+
|
208 |
+
# TRY NOT TO MODIFY: execute the game and log data.
|
209 |
+
next_obs, rewards, terminations, truncations, infos = envs.step(actions)
|
210 |
+
|
211 |
+
# TRY NOT TO MODIFY: record rewards for plotting purposes
|
212 |
+
if "final_info" in infos:
|
213 |
+
for info in infos["final_info"]:
|
214 |
+
# Skip the envs that are not done
|
215 |
+
if "episode" not in info:
|
216 |
+
continue
|
217 |
+
print(f"global_step={global_step}, episodic_return={info['episode']['r']}")
|
218 |
+
writer.add_scalar("charts/episodic_return", info["episode"]["r"], global_step)
|
219 |
+
writer.add_scalar("charts/episodic_length", info["episode"]["l"], global_step)
|
220 |
+
writer.add_scalar("charts/epsilon", epsilon, global_step)
|
221 |
+
break
|
222 |
+
|
223 |
+
# TRY NOT TO MODIFY: save data to reply buffer; handle `final_observation`
|
224 |
+
real_next_obs = next_obs.copy()
|
225 |
+
for idx, trunc in enumerate(truncations):
|
226 |
+
if trunc:
|
227 |
+
real_next_obs[idx] = infos["final_observation"][idx]
|
228 |
+
rb.add(obs, real_next_obs, actions, rewards, terminations, infos)
|
229 |
+
|
230 |
+
# TRY NOT TO MODIFY: CRUCIAL step easy to overlook
|
231 |
+
obs = next_obs
|
232 |
+
|
233 |
+
# ALGO LOGIC: training.
|
234 |
+
if global_step > args.learning_starts:
|
235 |
+
if global_step % args.train_frequency == 0:
|
236 |
+
data = rb.sample(args.batch_size)
|
237 |
+
with torch.no_grad():
|
238 |
+
target_max, _ = target_network(data.next_observations).max(dim=1)
|
239 |
+
td_target = data.rewards.flatten() + args.gamma * target_max * (1 - data.dones.flatten())
|
240 |
+
old_val = q_network(data.observations).gather(1, data.actions).squeeze()
|
241 |
+
loss = F.mse_loss(td_target, old_val)
|
242 |
+
|
243 |
+
if global_step % 100 == 0:
|
244 |
+
writer.add_scalar("losses/td_loss", loss, global_step)
|
245 |
+
writer.add_scalar("losses/q_values", old_val.mean().item(), global_step)
|
246 |
+
print("SPS:", int(global_step / (time.time() - start_time)))
|
247 |
+
writer.add_scalar("charts/SPS", int(global_step / (time.time() - start_time)), global_step)
|
248 |
+
|
249 |
+
# optimize the model
|
250 |
+
optimizer.zero_grad()
|
251 |
+
loss.backward()
|
252 |
+
optimizer.step()
|
253 |
+
|
254 |
+
# update target network
|
255 |
+
if global_step % args.target_network_frequency == 0:
|
256 |
+
for target_network_param, q_network_param in zip(target_network.parameters(), q_network.parameters()):
|
257 |
+
target_network_param.data.copy_(
|
258 |
+
args.tau * q_network_param.data + (1.0 - args.tau) * target_network_param.data
|
259 |
+
)
|
260 |
+
|
261 |
+
if args.save_model:
|
262 |
+
model_path = f"runs/{run_name}/{args.exp_name}.cleanrl_model"
|
263 |
+
torch.save(q_network.state_dict(), model_path)
|
264 |
+
print(f"model saved to {model_path}")
|
265 |
+
from cleanrl_utils.evals.dqn_eval import evaluate
|
266 |
+
|
267 |
+
episodic_returns = evaluate(
|
268 |
+
model_path,
|
269 |
+
make_env,
|
270 |
+
args.env_id,
|
271 |
+
eval_episodes=10,
|
272 |
+
run_name=f"{run_name}-eval",
|
273 |
+
Model=QNetwork,
|
274 |
+
device=device,
|
275 |
+
epsilon=0.05,
|
276 |
+
)
|
277 |
+
for idx, episodic_return in enumerate(episodic_returns):
|
278 |
+
writer.add_scalar("eval/episodic_return", episodic_return, idx)
|
279 |
+
|
280 |
+
if args.upload_model:
|
281 |
+
from cleanrl_utils.huggingface import push_to_hub
|
282 |
+
|
283 |
+
repo_name = f"{args.env_id}-{args.exp_name}-seed{args.seed}"
|
284 |
+
repo_id = f"{args.hf_entity}/{repo_name}" if args.hf_entity else repo_name
|
285 |
+
push_to_hub(args, episodic_returns, repo_id, "DQN", f"runs/{run_name}", f"videos/{run_name}-eval")
|
286 |
+
|
287 |
+
envs.close()
|
288 |
+
writer.close()
|
events.out.tfevents.1699103868.3090-172.2510710.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:695f39a2577e07f9d879e0d8326e4e4655a3109248c709a5e213484cf7e6402a
|
3 |
+
size 18047074
|
poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "cleanrl"
|
3 |
+
version = "1.1.0"
|
4 |
+
description = "High-quality single file implementation of Deep Reinforcement Learning algorithms with research-friendly features"
|
5 |
+
authors = ["Costa Huang <costa.huang@outlook.com>"]
|
6 |
+
packages = [
|
7 |
+
{ include = "cleanrl" },
|
8 |
+
{ include = "cleanrl_utils" },
|
9 |
+
]
|
10 |
+
keywords = ["reinforcement", "machine", "learning", "research"]
|
11 |
+
license="MIT"
|
12 |
+
readme = "README.md"
|
13 |
+
|
14 |
+
[tool.poetry.dependencies]
|
15 |
+
python = ">=3.7.1,<3.11"
|
16 |
+
tensorboard = "^2.10.0"
|
17 |
+
wandb = "^0.13.11"
|
18 |
+
gym = "0.23.1"
|
19 |
+
torch = ">=1.12.1"
|
20 |
+
stable-baselines3 = "1.2.0"
|
21 |
+
gymnasium = ">=0.28.1"
|
22 |
+
moviepy = "^1.0.3"
|
23 |
+
pygame = "2.1.0"
|
24 |
+
huggingface-hub = "^0.11.1"
|
25 |
+
rich = "<12.0"
|
26 |
+
tenacity = "^8.2.2"
|
27 |
+
|
28 |
+
ale-py = {version = "0.7.4", optional = true}
|
29 |
+
AutoROM = {extras = ["accept-rom-license"], version = "^0.4.2", optional = true}
|
30 |
+
opencv-python = {version = "^4.6.0.66", optional = true}
|
31 |
+
procgen = {version = "^0.10.7", optional = true}
|
32 |
+
pytest = {version = "^7.1.3", optional = true}
|
33 |
+
mujoco = {version = "<=2.3.3", optional = true}
|
34 |
+
imageio = {version = "^2.14.1", optional = true}
|
35 |
+
free-mujoco-py = {version = "^2.1.6", optional = true}
|
36 |
+
mkdocs-material = {version = "^8.4.3", optional = true}
|
37 |
+
markdown-include = {version = "^0.7.0", optional = true}
|
38 |
+
openrlbenchmark = {version = "^0.1.1b4", optional = true}
|
39 |
+
jax = {version = "^0.3.17", optional = true}
|
40 |
+
jaxlib = {version = "^0.3.15", optional = true}
|
41 |
+
flax = {version = "^0.6.0", optional = true}
|
42 |
+
optuna = {version = "^3.0.1", optional = true}
|
43 |
+
optuna-dashboard = {version = "^0.7.2", optional = true}
|
44 |
+
envpool = {version = "^0.6.4", optional = true}
|
45 |
+
PettingZoo = {version = "1.18.1", optional = true}
|
46 |
+
SuperSuit = {version = "3.4.0", optional = true}
|
47 |
+
multi-agent-ale-py = {version = "0.1.11", optional = true}
|
48 |
+
boto3 = {version = "^1.24.70", optional = true}
|
49 |
+
awscli = {version = "^1.25.71", optional = true}
|
50 |
+
shimmy = {version = ">=1.0.0", extras = ["dm-control"], optional = true}
|
51 |
+
|
52 |
+
[tool.poetry.group.dev.dependencies]
|
53 |
+
pre-commit = "^2.20.0"
|
54 |
+
|
55 |
+
|
56 |
+
[tool.poetry.group.isaacgym]
|
57 |
+
optional = true
|
58 |
+
[tool.poetry.group.isaacgym.dependencies]
|
59 |
+
isaacgymenvs = {git = "https://github.com/vwxyzjn/IsaacGymEnvs.git", rev = "poetry", python = ">=3.7.1,<3.10"}
|
60 |
+
isaacgym = {path = "cleanrl/ppo_continuous_action_isaacgym/isaacgym", develop = true}
|
61 |
+
|
62 |
+
|
63 |
+
[build-system]
|
64 |
+
requires = ["poetry-core"]
|
65 |
+
build-backend = "poetry.core.masonry.api"
|
66 |
+
|
67 |
+
[tool.poetry.extras]
|
68 |
+
atari = ["ale-py", "AutoROM", "opencv-python"]
|
69 |
+
procgen = ["procgen"]
|
70 |
+
plot = ["pandas", "seaborn"]
|
71 |
+
pytest = ["pytest"]
|
72 |
+
mujoco = ["mujoco", "imageio"]
|
73 |
+
mujoco_py = ["free-mujoco-py"]
|
74 |
+
jax = ["jax", "jaxlib", "flax"]
|
75 |
+
docs = ["mkdocs-material", "markdown-include", "openrlbenchmark"]
|
76 |
+
envpool = ["envpool"]
|
77 |
+
optuna = ["optuna", "optuna-dashboard"]
|
78 |
+
pettingzoo = ["PettingZoo", "SuperSuit", "multi-agent-ale-py"]
|
79 |
+
cloud = ["boto3", "awscli"]
|
80 |
+
dm_control = ["shimmy", "mujoco"]
|
81 |
+
|
82 |
+
# dependencies for algorithm variant (useful when you want to run a specific algorithm)
|
83 |
+
dqn = []
|
84 |
+
dqn_atari = ["ale-py", "AutoROM", "opencv-python"]
|
85 |
+
dqn_jax = ["jax", "jaxlib", "flax"]
|
86 |
+
dqn_atari_jax = [
|
87 |
+
"ale-py", "AutoROM", "opencv-python", # atari
|
88 |
+
"jax", "jaxlib", "flax" # jax
|
89 |
+
]
|
90 |
+
c51 = []
|
91 |
+
c51_atari = ["ale-py", "AutoROM", "opencv-python"]
|
92 |
+
c51_jax = ["jax", "jaxlib", "flax"]
|
93 |
+
c51_atari_jax = [
|
94 |
+
"ale-py", "AutoROM", "opencv-python", # atari
|
95 |
+
"jax", "jaxlib", "flax" # jax
|
96 |
+
]
|
97 |
+
ppo_atari_envpool_xla_jax_scan = [
|
98 |
+
"ale-py", "AutoROM", "opencv-python", # atari
|
99 |
+
"jax", "jaxlib", "flax", # jax
|
100 |
+
"envpool", # envpool
|
101 |
+
]
|
102 |
+
qdagger_dqn_atari_impalacnn = [
|
103 |
+
"ale-py", "AutoROM", "opencv-python"
|
104 |
+
]
|
105 |
+
qdagger_dqn_atari_jax_impalacnn = [
|
106 |
+
"ale-py", "AutoROM", "opencv-python", # atari
|
107 |
+
"jax", "jaxlib", "flax", # jax
|
108 |
+
]
|
replay.mp4
ADDED
Binary file (567 kB). View file
|
|
videos/MsPacmanNoFrameskip-v4__dqn_atari__1__1699103863-eval/rl-video-episode-0.mp4
ADDED
Binary file (604 kB). View file
|
|
videos/MsPacmanNoFrameskip-v4__dqn_atari__1__1699103863-eval/rl-video-episode-1.mp4
ADDED
Binary file (647 kB). View file
|
|
videos/MsPacmanNoFrameskip-v4__dqn_atari__1__1699103863-eval/rl-video-episode-8.mp4
ADDED
Binary file (567 kB). View file
|
|