zhangpaipai commited on
Commit
b0c2ce8
1 Parent(s): 57baf01

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +279 -0
README.md ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - Pendulum-v1
10
+ benchmark_name: OpenAI/Gym/ClassicControl
11
+ task_name: Pendulum-v1
12
+ pipeline_tag: reinforcement-learning
13
+ model-index:
14
+ - name: DDPG
15
+ results:
16
+ - task:
17
+ type: reinforcement-learning
18
+ name: reinforcement-learning
19
+ dataset:
20
+ name: OpenAI/Gym/ClassicControl-Pendulum-v1
21
+ type: OpenAI/Gym/ClassicControl-Pendulum-v1
22
+ metrics:
23
+ - type: mean_reward
24
+ value: -162.89 +/- 144.82
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **Pendulum-v1** with **DDPG** Policy
29
+
30
+ ## Model Description
31
+ <!-- Provide a longer summary of what this model is. -->
32
+ This is a simple **DDPG** implementation to OpenAI/Gym/ClassicControl **Pendulum-v1** 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 DDPGAgent
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 = DDPGAgent(env="pendulum", exp_name="Pendulum-v1-DDPG", cfg=cfg.exp_config, policy_state_dict=policy_state_dict)
73
+ # Continue training
74
+ agent.train(step=5000)
75
+ # Render the new agent performance
76
+ agent.deploy(enable_save_replay=True)
77
+
78
+ ```
79
+ </details>
80
+
81
+ ### Run Model by Using Huggingface_ding
82
+
83
+ <details close>
84
+ <summary>(Click for Details)</summary>
85
+
86
+ ```shell
87
+ # running with trained model
88
+ python3 -u run.py
89
+ ```
90
+ **run.py**
91
+ ```python
92
+ from ding.bonus import DDPGAgent
93
+ from huggingface_ding import pull_model_from_hub
94
+
95
+ # Pull model from Hugggingface hub
96
+ policy_state_dict, cfg = pull_model_from_hub(repo_id="OpenDILabCommunity/Pendulum-v1-DDPG")
97
+ # Instantiate the agent
98
+ agent = DDPGAgent(env="pendulum", exp_name="Pendulum-v1-DDPG", cfg=cfg.exp_config, policy_state_dict=policy_state_dict)
99
+ # Continue training
100
+ agent.train(step=5000)
101
+ # Render the new agent performance
102
+ agent.deploy(enable_save_replay=True)
103
+
104
+ ```
105
+ </details>
106
+
107
+ ## Model Training
108
+
109
+ ### Train the Model and Push to Huggingface_hub
110
+
111
+ <details close>
112
+ <summary>(Click for Details)</summary>
113
+
114
+ ```shell
115
+ #Training Your Own Agent
116
+ python3 -u train.py
117
+ ```
118
+ **train.py**
119
+ ```python
120
+ from ding.bonus import DDPGAgent
121
+ from huggingface_ding import push_model_to_hub
122
+
123
+ # Instantiate the agent
124
+ agent = DDPGAgent("pendulum", exp_name="Pendulum-v1-DDPG")
125
+ # Train the agent
126
+ return_ = agent.train(step=int(4000000))
127
+ # Push model to huggingface hub
128
+ push_model_to_hub(
129
+ agent=agent.best,
130
+ env_name="OpenAI/Gym/ClassicControl",
131
+ task_name="Pendulum-v1",
132
+ algo_name="DDPG",
133
+ wandb_url=return_.wandb_url,
134
+ github_repo_url="https://github.com/opendilab/DI-engine",
135
+ github_doc_model_url="https://di-engine-docs.readthedocs.io/en/latest/12_policies/ddpg.html",
136
+ github_doc_env_url="https://di-engine-docs.readthedocs.io/en/latest/13_envs/pendulum.html",
137
+ installation_guide="pip3 install DI-engine[common_env]",
138
+ usage_file_by_git_clone="./ddpg/pendulum_ddpg_deploy.py",
139
+ usage_file_by_huggingface_ding="./ddpg/pendulum_ddpg_download.py",
140
+ train_file="./ddpg/pendulum_ddpg.py",
141
+ repo_id="OpenDILabCommunity/Pendulum-v1-DDPG"
142
+ )
143
+
144
+ ```
145
+ </details>
146
+
147
+ **Configuration**
148
+ <details close>
149
+ <summary>(Click for Details)</summary>
150
+
151
+
152
+ ```python
153
+ exp_config = {
154
+ 'env': {
155
+ 'manager': {
156
+ 'episode_num': float("inf"),
157
+ 'max_retry': 1,
158
+ 'retry_type': 'reset',
159
+ 'auto_reset': True,
160
+ 'step_timeout': None,
161
+ 'reset_timeout': None,
162
+ 'retry_waiting_time': 0.1,
163
+ 'cfg_type': 'BaseEnvManagerDict'
164
+ },
165
+ 'stop_value': -250,
166
+ 'collector_env_num': 8,
167
+ 'evaluator_env_num': 5,
168
+ 'act_scale': True,
169
+ 'n_evaluator_episode': 5
170
+ },
171
+ 'policy': {
172
+ 'model': {
173
+ 'obs_shape': 3,
174
+ 'action_shape': 1,
175
+ 'twin_critic': False,
176
+ 'action_space': 'regression'
177
+ },
178
+ 'learn': {
179
+ 'learner': {
180
+ 'train_iterations': 1000000000,
181
+ 'dataloader': {
182
+ 'num_workers': 0
183
+ },
184
+ 'log_policy': True,
185
+ 'hook': {
186
+ 'load_ckpt_before_run': '',
187
+ 'log_show_after_iter': 100,
188
+ 'save_ckpt_after_iter': 10000,
189
+ 'save_ckpt_after_run': True
190
+ },
191
+ 'cfg_type': 'BaseLearnerDict'
192
+ },
193
+ 'update_per_collect': 2,
194
+ 'batch_size': 128,
195
+ 'learning_rate_actor': 0.001,
196
+ 'learning_rate_critic': 0.001,
197
+ 'ignore_done': True,
198
+ 'target_theta': 0.005,
199
+ 'discount_factor': 0.99,
200
+ 'actor_update_freq': 1,
201
+ 'noise': False
202
+ },
203
+ 'collect': {
204
+ 'collector': {
205
+ 'collect_print_freq': 1000
206
+ },
207
+ 'unroll_len': 1,
208
+ 'noise_sigma': 0.1,
209
+ 'n_sample': 48
210
+ },
211
+ 'eval': {
212
+ 'evaluator': {
213
+ 'eval_freq': 100,
214
+ 'render': {
215
+ 'render_freq': -1,
216
+ 'mode': 'train_iter'
217
+ },
218
+ 'cfg_type': 'InteractionSerialEvaluatorDict',
219
+ 'n_episode': 5,
220
+ 'stop_value': -250
221
+ }
222
+ },
223
+ 'other': {
224
+ 'replay_buffer': {
225
+ 'replay_buffer_size': 20000,
226
+ 'max_use': 16
227
+ }
228
+ },
229
+ 'on_policy': False,
230
+ 'cuda': False,
231
+ 'multi_gpu': False,
232
+ 'bp_update_sync': True,
233
+ 'traj_len_inf': False,
234
+ 'type': 'ddpg',
235
+ 'priority': False,
236
+ 'priority_IS_weight': False,
237
+ 'random_collect_size': 800,
238
+ 'transition_with_policy_data': False,
239
+ 'action_space': 'continuous',
240
+ 'reward_batch_norm': False,
241
+ 'multi_agent': False,
242
+ 'cfg_type': 'DDPGPolicyDict'
243
+ },
244
+ 'exp_name': 'Pendulum-v1-DDPG',
245
+ 'seed': 0,
246
+ 'wandb_logger': {
247
+ 'gradient_logger': True,
248
+ 'video_logger': True,
249
+ 'plot_logger': True,
250
+ 'action_logger': True,
251
+ 'return_logger': False
252
+ }
253
+ }
254
+
255
+ ```
256
+ </details>
257
+
258
+ **Training Procedure**
259
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
260
+ - **Weights & Biases (wandb):** [monitor link](https://wandb.ai/zhangpaipai/Pendulum-v1-DDPG)
261
+
262
+ ## Model Information
263
+ <!-- Provide the basic links for the model. -->
264
+ - **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
265
+ - **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/ddpg.html)
266
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/Pendulum-v1-DDPG/blob/main/policy_config.py)
267
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/Pendulum-v1-DDPG/blob/main/replay.mp4)
268
+ <!-- Provide the size information for the model. -->
269
+ - **Parameters total size:** 35.26 KB
270
+ - **Last Update Date:** 2023-04-29
271
+
272
+ ## Environments
273
+ <!-- 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. -->
274
+ - **Benchmark:** OpenAI/Gym/ClassicControl
275
+ - **Task:** Pendulum-v1
276
+ - **Gym version:** 0.25.1
277
+ - **DI-engine version:** v0.4.7
278
+ - **PyTorch version:** 1.7.1
279
+ - **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/pendulum.html)