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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 |
+
- PongNoFrameskip-v4
|
10 |
+
benchmark_name: OpenAI/Gym/Atari
|
11 |
+
task_name: PongNoFrameskip-v4
|
12 |
+
pipeline_tag: reinforcement-learning
|
13 |
+
model-index:
|
14 |
+
- name: C51
|
15 |
+
results:
|
16 |
+
- task:
|
17 |
+
type: reinforcement-learning
|
18 |
+
name: reinforcement-learning
|
19 |
+
dataset:
|
20 |
+
name: OpenAI/Gym/Atari-PongNoFrameskip-v4
|
21 |
+
type: OpenAI/Gym/Atari-PongNoFrameskip-v4
|
22 |
+
metrics:
|
23 |
+
- type: mean_reward
|
24 |
+
value: 20.25 +/- 0.83
|
25 |
+
name: mean_reward
|
26 |
+
---
|
27 |
+
|
28 |
+
# Play **PongNoFrameskip-v4** with **C51** Policy
|
29 |
+
|
30 |
+
## Model Description
|
31 |
+
<!-- Provide a longer summary of what this model is. -->
|
32 |
+
This is a simple **C51** implementation to OpenAI/Gym/Atari **PongNoFrameskip-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 C51Agent
|
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 = C51Agent(
|
73 |
+
env="PongNoFrameskip", exp_name="PongNoFrameskip-v4-C51", 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 C51Agent
|
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/PongNoFrameskip-v4-C51")
|
99 |
+
# Instantiate the agent
|
100 |
+
agent = C51Agent(
|
101 |
+
env="PongNoFrameskip", exp_name="PongNoFrameskip-v4-C51", 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 C51Agent
|
125 |
+
from huggingface_ding import push_model_to_hub
|
126 |
+
|
127 |
+
# Instantiate the agent
|
128 |
+
agent = C51Agent(env="PongNoFrameskip", exp_name="PongNoFrameskip-v4-C51")
|
129 |
+
# Train the agent
|
130 |
+
return_ = agent.train(step=int(20000000))
|
131 |
+
# Push model to huggingface hub
|
132 |
+
push_model_to_hub(
|
133 |
+
agent=agent.best,
|
134 |
+
env_name="OpenAI/Gym/Atari",
|
135 |
+
task_name="PongNoFrameskip-v4",
|
136 |
+
algo_name="C51",
|
137 |
+
wandb_url=return_.wandb_url,
|
138 |
+
github_repo_url="https://github.com/opendilab/DI-engine",
|
139 |
+
github_doc_model_url="https://di-engine-docs.readthedocs.io/en/latest/12_policies/c51.html",
|
140 |
+
github_doc_env_url="https://di-engine-docs.readthedocs.io/en/latest/13_envs/atari.html",
|
141 |
+
installation_guide="pip3 install DI-engine[common_env]",
|
142 |
+
usage_file_by_git_clone="./c51/pong_c51_deploy.py",
|
143 |
+
usage_file_by_huggingface_ding="./c51/pong_c51_download.py",
|
144 |
+
train_file="./c51/pong_c51.py",
|
145 |
+
repo_id="OpenDILabCommunity/PongNoFrameskip-v4-C51"
|
146 |
+
)
|
147 |
+
|
148 |
+
```
|
149 |
+
</details>
|
150 |
+
|
151 |
+
**Configuration**
|
152 |
+
<details close>
|
153 |
+
<summary>(Click for Details)</summary>
|
154 |
+
|
155 |
+
|
156 |
+
```python
|
157 |
+
exp_config = {
|
158 |
+
'env': {
|
159 |
+
'manager': {
|
160 |
+
'episode_num': float("inf"),
|
161 |
+
'max_retry': 1,
|
162 |
+
'retry_type': 'reset',
|
163 |
+
'auto_reset': True,
|
164 |
+
'step_timeout': None,
|
165 |
+
'reset_timeout': None,
|
166 |
+
'retry_waiting_time': 0.1,
|
167 |
+
'cfg_type': 'BaseEnvManagerDict'
|
168 |
+
},
|
169 |
+
'stop_value': 20,
|
170 |
+
'n_evaluator_episode': 8,
|
171 |
+
'collector_env_num': 8,
|
172 |
+
'evaluator_env_num': 8,
|
173 |
+
'env_id': 'PongNoFrameskip-v4',
|
174 |
+
'frame_stack': 4
|
175 |
+
},
|
176 |
+
'policy': {
|
177 |
+
'model': {
|
178 |
+
'encoder_hidden_size_list': [128, 128, 512],
|
179 |
+
'v_min': -10,
|
180 |
+
'v_max': 10,
|
181 |
+
'n_atom': 51,
|
182 |
+
'obs_shape': [4, 84, 84],
|
183 |
+
'action_shape': 6
|
184 |
+
},
|
185 |
+
'learn': {
|
186 |
+
'learner': {
|
187 |
+
'train_iterations': 1000000000,
|
188 |
+
'dataloader': {
|
189 |
+
'num_workers': 0
|
190 |
+
},
|
191 |
+
'log_policy': True,
|
192 |
+
'hook': {
|
193 |
+
'load_ckpt_before_run': '',
|
194 |
+
'log_show_after_iter': 100,
|
195 |
+
'save_ckpt_after_iter': 10000,
|
196 |
+
'save_ckpt_after_run': True
|
197 |
+
},
|
198 |
+
'cfg_type': 'BaseLearnerDict'
|
199 |
+
},
|
200 |
+
'update_per_collect': 10,
|
201 |
+
'batch_size': 32,
|
202 |
+
'learning_rate': 0.0001,
|
203 |
+
'target_update_freq': 500,
|
204 |
+
'target_theta': 0.005,
|
205 |
+
'ignore_done': False
|
206 |
+
},
|
207 |
+
'collect': {
|
208 |
+
'collector': {},
|
209 |
+
'n_sample': 100,
|
210 |
+
'unroll_len': 1
|
211 |
+
},
|
212 |
+
'eval': {
|
213 |
+
'evaluator': {
|
214 |
+
'eval_freq': 4000,
|
215 |
+
'render': {
|
216 |
+
'render_freq': -1,
|
217 |
+
'mode': 'train_iter'
|
218 |
+
},
|
219 |
+
'cfg_type': 'InteractionSerialEvaluatorDict',
|
220 |
+
'stop_value': 20,
|
221 |
+
'n_episode': 8
|
222 |
+
}
|
223 |
+
},
|
224 |
+
'other': {
|
225 |
+
'replay_buffer': {
|
226 |
+
'replay_buffer_size': 100000
|
227 |
+
},
|
228 |
+
'eps': {
|
229 |
+
'type': 'exp',
|
230 |
+
'start': 1.0,
|
231 |
+
'end': 0.05,
|
232 |
+
'decay': 250000
|
233 |
+
}
|
234 |
+
},
|
235 |
+
'on_policy': False,
|
236 |
+
'cuda': True,
|
237 |
+
'multi_gpu': False,
|
238 |
+
'bp_update_sync': True,
|
239 |
+
'traj_len_inf': False,
|
240 |
+
'type': 'c51',
|
241 |
+
'priority': False,
|
242 |
+
'priority_IS_weight': False,
|
243 |
+
'discount_factor': 0.99,
|
244 |
+
'nstep': 3,
|
245 |
+
'cfg_type': 'C51PolicyDict'
|
246 |
+
},
|
247 |
+
'exp_name': 'PongNoFrameskip-v4-C51',
|
248 |
+
'seed': 0,
|
249 |
+
'wandb_logger': {
|
250 |
+
'gradient_logger': True,
|
251 |
+
'video_logger': True,
|
252 |
+
'plot_logger': True,
|
253 |
+
'action_logger': True,
|
254 |
+
'return_logger': False
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
```
|
259 |
+
</details>
|
260 |
+
|
261 |
+
**Training Procedure**
|
262 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
263 |
+
- **Weights & Biases (wandb):** [monitor link](https://wandb.ai/zjowowen/PongNoFrameskip-v4-C51)
|
264 |
+
|
265 |
+
## Model Information
|
266 |
+
<!-- Provide the basic links for the model. -->
|
267 |
+
- **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
|
268 |
+
- **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/c51.html)
|
269 |
+
- **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/PongNoFrameskip-v4-C51/blob/main/policy_config.py)
|
270 |
+
- **Demo:** [video](https://huggingface.co/OpenDILabCommunity/PongNoFrameskip-v4-C51/blob/main/replay.mp4)
|
271 |
+
<!-- Provide the size information for the model. -->
|
272 |
+
- **Parameters total size:** 55276.2 KB
|
273 |
+
- **Last Update Date:** 2023-05-18
|
274 |
+
|
275 |
+
## Environments
|
276 |
+
<!-- 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. -->
|
277 |
+
- **Benchmark:** OpenAI/Gym/Atari
|
278 |
+
- **Task:** PongNoFrameskip-v4
|
279 |
+
- **Gym version:** 0.25.1
|
280 |
+
- **DI-engine version:** v0.4.7
|
281 |
+
- **PyTorch version:** 1.7.1
|
282 |
+
- **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/atari.html)
|