pushing model
Browse files- .gitattributes +5 -0
- README.md +64 -0
- dqn_atari_jax.cleanrl_model +3 -0
- dqn_atari_jax.py +294 -0
- events.out.tfevents.1671134108.pop-os.1473648.0 +3 -0
- poetry.lock +0 -0
- pyproject.toml +158 -0
- replay.mp4 +3 -0
- videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-0.mp4 +3 -0
- videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-1.mp4 +3 -0
- videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-8.mp4 +3 -0
.gitattributes
CHANGED
@@ -32,3 +32,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-0.mp4 filter=lfs diff=lfs merge=lfs -text
|
36 |
+
videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-1.mp4 filter=lfs diff=lfs merge=lfs -text
|
37 |
+
videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-8.mp4 filter=lfs diff=lfs merge=lfs -text
|
38 |
+
replay.mp4 filter=lfs diff=lfs merge=lfs -text
|
39 |
+
dqn_atari_jax.cleanrl_model filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- BeamRiderNoFrameskip-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: BeamRiderNoFrameskip-v4
|
16 |
+
type: BeamRiderNoFrameskip-v4
|
17 |
+
metrics:
|
18 |
+
- type: mean_reward
|
19 |
+
value: 5091.00 +/- 1923.97
|
20 |
+
name: mean_reward
|
21 |
+
verified: false
|
22 |
+
---
|
23 |
+
|
24 |
+
# (CleanRL) **DQN** Agent Playing **BeamRiderNoFrameskip-v4**
|
25 |
+
|
26 |
+
This is a trained model of a DQN agent playing BeamRiderNoFrameskip-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_jax.py).
|
29 |
+
|
30 |
+
## Command to reproduce the training
|
31 |
+
|
32 |
+
```bash
|
33 |
+
curl -OL https://huggingface.co/cleanrl/BeamRiderNoFrameskip-v4-dqn_atari_jax-seed1/raw/main/dqn.py
|
34 |
+
curl -OL https://huggingface.co/cleanrl/BeamRiderNoFrameskip-v4-dqn_atari_jax-seed1/raw/main/pyproject.toml
|
35 |
+
curl -OL https://huggingface.co/cleanrl/BeamRiderNoFrameskip-v4-dqn_atari_jax-seed1/raw/main/poetry.lock
|
36 |
+
poetry install --all-extras
|
37 |
+
python dqn_atari_jax.py --track --capture-video --save-model --upload-model --hf-entity cleanrl --env-id BeamRiderNoFrameskip-v4 --seed 1
|
38 |
+
```
|
39 |
+
|
40 |
+
# Hyperparameters
|
41 |
+
```python
|
42 |
+
{'batch_size': 32,
|
43 |
+
'buffer_size': 1000000,
|
44 |
+
'capture_video': True,
|
45 |
+
'end_e': 0.01,
|
46 |
+
'env_id': 'BeamRiderNoFrameskip-v4',
|
47 |
+
'exp_name': 'dqn_atari_jax',
|
48 |
+
'exploration_fraction': 0.1,
|
49 |
+
'gamma': 0.99,
|
50 |
+
'hf_entity': 'cleanrl',
|
51 |
+
'learning_rate': 0.0001,
|
52 |
+
'learning_starts': 80000,
|
53 |
+
'save_model': True,
|
54 |
+
'seed': 1,
|
55 |
+
'start_e': 1,
|
56 |
+
'target_network_frequency': 1000,
|
57 |
+
'total_timesteps': 10000000,
|
58 |
+
'track': True,
|
59 |
+
'train_frequency': 4,
|
60 |
+
'upload_model': True,
|
61 |
+
'wandb_entity': None,
|
62 |
+
'wandb_project_name': 'cleanRL'}
|
63 |
+
```
|
64 |
+
|
dqn_atari_jax.cleanrl_model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d32e7a195a6af98a1db5791e1203cf3ee7f0ff2925b3139b0e1f8df509129e51
|
3 |
+
size 6755298
|
dqn_atari_jax.py
ADDED
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# docs and experiment results can be found at https://docs.cleanrl.dev/rl-algorithms/dqn/#dqn_atari_jaxpy
|
2 |
+
import argparse
|
3 |
+
import os
|
4 |
+
import random
|
5 |
+
import time
|
6 |
+
from distutils.util import strtobool
|
7 |
+
|
8 |
+
os.environ[
|
9 |
+
"XLA_PYTHON_CLIENT_MEM_FRACTION"
|
10 |
+
] = "0.7" # see https://github.com/google/jax/discussions/6332#discussioncomment-1279991
|
11 |
+
|
12 |
+
import flax
|
13 |
+
import flax.linen as nn
|
14 |
+
import gym
|
15 |
+
import jax
|
16 |
+
import jax.numpy as jnp
|
17 |
+
import numpy as np
|
18 |
+
import optax
|
19 |
+
from flax.training.train_state import TrainState
|
20 |
+
from stable_baselines3.common.atari_wrappers import (
|
21 |
+
ClipRewardEnv,
|
22 |
+
EpisodicLifeEnv,
|
23 |
+
FireResetEnv,
|
24 |
+
MaxAndSkipEnv,
|
25 |
+
NoopResetEnv,
|
26 |
+
)
|
27 |
+
from stable_baselines3.common.buffers import ReplayBuffer
|
28 |
+
from torch.utils.tensorboard import SummaryWriter
|
29 |
+
|
30 |
+
|
31 |
+
def parse_args():
|
32 |
+
# fmt: off
|
33 |
+
parser = argparse.ArgumentParser()
|
34 |
+
parser.add_argument("--exp-name", type=str, default=os.path.basename(__file__).rstrip(".py"),
|
35 |
+
help="the name of this experiment")
|
36 |
+
parser.add_argument("--seed", type=int, default=1,
|
37 |
+
help="seed of the experiment")
|
38 |
+
parser.add_argument("--track", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
39 |
+
help="if toggled, this experiment will be tracked with Weights and Biases")
|
40 |
+
parser.add_argument("--wandb-project-name", type=str, default="cleanRL",
|
41 |
+
help="the wandb's project name")
|
42 |
+
parser.add_argument("--wandb-entity", type=str, default=None,
|
43 |
+
help="the entity (team) of wandb's project")
|
44 |
+
parser.add_argument("--capture-video", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
45 |
+
help="whether to capture videos of the agent performances (check out `videos` folder)")
|
46 |
+
parser.add_argument("--save-model", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
47 |
+
help="whether to save model into the `runs/{run_name}` folder")
|
48 |
+
parser.add_argument("--upload-model", type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True,
|
49 |
+
help="whether to upload the saved model to huggingface")
|
50 |
+
parser.add_argument("--hf-entity", type=str, default="",
|
51 |
+
help="the user or org name of the model repository from the Hugging Face Hub")
|
52 |
+
|
53 |
+
# Algorithm specific arguments
|
54 |
+
parser.add_argument("--env-id", type=str, default="BreakoutNoFrameskip-v4",
|
55 |
+
help="the id of the environment")
|
56 |
+
parser.add_argument("--total-timesteps", type=int, default=10000000,
|
57 |
+
help="total timesteps of the experiments")
|
58 |
+
parser.add_argument("--learning-rate", type=float, default=1e-4,
|
59 |
+
help="the learning rate of the optimizer")
|
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("--target-network-frequency", type=int, default=1000,
|
65 |
+
help="the timesteps it takes to update the target network")
|
66 |
+
parser.add_argument("--batch-size", type=int, default=32,
|
67 |
+
help="the batch size of sample from the reply memory")
|
68 |
+
parser.add_argument("--start-e", type=float, default=1,
|
69 |
+
help="the starting epsilon for exploration")
|
70 |
+
parser.add_argument("--end-e", type=float, default=0.01,
|
71 |
+
help="the ending epsilon for exploration")
|
72 |
+
parser.add_argument("--exploration-fraction", type=float, default=0.10,
|
73 |
+
help="the fraction of `total-timesteps` it takes from start-e to go end-e")
|
74 |
+
parser.add_argument("--learning-starts", type=int, default=80000,
|
75 |
+
help="timestep to start learning")
|
76 |
+
parser.add_argument("--train-frequency", type=int, default=4,
|
77 |
+
help="the frequency of training")
|
78 |
+
args = parser.parse_args()
|
79 |
+
# fmt: on
|
80 |
+
return args
|
81 |
+
|
82 |
+
|
83 |
+
def make_env(env_id, seed, idx, capture_video, run_name):
|
84 |
+
def thunk():
|
85 |
+
env = gym.make(env_id)
|
86 |
+
env = gym.wrappers.RecordEpisodeStatistics(env)
|
87 |
+
if capture_video:
|
88 |
+
if idx == 0:
|
89 |
+
env = gym.wrappers.RecordVideo(env, f"videos/{run_name}")
|
90 |
+
env = NoopResetEnv(env, noop_max=30)
|
91 |
+
env = MaxAndSkipEnv(env, skip=4)
|
92 |
+
env = EpisodicLifeEnv(env)
|
93 |
+
if "FIRE" in env.unwrapped.get_action_meanings():
|
94 |
+
env = FireResetEnv(env)
|
95 |
+
env = ClipRewardEnv(env)
|
96 |
+
env = gym.wrappers.ResizeObservation(env, (84, 84))
|
97 |
+
env = gym.wrappers.GrayScaleObservation(env)
|
98 |
+
env = gym.wrappers.FrameStack(env, 4)
|
99 |
+
env.seed(seed)
|
100 |
+
env.action_space.seed(seed)
|
101 |
+
env.observation_space.seed(seed)
|
102 |
+
return env
|
103 |
+
|
104 |
+
return thunk
|
105 |
+
|
106 |
+
|
107 |
+
# ALGO LOGIC: initialize agent here:
|
108 |
+
class QNetwork(nn.Module):
|
109 |
+
action_dim: int
|
110 |
+
|
111 |
+
@nn.compact
|
112 |
+
def __call__(self, x):
|
113 |
+
x = jnp.transpose(x, (0, 2, 3, 1))
|
114 |
+
x = x / (255.0)
|
115 |
+
x = nn.Conv(32, kernel_size=(8, 8), strides=(4, 4), padding="VALID")(x)
|
116 |
+
x = nn.relu(x)
|
117 |
+
x = nn.Conv(64, kernel_size=(4, 4), strides=(2, 2), padding="VALID")(x)
|
118 |
+
x = nn.relu(x)
|
119 |
+
x = nn.Conv(64, kernel_size=(3, 3), strides=(1, 1), padding="VALID")(x)
|
120 |
+
x = nn.relu(x)
|
121 |
+
x = x.reshape((x.shape[0], -1))
|
122 |
+
x = nn.Dense(512)(x)
|
123 |
+
x = nn.relu(x)
|
124 |
+
x = nn.Dense(self.action_dim)(x)
|
125 |
+
return x
|
126 |
+
|
127 |
+
|
128 |
+
class TrainState(TrainState):
|
129 |
+
target_params: flax.core.FrozenDict
|
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 |
+
args = parse_args()
|
139 |
+
run_name = f"{args.env_id}__{args.exp_name}__{args.seed}__{int(time.time())}"
|
140 |
+
if args.track:
|
141 |
+
import wandb
|
142 |
+
|
143 |
+
wandb.init(
|
144 |
+
project=args.wandb_project_name,
|
145 |
+
entity=args.wandb_entity,
|
146 |
+
sync_tensorboard=True,
|
147 |
+
config=vars(args),
|
148 |
+
name=run_name,
|
149 |
+
monitor_gym=True,
|
150 |
+
save_code=True,
|
151 |
+
)
|
152 |
+
writer = SummaryWriter(f"runs/{run_name}")
|
153 |
+
writer.add_text(
|
154 |
+
"hyperparameters",
|
155 |
+
"|param|value|\n|-|-|\n%s" % ("\n".join([f"|{key}|{value}|" for key, value in vars(args).items()])),
|
156 |
+
)
|
157 |
+
|
158 |
+
# TRY NOT TO MODIFY: seeding
|
159 |
+
random.seed(args.seed)
|
160 |
+
np.random.seed(args.seed)
|
161 |
+
key = jax.random.PRNGKey(args.seed)
|
162 |
+
key, q_key = jax.random.split(key, 2)
|
163 |
+
|
164 |
+
# env setup
|
165 |
+
envs = gym.vector.SyncVectorEnv([make_env(args.env_id, args.seed, 0, args.capture_video, run_name)])
|
166 |
+
assert isinstance(envs.single_action_space, gym.spaces.Discrete), "only discrete action space is supported"
|
167 |
+
|
168 |
+
obs = envs.reset()
|
169 |
+
|
170 |
+
q_network = QNetwork(action_dim=envs.single_action_space.n)
|
171 |
+
|
172 |
+
q_state = TrainState.create(
|
173 |
+
apply_fn=q_network.apply,
|
174 |
+
params=q_network.init(q_key, obs),
|
175 |
+
target_params=q_network.init(q_key, obs),
|
176 |
+
tx=optax.adam(learning_rate=args.learning_rate),
|
177 |
+
)
|
178 |
+
|
179 |
+
q_network.apply = jax.jit(q_network.apply)
|
180 |
+
# This step is not necessary as init called on same observation and key will always lead to same initializations
|
181 |
+
q_state = q_state.replace(target_params=optax.incremental_update(q_state.params, q_state.target_params, 1))
|
182 |
+
|
183 |
+
rb = ReplayBuffer(
|
184 |
+
args.buffer_size,
|
185 |
+
envs.single_observation_space,
|
186 |
+
envs.single_action_space,
|
187 |
+
"cpu",
|
188 |
+
optimize_memory_usage=True,
|
189 |
+
handle_timeout_termination=True,
|
190 |
+
)
|
191 |
+
|
192 |
+
@jax.jit
|
193 |
+
def update(q_state, observations, actions, next_observations, rewards, dones):
|
194 |
+
q_next_target = q_network.apply(q_state.target_params, next_observations) # (batch_size, num_actions)
|
195 |
+
q_next_target = jnp.max(q_next_target, axis=-1) # (batch_size,)
|
196 |
+
next_q_value = rewards + (1 - dones) * args.gamma * q_next_target
|
197 |
+
|
198 |
+
def mse_loss(params):
|
199 |
+
q_pred = q_network.apply(params, observations) # (batch_size, num_actions)
|
200 |
+
q_pred = q_pred[np.arange(q_pred.shape[0]), actions.squeeze()] # (batch_size,)
|
201 |
+
return ((q_pred - next_q_value) ** 2).mean(), q_pred
|
202 |
+
|
203 |
+
(loss_value, q_pred), grads = jax.value_and_grad(mse_loss, has_aux=True)(q_state.params)
|
204 |
+
q_state = q_state.apply_gradients(grads=grads)
|
205 |
+
return loss_value, q_pred, q_state
|
206 |
+
|
207 |
+
start_time = time.time()
|
208 |
+
|
209 |
+
# TRY NOT TO MODIFY: start the game
|
210 |
+
obs = envs.reset()
|
211 |
+
for global_step in range(args.total_timesteps):
|
212 |
+
# ALGO LOGIC: put action logic here
|
213 |
+
epsilon = linear_schedule(args.start_e, args.end_e, args.exploration_fraction * args.total_timesteps, global_step)
|
214 |
+
if random.random() < epsilon:
|
215 |
+
actions = np.array([envs.single_action_space.sample() for _ in range(envs.num_envs)])
|
216 |
+
else:
|
217 |
+
q_values = q_network.apply(q_state.params, obs)
|
218 |
+
actions = q_values.argmax(axis=-1)
|
219 |
+
actions = jax.device_get(actions)
|
220 |
+
|
221 |
+
# TRY NOT TO MODIFY: execute the game and log data.
|
222 |
+
next_obs, rewards, dones, infos = envs.step(actions)
|
223 |
+
|
224 |
+
# TRY NOT TO MODIFY: record rewards for plotting purposes
|
225 |
+
for info in infos:
|
226 |
+
if "episode" in info.keys():
|
227 |
+
print(f"global_step={global_step}, episodic_return={info['episode']['r']}")
|
228 |
+
writer.add_scalar("charts/episodic_return", info["episode"]["r"], global_step)
|
229 |
+
writer.add_scalar("charts/episodic_length", info["episode"]["l"], global_step)
|
230 |
+
writer.add_scalar("charts/epsilon", epsilon, global_step)
|
231 |
+
break
|
232 |
+
|
233 |
+
# TRY NOT TO MODIFY: save data to reply buffer; handle `terminal_observation`
|
234 |
+
real_next_obs = next_obs.copy()
|
235 |
+
for idx, d in enumerate(dones):
|
236 |
+
if d:
|
237 |
+
real_next_obs[idx] = infos[idx]["terminal_observation"]
|
238 |
+
rb.add(obs, real_next_obs, actions, rewards, dones, infos)
|
239 |
+
|
240 |
+
# TRY NOT TO MODIFY: CRUCIAL step easy to overlook
|
241 |
+
obs = next_obs
|
242 |
+
|
243 |
+
# ALGO LOGIC: training.
|
244 |
+
if global_step > args.learning_starts:
|
245 |
+
if global_step % args.train_frequency == 0:
|
246 |
+
data = rb.sample(args.batch_size)
|
247 |
+
# perform a gradient-descent step
|
248 |
+
loss, old_val, q_state = update(
|
249 |
+
q_state,
|
250 |
+
data.observations.numpy(),
|
251 |
+
data.actions.numpy(),
|
252 |
+
data.next_observations.numpy(),
|
253 |
+
data.rewards.flatten().numpy(),
|
254 |
+
data.dones.flatten().numpy(),
|
255 |
+
)
|
256 |
+
|
257 |
+
if global_step % 100 == 0:
|
258 |
+
writer.add_scalar("losses/td_loss", jax.device_get(loss), global_step)
|
259 |
+
writer.add_scalar("losses/q_values", jax.device_get(old_val).mean(), global_step)
|
260 |
+
print("SPS:", int(global_step / (time.time() - start_time)))
|
261 |
+
writer.add_scalar("charts/SPS", int(global_step / (time.time() - start_time)), global_step)
|
262 |
+
|
263 |
+
# update the target network
|
264 |
+
if global_step % args.target_network_frequency == 0:
|
265 |
+
q_state = q_state.replace(target_params=optax.incremental_update(q_state.params, q_state.target_params, 1))
|
266 |
+
|
267 |
+
if args.save_model:
|
268 |
+
model_path = f"runs/{run_name}/{args.exp_name}.cleanrl_model"
|
269 |
+
with open(model_path, "wb") as f:
|
270 |
+
f.write(flax.serialization.to_bytes(q_state.params))
|
271 |
+
print(f"model saved to {model_path}")
|
272 |
+
from cleanrl_utils.evals.dqn_jax_eval import evaluate
|
273 |
+
|
274 |
+
episodic_returns = evaluate(
|
275 |
+
model_path,
|
276 |
+
make_env,
|
277 |
+
args.env_id,
|
278 |
+
eval_episodes=10,
|
279 |
+
run_name=f"{run_name}-eval",
|
280 |
+
Model=QNetwork,
|
281 |
+
epsilon=0.05,
|
282 |
+
)
|
283 |
+
for idx, episodic_return in enumerate(episodic_returns):
|
284 |
+
writer.add_scalar("eval/episodic_return", episodic_return, idx)
|
285 |
+
|
286 |
+
if args.upload_model:
|
287 |
+
from cleanrl_utils.huggingface import push_to_hub
|
288 |
+
|
289 |
+
repo_name = f"{args.env_id}-{args.exp_name}-seed{args.seed}"
|
290 |
+
repo_id = f"{args.hf_entity}/{repo_name}" if args.hf_entity else repo_name
|
291 |
+
push_to_hub(args, episodic_returns, repo_id, "DQN", f"runs/{run_name}", f"videos/{run_name}-eval")
|
292 |
+
|
293 |
+
envs.close()
|
294 |
+
writer.close()
|
events.out.tfevents.1671134108.pop-os.1473648.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4ae7c400af547eff10136e3f8984be3301948d151626db45d13cd429c0e9d52f
|
3 |
+
size 16475382
|
poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "cleanrl-test"
|
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 <[email protected]>"]
|
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.10"
|
16 |
+
tensorboard = "^2.10.0"
|
17 |
+
wandb = "^0.13.6"
|
18 |
+
gym = "0.23.1"
|
19 |
+
torch = ">=1.12.1"
|
20 |
+
stable-baselines3 = "1.2.0"
|
21 |
+
gymnasium = "^0.26.3"
|
22 |
+
moviepy = "^1.0.3"
|
23 |
+
pygame = "2.1.0"
|
24 |
+
huggingface-hub = "^0.11.1"
|
25 |
+
|
26 |
+
ale-py = {version = "0.7.4", optional = true}
|
27 |
+
AutoROM = {extras = ["accept-rom-license"], version = "^0.4.2"}
|
28 |
+
opencv-python = {version = "^4.6.0.66", optional = true}
|
29 |
+
pybullet = {version = "3.1.8", optional = true}
|
30 |
+
procgen = {version = "^0.10.7", optional = true}
|
31 |
+
pytest = {version = "^7.1.3", optional = true}
|
32 |
+
mujoco = {version = "^2.2", optional = true}
|
33 |
+
imageio = {version = "^2.14.1", optional = true}
|
34 |
+
free-mujoco-py = {version = "^2.1.6", optional = true}
|
35 |
+
mkdocs-material = {version = "^8.4.3", optional = true}
|
36 |
+
markdown-include = {version = "^0.7.0", optional = true}
|
37 |
+
jax = {version = "^0.3.17", optional = true}
|
38 |
+
jaxlib = {version = "^0.3.15", optional = true}
|
39 |
+
flax = {version = "^0.6.0", optional = true}
|
40 |
+
optuna = {version = "^3.0.1", optional = true}
|
41 |
+
optuna-dashboard = {version = "^0.7.2", optional = true}
|
42 |
+
rich = {version = "<12.0", optional = true}
|
43 |
+
envpool = {version = "^0.6.4", optional = true}
|
44 |
+
PettingZoo = {version = "1.18.1", optional = true}
|
45 |
+
SuperSuit = {version = "3.4.0", optional = true}
|
46 |
+
multi-agent-ale-py = {version = "0.1.11", optional = true}
|
47 |
+
boto3 = {version = "^1.24.70", optional = true}
|
48 |
+
awscli = {version = "^1.25.71", optional = true}
|
49 |
+
shimmy = {version = "^0.1.0", optional = true}
|
50 |
+
dm-control = {version = "^1.0.8", optional = true}
|
51 |
+
|
52 |
+
[tool.poetry.group.dev.dependencies]
|
53 |
+
pre-commit = "^2.20.0"
|
54 |
+
|
55 |
+
[tool.poetry.group.atari]
|
56 |
+
optional = true
|
57 |
+
[tool.poetry.group.atari.dependencies]
|
58 |
+
ale-py = "0.7.4"
|
59 |
+
AutoROM = {extras = ["accept-rom-license"], version = "^0.4.2"}
|
60 |
+
opencv-python = "^4.6.0.66"
|
61 |
+
|
62 |
+
[tool.poetry.group.pybullet]
|
63 |
+
optional = true
|
64 |
+
[tool.poetry.group.pybullet.dependencies]
|
65 |
+
pybullet = "3.1.8"
|
66 |
+
|
67 |
+
[tool.poetry.group.procgen]
|
68 |
+
optional = true
|
69 |
+
[tool.poetry.group.procgen.dependencies]
|
70 |
+
procgen = "^0.10.7"
|
71 |
+
|
72 |
+
[tool.poetry.group.pytest]
|
73 |
+
optional = true
|
74 |
+
[tool.poetry.group.pytest.dependencies]
|
75 |
+
pytest = "^7.1.3"
|
76 |
+
|
77 |
+
[tool.poetry.group.mujoco]
|
78 |
+
optional = true
|
79 |
+
[tool.poetry.group.mujoco.dependencies]
|
80 |
+
mujoco = "^2.2"
|
81 |
+
imageio = "^2.14.1"
|
82 |
+
|
83 |
+
[tool.poetry.group.mujoco_py]
|
84 |
+
optional = true
|
85 |
+
[tool.poetry.group.mujoco_py.dependencies]
|
86 |
+
free-mujoco-py = "^2.1.6"
|
87 |
+
|
88 |
+
[tool.poetry.group.docs]
|
89 |
+
optional = true
|
90 |
+
[tool.poetry.group.docs.dependencies]
|
91 |
+
mkdocs-material = "^8.4.3"
|
92 |
+
markdown-include = "^0.7.0"
|
93 |
+
|
94 |
+
[tool.poetry.group.jax]
|
95 |
+
optional = true
|
96 |
+
[tool.poetry.group.jax.dependencies]
|
97 |
+
jax = "^0.3.17"
|
98 |
+
jaxlib = "^0.3.15"
|
99 |
+
flax = "^0.6.0"
|
100 |
+
|
101 |
+
[tool.poetry.group.optuna]
|
102 |
+
optional = true
|
103 |
+
[tool.poetry.group.optuna.dependencies]
|
104 |
+
optuna = "^3.0.1"
|
105 |
+
optuna-dashboard = "^0.7.2"
|
106 |
+
rich = "<12.0"
|
107 |
+
|
108 |
+
[tool.poetry.group.envpool]
|
109 |
+
optional = true
|
110 |
+
[tool.poetry.group.envpool.dependencies]
|
111 |
+
envpool = "^0.6.4"
|
112 |
+
|
113 |
+
[tool.poetry.group.pettingzoo]
|
114 |
+
optional = true
|
115 |
+
[tool.poetry.group.pettingzoo.dependencies]
|
116 |
+
PettingZoo = "1.18.1"
|
117 |
+
SuperSuit = "3.4.0"
|
118 |
+
multi-agent-ale-py = "0.1.11"
|
119 |
+
|
120 |
+
[tool.poetry.group.cloud]
|
121 |
+
optional = true
|
122 |
+
[tool.poetry.group.cloud.dependencies]
|
123 |
+
boto3 = "^1.24.70"
|
124 |
+
awscli = "^1.25.71"
|
125 |
+
|
126 |
+
[tool.poetry.group.isaacgym]
|
127 |
+
optional = true
|
128 |
+
[tool.poetry.group.isaacgym.dependencies]
|
129 |
+
isaacgymenvs = {git = "https://github.com/vwxyzjn/IsaacGymEnvs.git", rev = "poetry"}
|
130 |
+
isaacgym = {path = "cleanrl/ppo_continuous_action_isaacgym/isaacgym", develop = true}
|
131 |
+
|
132 |
+
[tool.poetry.group.dm_control]
|
133 |
+
optional = true
|
134 |
+
[tool.poetry.group.dm_control.dependencies]
|
135 |
+
shimmy = "^0.1.0"
|
136 |
+
dm-control = "^1.0.8"
|
137 |
+
mujoco = "^2.2"
|
138 |
+
|
139 |
+
[build-system]
|
140 |
+
requires = ["poetry-core"]
|
141 |
+
build-backend = "poetry.core.masonry.api"
|
142 |
+
|
143 |
+
[tool.poetry.extras]
|
144 |
+
atari = ["ale-py", "AutoROM", "opencv-python"]
|
145 |
+
pybullet = ["pybullet"]
|
146 |
+
procgen = ["procgen"]
|
147 |
+
plot = ["pandas", "seaborn"]
|
148 |
+
spyder = ["spyder"]
|
149 |
+
pytest = ["pytest"]
|
150 |
+
mujoco = ["mujoco", "imageio"]
|
151 |
+
mujoco_py = ["free-mujoco-py"]
|
152 |
+
jax = ["jax", "jaxlib", "flax"]
|
153 |
+
docs = ["mkdocs-material", "markdown-include"]
|
154 |
+
envpool = ["envpool"]
|
155 |
+
optuna = ["optuna", "optuna-dashboard", "rich"]
|
156 |
+
pettingzoo = ["PettingZoo", "SuperSuit", "multi-agent-ale-py"]
|
157 |
+
cloud = ["boto3", "awscli"]
|
158 |
+
dm_control = ["shimmy", "dm-control", "mujoco"]
|
replay.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a51cfc3ece0e615e582459528e8fd5fa5312ee28d3f089db7f48bfd02ef0cc58
|
3 |
+
size 2537092
|
videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-0.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2d37e0e10ee88ddebddc19f642d722ca237baf5131b8d580bf8ac091c9c6a0a4
|
3 |
+
size 2281024
|
videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-1.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:af6c853db29d05f7398f59ec195f9eb747c336ea9af68eb75c12051e2630f7ed
|
3 |
+
size 3760840
|
videos/BeamRiderNoFrameskip-v4__dqn_atari_jax__1__1671134107-eval/rl-video-episode-8.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a51cfc3ece0e615e582459528e8fd5fa5312ee28d3f089db7f48bfd02ef0cc58
|
3 |
+
size 2537092
|