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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
license: apache-2.0
|
4 |
+
library_name: pytorch
|
5 |
+
tags:
|
6 |
+
- deep-reinforcement-learning
|
7 |
+
- reinforcement-learning
|
8 |
+
- DI-engine
|
9 |
+
- SpaceInvadersNoFrameskip-v4
|
10 |
+
benchmark_name: OpenAI/Gym/Atari
|
11 |
+
task_name: SpaceInvadersNoFrameskip-v4
|
12 |
+
pipeline_tag: reinforcement-learning
|
13 |
+
model-index:
|
14 |
+
- name: DQN
|
15 |
+
results:
|
16 |
+
- task:
|
17 |
+
type: reinforcement-learning
|
18 |
+
name: reinforcement-learning
|
19 |
+
dataset:
|
20 |
+
name: OpenAI/Gym/Atari-SpaceInvadersNoFrameskip-v4
|
21 |
+
type: OpenAI/Gym/Atari-SpaceInvadersNoFrameskip-v4
|
22 |
+
metrics:
|
23 |
+
- type: mean_reward
|
24 |
+
value: 1481.25 +/- 237.47
|
25 |
+
name: mean_reward
|
26 |
+
---
|
27 |
+
|
28 |
+
# Play **SpaceInvadersNoFrameskip-v4** with **DQN** Policy
|
29 |
+
|
30 |
+
## Model Description
|
31 |
+
<!-- Provide a longer summary of what this model is. -->
|
32 |
+
This is a simple **DQN** implementation to OpenAI/Gym/Atari **SpaceInvadersNoFrameskip-v4** using the [DI-engine library](https://github.com/opendilab/di-engine) and the [DI-zoo](https://github.com/opendilab/DI-engine/tree/main/dizoo).
|
33 |
+
|
34 |
+
**DI-engine** is a python library for solving general decision intelligence problems, which is based on implementations of reinforcement learning framework using PyTorch or JAX. This library aims to standardize the reinforcement learning framework across different algorithms, benchmarks, environments, and to support both academic researches and prototype applications. Besides, self-customized training pipelines and applications are supported by reusing different abstraction levels of DI-engine reinforcement learning framework.
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
## Model Usage
|
39 |
+
### Install the Dependencies
|
40 |
+
<details close>
|
41 |
+
<summary>(Click for Details)</summary>
|
42 |
+
|
43 |
+
```shell
|
44 |
+
# install huggingface_ding
|
45 |
+
git clone https://github.com/opendilab/huggingface_ding.git
|
46 |
+
pip3 install -e ./huggingface_ding/
|
47 |
+
# install environment dependencies if needed
|
48 |
+
pip3 install DI-engine[common_env]
|
49 |
+
```
|
50 |
+
</details>
|
51 |
+
|
52 |
+
### Git Clone from Huggingface and Run the Model
|
53 |
+
|
54 |
+
<details close>
|
55 |
+
<summary>(Click for Details)</summary>
|
56 |
+
|
57 |
+
```shell
|
58 |
+
# running with trained model
|
59 |
+
python3 -u run.py
|
60 |
+
```
|
61 |
+
**run.py**
|
62 |
+
```python
|
63 |
+
from ding.bonus import DQNAgent
|
64 |
+
from ding.config import Config
|
65 |
+
from easydict import EasyDict
|
66 |
+
import torch
|
67 |
+
|
68 |
+
# Pull model from files which are git cloned from huggingface
|
69 |
+
policy_state_dict = torch.load("pytorch_model.bin", map_location=torch.device("cpu"))
|
70 |
+
cfg = EasyDict(Config.file_to_dict("policy_config.py"))
|
71 |
+
# Instantiate the agent
|
72 |
+
agent = DQNAgent(
|
73 |
+
env="SpaceInvadersNoFrameskip", exp_name="SpaceInvadersNoFrameskip-v4-DQN", cfg=cfg.exp_config, policy_state_dict=policy_state_dict
|
74 |
+
)
|
75 |
+
# Continue training
|
76 |
+
agent.train(step=5000)
|
77 |
+
# Render the new agent performance
|
78 |
+
agent.deploy(enable_save_replay=True)
|
79 |
+
|
80 |
+
```
|
81 |
+
</details>
|
82 |
+
|
83 |
+
### Run Model by Using Huggingface_ding
|
84 |
+
|
85 |
+
<details close>
|
86 |
+
<summary>(Click for Details)</summary>
|
87 |
+
|
88 |
+
```shell
|
89 |
+
# running with trained model
|
90 |
+
python3 -u run.py
|
91 |
+
```
|
92 |
+
**run.py**
|
93 |
+
```python
|
94 |
+
from ding.bonus import DQNAgent
|
95 |
+
from huggingface_ding import pull_model_from_hub
|
96 |
+
|
97 |
+
# Pull model from Hugggingface hub
|
98 |
+
policy_state_dict, cfg = pull_model_from_hub(repo_id="OpenDILabCommunity/SpaceInvadersNoFrameskip-v4-DQN")
|
99 |
+
# Instantiate the agent
|
100 |
+
agent = DQNAgent(
|
101 |
+
env="SpaceInvadersNoFrameskip", exp_name="SpaceInvadersNoFrameskip-v4-DQN", cfg=cfg.exp_config, policy_state_dict=policy_state_dict
|
102 |
+
)
|
103 |
+
# Continue training
|
104 |
+
agent.train(step=5000)
|
105 |
+
# Render the new agent performance
|
106 |
+
agent.deploy(enable_save_replay=True)
|
107 |
+
|
108 |
+
```
|
109 |
+
</details>
|
110 |
+
|
111 |
+
## Model Training
|
112 |
+
|
113 |
+
### Train the Model and Push to Huggingface_hub
|
114 |
+
|
115 |
+
<details close>
|
116 |
+
<summary>(Click for Details)</summary>
|
117 |
+
|
118 |
+
```shell
|
119 |
+
#Training Your Own Agent
|
120 |
+
python3 -u train.py
|
121 |
+
```
|
122 |
+
**train.py**
|
123 |
+
```python
|
124 |
+
from ding.bonus import DQNAgent
|
125 |
+
from huggingface_ding import push_model_to_hub
|
126 |
+
|
127 |
+
# Instantiate the agent
|
128 |
+
agent = DQNAgent(env="SpaceInvadersNoFrameskip", exp_name="SpaceInvadersNoFrameskip-v4-DQN")
|
129 |
+
# Train the agent
|
130 |
+
return_ = agent.train(step=int(20000000), collector_env_num=8, evaluator_env_num=8, debug=False)
|
131 |
+
print("-----wandb url is----:", return_.wandb_url)
|
132 |
+
# Push model to huggingface hub
|
133 |
+
push_model_to_hub(
|
134 |
+
agent=agent.best,
|
135 |
+
env_name="OpenAI/Gym/Atari",
|
136 |
+
task_name="SpaceInvadersNoFrameskip-v4",
|
137 |
+
algo_name="DQN",
|
138 |
+
wandb_url=return_.wandb_url,
|
139 |
+
github_repo_url="https://github.com/opendilab/DI-engine",
|
140 |
+
github_doc_model_url="https://di-engine-docs.readthedocs.io/en/latest/12_policies/dqn.html",
|
141 |
+
github_doc_env_url="https://di-engine-docs.readthedocs.io/en/latest/13_envs/atari.html",
|
142 |
+
installation_guide="pip3 install DI-engine[common_env]",
|
143 |
+
usage_file_by_git_clone="./dqn/spaceinvaders_dqn_deploy.py",
|
144 |
+
usage_file_by_huggingface_ding="./dqn/spaceinvaders_dqn_download.py",
|
145 |
+
train_file="./dqn/spaceinvaders_dqn.py",
|
146 |
+
repo_id="OpenDILabCommunity/SpaceInvadersNoFrameskip-v4-DQN"
|
147 |
+
)
|
148 |
+
|
149 |
+
```
|
150 |
+
</details>
|
151 |
+
|
152 |
+
**Configuration**
|
153 |
+
<details close>
|
154 |
+
<summary>(Click for Details)</summary>
|
155 |
+
|
156 |
+
|
157 |
+
```python
|
158 |
+
exp_config = {
|
159 |
+
'env': {
|
160 |
+
'manager': {
|
161 |
+
'episode_num': float("inf"),
|
162 |
+
'max_retry': 1,
|
163 |
+
'retry_type': 'reset',
|
164 |
+
'auto_reset': True,
|
165 |
+
'step_timeout': None,
|
166 |
+
'reset_timeout': None,
|
167 |
+
'retry_waiting_time': 0.1,
|
168 |
+
'cfg_type': 'BaseEnvManagerDict'
|
169 |
+
},
|
170 |
+
'stop_value': 2000,
|
171 |
+
'n_evaluator_episode': 8,
|
172 |
+
'env_id': 'SpaceInvadersNoFrameskip-v4',
|
173 |
+
'collector_env_num': 8,
|
174 |
+
'evaluator_env_num': 8,
|
175 |
+
'fram_stack': 4
|
176 |
+
},
|
177 |
+
'policy': {
|
178 |
+
'model': {
|
179 |
+
'encoder_hidden_size_list': [128, 128, 512],
|
180 |
+
'obs_shape': [4, 84, 84],
|
181 |
+
'action_shape': 6
|
182 |
+
},
|
183 |
+
'learn': {
|
184 |
+
'learner': {
|
185 |
+
'train_iterations': 1000000000,
|
186 |
+
'dataloader': {
|
187 |
+
'num_workers': 0
|
188 |
+
},
|
189 |
+
'log_policy': True,
|
190 |
+
'hook': {
|
191 |
+
'load_ckpt_before_run': '',
|
192 |
+
'log_show_after_iter': 100,
|
193 |
+
'save_ckpt_after_iter': 10000,
|
194 |
+
'save_ckpt_after_run': True
|
195 |
+
},
|
196 |
+
'cfg_type': 'BaseLearnerDict'
|
197 |
+
},
|
198 |
+
'update_per_collect': 10,
|
199 |
+
'batch_size': 32,
|
200 |
+
'learning_rate': 0.0001,
|
201 |
+
'target_update_freq': 500,
|
202 |
+
'target_theta': 0.005,
|
203 |
+
'ignore_done': False,
|
204 |
+
'hook': {
|
205 |
+
'save_ckpt_after_iter': 1000000
|
206 |
+
}
|
207 |
+
},
|
208 |
+
'collect': {
|
209 |
+
'collector': {},
|
210 |
+
'n_sample': 100,
|
211 |
+
'unroll_len': 1
|
212 |
+
},
|
213 |
+
'eval': {
|
214 |
+
'evaluator': {
|
215 |
+
'eval_freq': 1000,
|
216 |
+
'render': {
|
217 |
+
'render_freq': -1,
|
218 |
+
'mode': 'train_iter'
|
219 |
+
},
|
220 |
+
'cfg_type': 'InteractionSerialEvaluatorDict',
|
221 |
+
'stop_value': 2000,
|
222 |
+
'n_episode': 8
|
223 |
+
}
|
224 |
+
},
|
225 |
+
'other': {
|
226 |
+
'replay_buffer': {
|
227 |
+
'replay_buffer_size': 400000
|
228 |
+
},
|
229 |
+
'eps': {
|
230 |
+
'type': 'exp',
|
231 |
+
'start': 1.0,
|
232 |
+
'end': 0.05,
|
233 |
+
'decay': 1000000
|
234 |
+
}
|
235 |
+
},
|
236 |
+
'on_policy': False,
|
237 |
+
'cuda': True,
|
238 |
+
'multi_gpu': False,
|
239 |
+
'bp_update_sync': True,
|
240 |
+
'traj_len_inf': False,
|
241 |
+
'type': 'dqn',
|
242 |
+
'priority': False,
|
243 |
+
'priority_IS_weight': False,
|
244 |
+
'discount_factor': 0.99,
|
245 |
+
'nstep': 3,
|
246 |
+
'cfg_type': 'DQNPolicyDict'
|
247 |
+
},
|
248 |
+
'exp_name': 'SpaceInvadersNoFrameskip-v4-DQN',
|
249 |
+
'seed': 0,
|
250 |
+
'wandb_logger': {
|
251 |
+
'gradient_logger': True,
|
252 |
+
'video_logger': True,
|
253 |
+
'plot_logger': True,
|
254 |
+
'action_logger': True,
|
255 |
+
'return_logger': False
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
```
|
260 |
+
</details>
|
261 |
+
|
262 |
+
**Training Procedure**
|
263 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
264 |
+
- **Weights & Biases (wandb):** [monitor link](https://wandb.ai/zhangpaipai/SpaceInvadersNoFrameskip-v4-DQN)
|
265 |
+
|
266 |
+
## Model Information
|
267 |
+
<!-- Provide the basic links for the model. -->
|
268 |
+
- **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
|
269 |
+
- **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/dqn.html)
|
270 |
+
- **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/SpaceInvadersNoFrameskip-v4-DQN/blob/main/policy_config.py)
|
271 |
+
- **Demo:** [video](https://huggingface.co/OpenDILabCommunity/SpaceInvadersNoFrameskip-v4-DQN/blob/main/replay.mp4)
|
272 |
+
<!-- Provide the size information for the model. -->
|
273 |
+
- **Parameters total size:** 55703.03 KB
|
274 |
+
- **Last Update Date:** 2023-05-20
|
275 |
+
|
276 |
+
## Environments
|
277 |
+
<!-- Address questions around what environment the model is intended to be trained and deployed at, including the necessary information needed to be provided for future users. -->
|
278 |
+
- **Benchmark:** OpenAI/Gym/Atari
|
279 |
+
- **Task:** SpaceInvadersNoFrameskip-v4
|
280 |
+
- **Gym version:** 0.25.1
|
281 |
+
- **DI-engine version:** v0.4.7
|
282 |
+
- **PyTorch version:** 1.7.1
|
283 |
+
- **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/atari.html)
|