zjowowen commited on
Commit
17d5595
1 Parent(s): 67928f7

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +312 -0
README.md ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: SAC
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: 4279.46 +/- 47.85
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **Hopper-v3** with **SAC** Policy
29
+
30
+ ## Model Description
31
+ <!-- Provide a longer summary of what this model is. -->
32
+ This is a simple **SAC** 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 SACAgent
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 = SACAgent(env="hopper", exp_name="Hopper-v3-SAC", 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 SACAgent
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-SAC")
106
+ # Instantiate the agent
107
+ agent = SACAgent(env="hopper", exp_name="Hopper-v3-SAC", 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.sac import SACAgent
130
+ from huggingface_ding import push_model_to_hub
131
+
132
+ # Instantiate the agent
133
+ agent = SACAgent(env="hopper", exp_name="Hopper-v3-SAC")
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="SAC",
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/sac.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="./sac/hopper_sac_deploy.py",
170
+ usage_file_by_huggingface_ding="./sac/hopper_sac_download.py",
171
+ train_file="./sac/hopper_sac.py",
172
+ repo_id="OpenDILabCommunity/Hopper-v3-SAC"
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
+ 'collector_env_num': 8,
199
+ 'evaluator_env_num': 8,
200
+ 'n_evaluator_episode': 8
201
+ },
202
+ 'policy': {
203
+ 'model': {
204
+ 'twin_critic': True,
205
+ 'action_space': 'reparameterization',
206
+ 'obs_shape': 11,
207
+ 'action_shape': 3,
208
+ 'actor_head_hidden_size': 256,
209
+ 'critic_head_hidden_size': 256
210
+ },
211
+ 'learn': {
212
+ 'learner': {
213
+ 'train_iterations': 1000000000,
214
+ 'dataloader': {
215
+ 'num_workers': 0
216
+ },
217
+ 'log_policy': True,
218
+ 'hook': {
219
+ 'load_ckpt_before_run': '',
220
+ 'log_show_after_iter': 100,
221
+ 'save_ckpt_after_iter': 10000,
222
+ 'save_ckpt_after_run': True
223
+ },
224
+ 'cfg_type': 'BaseLearnerDict'
225
+ },
226
+ 'update_per_collect': 1,
227
+ 'batch_size': 256,
228
+ 'learning_rate_q': 0.001,
229
+ 'learning_rate_policy': 0.001,
230
+ 'learning_rate_alpha': 0.0003,
231
+ 'target_theta': 0.005,
232
+ 'discount_factor': 0.99,
233
+ 'alpha': 0.2,
234
+ 'auto_alpha': False,
235
+ 'log_space': True,
236
+ 'target_entropy': None,
237
+ 'ignore_done': False,
238
+ 'init_w': 0.003,
239
+ 'reparameterization': True
240
+ },
241
+ 'collect': {
242
+ 'collector': {},
243
+ 'n_sample': 1,
244
+ 'unroll_len': 1,
245
+ 'collector_logit': False
246
+ },
247
+ 'eval': {
248
+ 'evaluator': {
249
+ 'eval_freq': 1000,
250
+ 'render': {
251
+ 'render_freq': -1,
252
+ 'mode': 'train_iter'
253
+ },
254
+ 'cfg_type': 'InteractionSerialEvaluatorDict',
255
+ 'n_episode': 8,
256
+ 'stop_value': 6000
257
+ }
258
+ },
259
+ 'other': {
260
+ 'replay_buffer': {
261
+ 'replay_buffer_size': 1000000
262
+ }
263
+ },
264
+ 'on_policy': False,
265
+ 'cuda': True,
266
+ 'multi_gpu': False,
267
+ 'bp_update_sync': True,
268
+ 'traj_len_inf': False,
269
+ 'type': 'sac',
270
+ 'priority': False,
271
+ 'priority_IS_weight': False,
272
+ 'random_collect_size': 10000,
273
+ 'transition_with_policy_data': True,
274
+ 'multi_agent': False,
275
+ 'cfg_type': 'SACPolicyDict'
276
+ },
277
+ 'exp_name': 'Hopper-v3-SAC',
278
+ 'seed': 0,
279
+ 'wandb_logger': {
280
+ 'gradient_logger': True,
281
+ 'video_logger': True,
282
+ 'plot_logger': True,
283
+ 'action_logger': True,
284
+ 'return_logger': False
285
+ }
286
+ }
287
+
288
+ ```
289
+ </details>
290
+
291
+ **Training Procedure**
292
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
293
+ - **Weights & Biases (wandb):** [monitor link](https://wandb.ai/zjowowen/Hopper-v3-SAC)
294
+
295
+ ## Model Information
296
+ <!-- Provide the basic links for the model. -->
297
+ - **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
298
+ - **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/sac.html)
299
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/Hopper-v3-SAC/blob/main/policy_config.py)
300
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/Hopper-v3-SAC/blob/main/replay.mp4)
301
+ <!-- Provide the size information for the model. -->
302
+ - **Parameters total size:** 821.03 KB
303
+ - **Last Update Date:** 2023-04-14
304
+
305
+ ## Environments
306
+ <!-- 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. -->
307
+ - **Benchmark:** OpenAI/Gym/MuJoCo
308
+ - **Task:** Hopper-v3
309
+ - **Gym version:** 0.25.1
310
+ - **DI-engine version:** v0.4.7
311
+ - **PyTorch version:** 1.7.1
312
+ - **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/mujoco.html)