pushing model
Browse files- .gitattributes +1 -0
- README.md +80 -0
- dqn_atari.cleanrl_model +3 -0
- dqn_atari.py +286 -0
- events.out.tfevents.1689750731.4090-171.2443727.0 +3 -0
- poetry.lock +0 -0
- pyproject.toml +108 -0
- replay.mp4 +0 -0
- videos/BreakoutNoFrameskip-v4__dqn_atari__1__1689750723-eval/rl-video-episode-0.mp4 +0 -0
- videos/BreakoutNoFrameskip-v4__dqn_atari__1__1689750723-eval/rl-video-episode-1.mp4 +0 -0
- videos/BreakoutNoFrameskip-v4__dqn_atari__1__1689750723-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 |
+
- BreakoutNoFrameskip-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: BreakoutNoFrameskip-v4
|
16 |
+
type: BreakoutNoFrameskip-v4
|
17 |
+
metrics:
|
18 |
+
- type: mean_reward
|
19 |
+
value: 67.10 +/- 69.94
|
20 |
+
name: mean_reward
|
21 |
+
verified: false
|
22 |
+
---
|
23 |
+
|
24 |
+
# (CleanRL) **DQN** Agent Playing **BreakoutNoFrameskip-v4**
|
25 |
+
|
26 |
+
This is a trained model of a DQN agent playing BreakoutNoFrameskip-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 BreakoutNoFrameskip-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/sdpkjc/BreakoutNoFrameskip-v4-dqn_atari-seed1/raw/main/dqn_atari.py
|
46 |
+
curl -OL https://huggingface.co/sdpkjc/BreakoutNoFrameskip-v4-dqn_atari-seed1/raw/main/pyproject.toml
|
47 |
+
curl -OL https://huggingface.co/sdpkjc/BreakoutNoFrameskip-v4-dqn_atari-seed1/raw/main/poetry.lock
|
48 |
+
poetry install --all-extras
|
49 |
+
python dqn_atari.py --track --capture-video --save-model --hf-entity sdpkjc --upload-mode --seed 1 --total-timesteps 1000000
|
50 |
+
```
|
51 |
+
|
52 |
+
# Hyperparameters
|
53 |
+
```python
|
54 |
+
{'batch_size': 32,
|
55 |
+
'buffer_size': 1000000,
|
56 |
+
'capture_video': True,
|
57 |
+
'cuda': True,
|
58 |
+
'end_e': 0.01,
|
59 |
+
'env_id': 'BreakoutNoFrameskip-v4',
|
60 |
+
'exp_name': 'dqn_atari',
|
61 |
+
'exploration_fraction': 0.1,
|
62 |
+
'gamma': 0.99,
|
63 |
+
'hf_entity': 'sdpkjc',
|
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': 1000000,
|
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:d7437f712df5f6934a79d3fe17709537915ee0c7bfb16c2ef9a3fc4663f75508
|
3 |
+
size 6748319
|
dqn_atari.py
ADDED
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
env = NoopResetEnv(env, noop_max=30)
|
96 |
+
env = MaxAndSkipEnv(env, skip=4)
|
97 |
+
env = EpisodicLifeEnv(env)
|
98 |
+
if "FIRE" in env.unwrapped.get_action_meanings():
|
99 |
+
env = FireResetEnv(env)
|
100 |
+
env = ClipRewardEnv(env)
|
101 |
+
env = gym.wrappers.ResizeObservation(env, (84, 84))
|
102 |
+
env = gym.wrappers.GrayScaleObservation(env)
|
103 |
+
env = gym.wrappers.FrameStack(env, 4)
|
104 |
+
env.action_space.seed(seed)
|
105 |
+
|
106 |
+
return env
|
107 |
+
|
108 |
+
return thunk
|
109 |
+
|
110 |
+
|
111 |
+
# ALGO LOGIC: initialize agent here:
|
112 |
+
class QNetwork(nn.Module):
|
113 |
+
def __init__(self, env):
|
114 |
+
super().__init__()
|
115 |
+
self.network = nn.Sequential(
|
116 |
+
nn.Conv2d(4, 32, 8, stride=4),
|
117 |
+
nn.ReLU(),
|
118 |
+
nn.Conv2d(32, 64, 4, stride=2),
|
119 |
+
nn.ReLU(),
|
120 |
+
nn.Conv2d(64, 64, 3, stride=1),
|
121 |
+
nn.ReLU(),
|
122 |
+
nn.Flatten(),
|
123 |
+
nn.Linear(3136, 512),
|
124 |
+
nn.ReLU(),
|
125 |
+
nn.Linear(512, env.single_action_space.n),
|
126 |
+
)
|
127 |
+
|
128 |
+
def forward(self, x):
|
129 |
+
return self.network(x / 255.0)
|
130 |
+
|
131 |
+
|
132 |
+
def linear_schedule(start_e: float, end_e: float, duration: int, t: int):
|
133 |
+
slope = (end_e - start_e) / duration
|
134 |
+
return max(slope * t + start_e, end_e)
|
135 |
+
|
136 |
+
|
137 |
+
if __name__ == "__main__":
|
138 |
+
import stable_baselines3 as sb3
|
139 |
+
|
140 |
+
if sb3.__version__ < "2.0":
|
141 |
+
raise ValueError(
|
142 |
+
"""Ongoing migration: run the following command to install the new dependencies:
|
143 |
+
|
144 |
+
poetry run pip install "stable_baselines3==2.0.0a1" "gymnasium[atari,accept-rom-license]==0.28.1" "ale-py==0.8.1"
|
145 |
+
"""
|
146 |
+
)
|
147 |
+
args = parse_args()
|
148 |
+
run_name = f"{args.env_id}__{args.exp_name}__{args.seed}__{int(time.time())}"
|
149 |
+
if args.track:
|
150 |
+
import wandb
|
151 |
+
|
152 |
+
wandb.init(
|
153 |
+
project=args.wandb_project_name,
|
154 |
+
entity=args.wandb_entity,
|
155 |
+
sync_tensorboard=True,
|
156 |
+
config=vars(args),
|
157 |
+
name=run_name,
|
158 |
+
monitor_gym=True,
|
159 |
+
save_code=True,
|
160 |
+
)
|
161 |
+
writer = SummaryWriter(f"runs/{run_name}")
|
162 |
+
writer.add_text(
|
163 |
+
"hyperparameters",
|
164 |
+
"|param|value|\n|-|-|\n%s" % ("\n".join([f"|{key}|{value}|" for key, value in vars(args).items()])),
|
165 |
+
)
|
166 |
+
|
167 |
+
# TRY NOT TO MODIFY: seeding
|
168 |
+
random.seed(args.seed)
|
169 |
+
np.random.seed(args.seed)
|
170 |
+
torch.manual_seed(args.seed)
|
171 |
+
torch.backends.cudnn.deterministic = args.torch_deterministic
|
172 |
+
|
173 |
+
device = torch.device("cuda" if torch.cuda.is_available() and args.cuda else "cpu")
|
174 |
+
|
175 |
+
# env setup
|
176 |
+
envs = gym.vector.SyncVectorEnv(
|
177 |
+
[make_env(args.env_id, args.seed + i, i, args.capture_video, run_name) for i in range(args.num_envs)]
|
178 |
+
)
|
179 |
+
assert isinstance(envs.single_action_space, gym.spaces.Discrete), "only discrete action space is supported"
|
180 |
+
|
181 |
+
q_network = QNetwork(envs).to(device)
|
182 |
+
optimizer = optim.Adam(q_network.parameters(), lr=args.learning_rate)
|
183 |
+
target_network = QNetwork(envs).to(device)
|
184 |
+
target_network.load_state_dict(q_network.state_dict())
|
185 |
+
|
186 |
+
rb = ReplayBuffer(
|
187 |
+
args.buffer_size,
|
188 |
+
envs.single_observation_space,
|
189 |
+
envs.single_action_space,
|
190 |
+
device,
|
191 |
+
optimize_memory_usage=True,
|
192 |
+
handle_timeout_termination=False,
|
193 |
+
)
|
194 |
+
start_time = time.time()
|
195 |
+
|
196 |
+
# TRY NOT TO MODIFY: start the game
|
197 |
+
obs, _ = envs.reset(seed=args.seed)
|
198 |
+
for global_step in range(args.total_timesteps):
|
199 |
+
# ALGO LOGIC: put action logic here
|
200 |
+
epsilon = linear_schedule(args.start_e, args.end_e, args.exploration_fraction * args.total_timesteps, global_step)
|
201 |
+
if random.random() < epsilon:
|
202 |
+
actions = np.array([envs.single_action_space.sample() for _ in range(envs.num_envs)])
|
203 |
+
else:
|
204 |
+
q_values = q_network(torch.Tensor(obs).to(device))
|
205 |
+
actions = torch.argmax(q_values, dim=1).cpu().numpy()
|
206 |
+
|
207 |
+
# TRY NOT TO MODIFY: execute the game and log data.
|
208 |
+
next_obs, rewards, terminated, truncated, infos = envs.step(actions)
|
209 |
+
|
210 |
+
# TRY NOT TO MODIFY: record rewards for plotting purposes
|
211 |
+
if "final_info" in infos:
|
212 |
+
for info in infos["final_info"]:
|
213 |
+
# Skip the envs that are not done
|
214 |
+
if "episode" not in info:
|
215 |
+
continue
|
216 |
+
print(f"global_step={global_step}, episodic_return={info['episode']['r']}")
|
217 |
+
writer.add_scalar("charts/episodic_return", info["episode"]["r"], global_step)
|
218 |
+
writer.add_scalar("charts/episodic_length", info["episode"]["l"], global_step)
|
219 |
+
writer.add_scalar("charts/epsilon", epsilon, global_step)
|
220 |
+
|
221 |
+
# TRY NOT TO MODIFY: save data to reply buffer; handle `final_observation`
|
222 |
+
real_next_obs = next_obs.copy()
|
223 |
+
for idx, d in enumerate(truncated):
|
224 |
+
if d:
|
225 |
+
real_next_obs[idx] = infos["final_observation"][idx]
|
226 |
+
rb.add(obs, real_next_obs, actions, rewards, terminated, infos)
|
227 |
+
|
228 |
+
# TRY NOT TO MODIFY: CRUCIAL step easy to overlook
|
229 |
+
obs = next_obs
|
230 |
+
|
231 |
+
# ALGO LOGIC: training.
|
232 |
+
if global_step > args.learning_starts:
|
233 |
+
if global_step % args.train_frequency == 0:
|
234 |
+
data = rb.sample(args.batch_size)
|
235 |
+
with torch.no_grad():
|
236 |
+
target_max, _ = target_network(data.next_observations).max(dim=1)
|
237 |
+
td_target = data.rewards.flatten() + args.gamma * target_max * (1 - data.dones.flatten())
|
238 |
+
old_val = q_network(data.observations).gather(1, data.actions).squeeze()
|
239 |
+
loss = F.mse_loss(td_target, old_val)
|
240 |
+
|
241 |
+
if global_step % 100 == 0:
|
242 |
+
writer.add_scalar("losses/td_loss", loss, global_step)
|
243 |
+
writer.add_scalar("losses/q_values", old_val.mean().item(), global_step)
|
244 |
+
print("SPS:", int(global_step / (time.time() - start_time)))
|
245 |
+
writer.add_scalar("charts/SPS", int(global_step / (time.time() - start_time)), global_step)
|
246 |
+
|
247 |
+
# optimize the model
|
248 |
+
optimizer.zero_grad()
|
249 |
+
loss.backward()
|
250 |
+
optimizer.step()
|
251 |
+
|
252 |
+
# update target network
|
253 |
+
if global_step % args.target_network_frequency == 0:
|
254 |
+
for target_network_param, q_network_param in zip(target_network.parameters(), q_network.parameters()):
|
255 |
+
target_network_param.data.copy_(
|
256 |
+
args.tau * q_network_param.data + (1.0 - args.tau) * target_network_param.data
|
257 |
+
)
|
258 |
+
|
259 |
+
if args.save_model:
|
260 |
+
model_path = f"runs/{run_name}/{args.exp_name}.cleanrl_model"
|
261 |
+
torch.save(q_network.state_dict(), model_path)
|
262 |
+
print(f"model saved to {model_path}")
|
263 |
+
from cleanrl_utils.evals.dqn_eval import evaluate
|
264 |
+
|
265 |
+
episodic_returns = evaluate(
|
266 |
+
model_path,
|
267 |
+
make_env,
|
268 |
+
args.env_id,
|
269 |
+
eval_episodes=10,
|
270 |
+
run_name=f"{run_name}-eval",
|
271 |
+
Model=QNetwork,
|
272 |
+
device=device,
|
273 |
+
epsilon=0.05,
|
274 |
+
)
|
275 |
+
for idx, episodic_return in enumerate(episodic_returns):
|
276 |
+
writer.add_scalar("eval/episodic_return", episodic_return, idx)
|
277 |
+
|
278 |
+
if args.upload_model:
|
279 |
+
from cleanrl_utils.huggingface import push_to_hub
|
280 |
+
|
281 |
+
repo_name = f"{args.env_id}-{args.exp_name}-seed{args.seed}"
|
282 |
+
repo_id = f"{args.hf_entity}/{repo_name}" if args.hf_entity else repo_name
|
283 |
+
push_to_hub(args, episodic_returns, repo_id, "DQN", f"runs/{run_name}", f"videos/{run_name}-eval")
|
284 |
+
|
285 |
+
envs.close()
|
286 |
+
writer.close()
|
events.out.tfevents.1689750731.4090-171.2443727.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:216762c8c76e877fdbaba12e3d78e1c9c0c562fca42e643775c2dfce4d1fb49c
|
3 |
+
size 1836157
|
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 (290 kB). View file
|
|
videos/BreakoutNoFrameskip-v4__dqn_atari__1__1689750723-eval/rl-video-episode-0.mp4
ADDED
Binary file (204 kB). View file
|
|
videos/BreakoutNoFrameskip-v4__dqn_atari__1__1689750723-eval/rl-video-episode-1.mp4
ADDED
Binary file (124 kB). View file
|
|
videos/BreakoutNoFrameskip-v4__dqn_atari__1__1689750723-eval/rl-video-episode-8.mp4
ADDED
Binary file (290 kB). View file
|
|