Aron751 commited on
Commit
bae8660
1 Parent(s): f3d07eb

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +267 -0
README.md ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - Pong-v4
10
+ benchmark_name: OpenAI/Gym/Atari
11
+ task_name: Pong-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-Pong-v4
21
+ type: OpenAI/Gym/Atari-Pong-v4
22
+ metrics:
23
+ - type: mean_reward
24
+ value: 19.0 +/- 1.87
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **Pong-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 **Pong-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="Pong", exp_name="Pong-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
+ # [More Information Needed]
95
+ ```
96
+ </details>
97
+
98
+ ## Model Training
99
+
100
+ ### Train the Model and Push to Huggingface_hub
101
+
102
+ <details close>
103
+ <summary>(Click for Details)</summary>
104
+
105
+ ```shell
106
+ #Training Your Own Agent
107
+ python3 -u train.py
108
+ ```
109
+ **train.py**
110
+ ```python
111
+ from ding.bonus import DQNAgent
112
+ from huggingface_ding import push_model_to_hub
113
+
114
+ # Instantiate the agent
115
+ agent = DQNAgent(env="Pong", exp_name="Pong-v4-DQN")
116
+ # Train the agent
117
+ return_ = agent.train(step=int(40000000000), collector_env_num=8, evaluator_env_num=8, debug=False)
118
+ print("-----wandb url is----:", return_.wandb_url)
119
+ # Push model to huggingface hub
120
+ push_model_to_hub(
121
+ agent=agent.best,
122
+ env_name="OpenAI/Gym/Atari",
123
+ task_name="Pong-v4",
124
+ algo_name="DQN",
125
+ wandb_url=return_.wandb_url,
126
+ github_repo_url="https://github.com/opendilab/DI-engine",
127
+ github_doc_model_url="https://di-engine-docs.readthedocs.io/en/latest/12_policies/dqn.html",
128
+ github_doc_env_url="https://di-engine-docs.readthedocs.io/en/latest/13_envs/atari.html",
129
+ installation_guide="pip3 install DI-engine[common_env]",
130
+ usage_file_by_git_clone="./dqn/pong_dqn_deploy.py",
131
+ usage_file_by_huggingface_ding="./dqn/pong_dqn_download.py",
132
+ train_file="./dqn/pong_dqn.py",
133
+ repo_id="OpenDILabCommunity/Pong-v4-DQN"
134
+ )
135
+
136
+ ```
137
+ </details>
138
+
139
+ **Configuration**
140
+ <details close>
141
+ <summary>(Click for Details)</summary>
142
+
143
+
144
+ ```python
145
+ exp_config = {
146
+ 'env': {
147
+ 'manager': {
148
+ 'episode_num': float("inf"),
149
+ 'max_retry': 1,
150
+ 'retry_type': 'reset',
151
+ 'auto_reset': True,
152
+ 'step_timeout': None,
153
+ 'reset_timeout': None,
154
+ 'retry_waiting_time': 0.1,
155
+ 'cfg_type': 'BaseEnvManagerDict'
156
+ },
157
+ 'stop_value': 20,
158
+ 'env_id': 'Pong-v4',
159
+ 'collector_env_num': 8,
160
+ 'evaluator_env_num': 8,
161
+ 'n_evaluator_episode': 8,
162
+ 'fram_stack': 4
163
+ },
164
+ 'policy': {
165
+ 'model': {
166
+ 'encoder_hidden_size_list': [128, 128, 512],
167
+ 'obs_shape': [4, 84, 84],
168
+ 'action_shape': 6
169
+ },
170
+ 'learn': {
171
+ 'learner': {
172
+ 'train_iterations': 1000000000,
173
+ 'dataloader': {
174
+ 'num_workers': 0
175
+ },
176
+ 'log_policy': True,
177
+ 'hook': {
178
+ 'load_ckpt_before_run': '',
179
+ 'log_show_after_iter': 100,
180
+ 'save_ckpt_after_iter': 10000,
181
+ 'save_ckpt_after_run': True
182
+ },
183
+ 'cfg_type': 'BaseLearnerDict'
184
+ },
185
+ 'update_per_collect': 10,
186
+ 'batch_size': 32,
187
+ 'learning_rate': 0.0001,
188
+ 'target_update_freq': 500,
189
+ 'target_theta': 0.005,
190
+ 'ignore_done': False
191
+ },
192
+ 'collect': {
193
+ 'collector': {},
194
+ 'n_sample': 96,
195
+ 'unroll_len': 1
196
+ },
197
+ 'eval': {
198
+ 'evaluator': {
199
+ 'eval_freq': 1000,
200
+ 'render': {
201
+ 'render_freq': -1,
202
+ 'mode': 'train_iter'
203
+ },
204
+ 'cfg_type': 'InteractionSerialEvaluatorDict',
205
+ 'n_episode': 8,
206
+ 'stop_value': 20
207
+ }
208
+ },
209
+ 'other': {
210
+ 'replay_buffer': {
211
+ 'replay_buffer_size': 100000
212
+ },
213
+ 'eps': {
214
+ 'type': 'exp',
215
+ 'start': 1.0,
216
+ 'end': 0.05,
217
+ 'decay': 250000
218
+ }
219
+ },
220
+ 'on_policy': False,
221
+ 'cuda': True,
222
+ 'multi_gpu': False,
223
+ 'bp_update_sync': True,
224
+ 'traj_len_inf': False,
225
+ 'type': 'dqn',
226
+ 'priority': False,
227
+ 'priority_IS_weight': False,
228
+ 'discount_factor': 0.99,
229
+ 'nstep': 3,
230
+ 'cfg_type': 'DQNPolicyDict'
231
+ },
232
+ 'exp_name': 'Pong-v4-DQN',
233
+ 'seed': 0,
234
+ 'wandb_logger': {
235
+ 'gradient_logger': True,
236
+ 'video_logger': True,
237
+ 'plot_logger': True,
238
+ 'action_logger': True,
239
+ 'return_logger': False
240
+ }
241
+ }
242
+
243
+ ```
244
+ </details>
245
+
246
+ **Training Procedure**
247
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
248
+ - **Weights & Biases (wandb):** [monitor link](https://wandb.ai/ruoyugao/Pong-v4-DQN)
249
+
250
+ ## Model Information
251
+ <!-- Provide the basic links for the model. -->
252
+ - **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
253
+ - **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/dqn.html)
254
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/Pong-v4-DQN/blob/main/policy_config.py)
255
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/Pong-v4-DQN/blob/main/replay.mp4)
256
+ <!-- Provide the size information for the model. -->
257
+ - **Parameters total size:** 55703.03 KB
258
+ - **Last Update Date:** 2023-04-24
259
+
260
+ ## Environments
261
+ <!-- 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. -->
262
+ - **Benchmark:** OpenAI/Gym/Atari
263
+ - **Task:** Pong-v4
264
+ - **Gym version:** 0.25.1
265
+ - **DI-engine version:** v0.4.7
266
+ - **PyTorch version:** 1.7.1
267
+ - **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/atari.html)