zjowowen commited on
Commit
c092c2a
1 Parent(s): ed99602

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +308 -0
README.md ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - Hopper-v3
10
+ benchmark_name: OpenAI/Gym/MuJoCo
11
+ task_name: Hopper-v3
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/MuJoCo-Hopper-v3
21
+ type: OpenAI/Gym/MuJoCo-Hopper-v3
22
+ metrics:
23
+ - type: mean_reward
24
+ value: 3061.47 +/- 1031.42
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **Hopper-v3** 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/MuJoCo **Hopper-v3** 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
+
49
+ sudo apt update -y && sudo apt install -y build-essential libgl1-mesa-dev libgl1-mesa-glx libglew-dev libosmesa6-dev libglfw3 libglfw3-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-dev patchelf
50
+
51
+ mkdir -p ~/.mujoco
52
+ wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz -O mujoco.tar.gz
53
+ tar -xf mujoco.tar.gz -C ~/.mujoco
54
+ echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin" >> ~/.bashrc
55
+ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin
56
+ pip3 install DI-engine[common_env]
57
+
58
+ ```
59
+ </details>
60
+
61
+ ### Git Clone from Huggingface and Run the Model
62
+
63
+ <details close>
64
+ <summary>(Click for Details)</summary>
65
+
66
+ ```shell
67
+ # running with trained model
68
+ python3 -u run.py
69
+ ```
70
+ **run.py**
71
+ ```python
72
+ from ding.bonus import DDPGAgent
73
+ from ding.config import Config
74
+ from easydict import EasyDict
75
+ import torch
76
+
77
+ # Pull model from files which are git cloned from huggingface
78
+ policy_state_dict = torch.load("pytorch_model.bin", map_location=torch.device("cpu"))
79
+ cfg = EasyDict(Config.file_to_dict("policy_config.py"))
80
+ # Instantiate the agent
81
+ agent = DDPGAgent(env="hopper", exp_name="Hopper-v3-DDPG", cfg=cfg.exp_config, policy_state_dict=policy_state_dict)
82
+ # Continue training
83
+ agent.train(step=5000)
84
+ # Render the new agent performance
85
+ agent.deploy(enable_save_replay=True)
86
+
87
+ ```
88
+ </details>
89
+
90
+ ### Run Model by Using Huggingface_ding
91
+
92
+ <details close>
93
+ <summary>(Click for Details)</summary>
94
+
95
+ ```shell
96
+ # running with trained model
97
+ python3 -u run.py
98
+ ```
99
+ **run.py**
100
+ ```python
101
+ from ding.bonus import DDPGAgent
102
+ from huggingface_ding import pull_model_from_hub
103
+
104
+ # Pull model from Hugggingface hub
105
+ policy_state_dict, cfg = pull_model_from_hub(repo_id="OpenDILabCommunity/Hopper-v3-DDPG")
106
+ # Instantiate the agent
107
+ agent = DDPGAgent(env="hopper", exp_name="Hopper-v3-DDPG", cfg=cfg.exp_config, policy_state_dict=policy_state_dict)
108
+ # Continue training
109
+ agent.train(step=5000)
110
+ # Render the new agent performance
111
+ agent.deploy(enable_save_replay=True)
112
+
113
+ ```
114
+ </details>
115
+
116
+ ## Model Training
117
+
118
+ ### Train the Model and Push to Huggingface_hub
119
+
120
+ <details close>
121
+ <summary>(Click for Details)</summary>
122
+
123
+ ```shell
124
+ #Training Your Own Agent
125
+ python3 -u train.py
126
+ ```
127
+ **train.py**
128
+ ```python
129
+ from ding.bonus import DDPGAgent
130
+ from huggingface_ding import push_model_to_hub
131
+
132
+ # Instantiate the agent
133
+ agent = DDPGAgent(env="hopper", exp_name="Hopper-v3-DDPG")
134
+ # Train the agent
135
+ return_ = agent.train(step=int(10000000), collector_env_num=4, evaluator_env_num=4, debug=False)
136
+ # Push model to huggingface hub
137
+ push_model_to_hub(
138
+ agent=agent.best,
139
+ env_name="OpenAI/Gym/MuJoCo",
140
+ task_name="Hopper-v3",
141
+ algo_name="DDPG",
142
+ wandb_url=return_.wandb_url,
143
+ github_repo_url="https://github.com/opendilab/DI-engine",
144
+ github_doc_model_url="https://di-engine-docs.readthedocs.io/en/latest/12_policies/ddpg.html",
145
+ github_doc_env_url="https://di-engine-docs.readthedocs.io/en/latest/13_envs/mujoco.html",
146
+ installation_guide='''
147
+ sudo apt update -y \
148
+ && sudo apt install -y \
149
+ build-essential \
150
+ libgl1-mesa-dev \
151
+ libgl1-mesa-glx \
152
+ libglew-dev \
153
+ libosmesa6-dev \
154
+ libglfw3 \
155
+ libglfw3-dev \
156
+ libsdl2-dev \
157
+ libsdl2-image-dev \
158
+ libglm-dev \
159
+ libfreetype6-dev \
160
+ patchelf
161
+
162
+ mkdir -p ~/.mujoco
163
+ wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz -O mujoco.tar.gz
164
+ tar -xf mujoco.tar.gz -C ~/.mujoco
165
+ echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin" >> ~/.bashrc
166
+ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin
167
+ pip3 install DI-engine[common_env]
168
+ ''',
169
+ usage_file_by_git_clone="./ddpg/hopper_ddpg_deploy.py",
170
+ usage_file_by_huggingface_ding="./ddpg/hopper_ddpg_download.py",
171
+ train_file="./ddpg/hopper_ddpg.py",
172
+ repo_id="OpenDILabCommunity/Hopper-v3-DDPG"
173
+ )
174
+
175
+ ```
176
+ </details>
177
+
178
+ **Configuration**
179
+ <details close>
180
+ <summary>(Click for Details)</summary>
181
+
182
+
183
+ ```python
184
+ exp_config = {
185
+ 'env': {
186
+ 'manager': {
187
+ 'episode_num': float("inf"),
188
+ 'max_retry': 1,
189
+ 'retry_type': 'reset',
190
+ 'auto_reset': True,
191
+ 'step_timeout': None,
192
+ 'reset_timeout': None,
193
+ 'retry_waiting_time': 0.1,
194
+ 'cfg_type': 'BaseEnvManagerDict'
195
+ },
196
+ 'stop_value': 6000,
197
+ 'env_id': 'Hopper-v3',
198
+ 'norm_obs': {
199
+ 'use_norm': False
200
+ },
201
+ 'norm_reward': {
202
+ 'use_norm': False
203
+ },
204
+ 'collector_env_num': 1,
205
+ 'evaluator_env_num': 8,
206
+ 'n_evaluator_episode': 8
207
+ },
208
+ 'policy': {
209
+ 'model': {
210
+ 'obs_shape': 11,
211
+ 'action_shape': 3,
212
+ 'twin_critic': False,
213
+ 'actor_head_hidden_size': 256,
214
+ 'critic_head_hidden_size': 256,
215
+ 'action_space': 'regression'
216
+ },
217
+ 'learn': {
218
+ 'learner': {
219
+ 'train_iterations': 1000000000,
220
+ 'dataloader': {
221
+ 'num_workers': 0
222
+ },
223
+ 'log_policy': True,
224
+ 'hook': {
225
+ 'load_ckpt_before_run': '',
226
+ 'log_show_after_iter': 100,
227
+ 'save_ckpt_after_iter': 10000,
228
+ 'save_ckpt_after_run': True
229
+ },
230
+ 'cfg_type': 'BaseLearnerDict'
231
+ },
232
+ 'update_per_collect': 1,
233
+ 'batch_size': 256,
234
+ 'learning_rate_actor': 0.001,
235
+ 'learning_rate_critic': 0.001,
236
+ 'ignore_done': False,
237
+ 'target_theta': 0.005,
238
+ 'discount_factor': 0.99,
239
+ 'actor_update_freq': 1,
240
+ 'noise': False
241
+ },
242
+ 'collect': {
243
+ 'collector': {},
244
+ 'unroll_len': 1,
245
+ 'noise_sigma': 0.1,
246
+ 'n_sample': 1
247
+ },
248
+ 'eval': {
249
+ 'evaluator': {
250
+ 'eval_freq': 5000,
251
+ 'render': {
252
+ 'render_freq': -1,
253
+ 'mode': 'train_iter'
254
+ },
255
+ 'cfg_type': 'InteractionSerialEvaluatorDict',
256
+ 'n_episode': 8,
257
+ 'stop_value': 6000
258
+ }
259
+ },
260
+ 'other': {
261
+ 'replay_buffer': {
262
+ 'replay_buffer_size': 1000000
263
+ }
264
+ },
265
+ 'on_policy': False,
266
+ 'cuda': True,
267
+ 'multi_gpu': False,
268
+ 'bp_update_sync': True,
269
+ 'traj_len_inf': False,
270
+ 'type': 'ddpg',
271
+ 'priority': False,
272
+ 'priority_IS_weight': False,
273
+ 'random_collect_size': 25000,
274
+ 'transition_with_policy_data': False,
275
+ 'action_space': 'continuous',
276
+ 'reward_batch_norm': False,
277
+ 'multi_agent': False,
278
+ 'cfg_type': 'DDPGPolicyDict'
279
+ },
280
+ 'exp_name': 'Hopper-v3-DDPG',
281
+ 'seed': 0
282
+ }
283
+
284
+ ```
285
+ </details>
286
+
287
+ **Training Procedure**
288
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
289
+ - **Weights & Biases (wandb):** [monitor link](https://wandb.ai/zjowowen/Hopper-v3-DDPG)
290
+
291
+ ## Model Information
292
+ <!-- Provide the basic links for the model. -->
293
+ - **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
294
+ - **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/ddpg.html)
295
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/Hopper-v3-DDPG/blob/main/policy_config.py)
296
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/Hopper-v3-DDPG/blob/main/replay.mp4)
297
+ <!-- Provide the size information for the model. -->
298
+ - **Parameters total size:** 545.02 KB
299
+ - **Last Update Date:** 2023-04-19
300
+
301
+ ## Environments
302
+ <!-- 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. -->
303
+ - **Benchmark:** OpenAI/Gym/MuJoCo
304
+ - **Task:** Hopper-v3
305
+ - **Gym version:** 0.25.1
306
+ - **DI-engine version:** v0.4.7
307
+ - **PyTorch version:** 1.7.1
308
+ - **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/mujoco.html)