zhangpaipai commited on
Commit
db592e6
1 Parent(s): f77ce07

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +319 -0
README.md ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - HalfCheetah-v3
10
+ benchmark_name: OpenAI/Gym/MuJoCo
11
+ task_name: HalfCheetah-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-HalfCheetah-v3
21
+ type: OpenAI/Gym/MuJoCo-HalfCheetah-v3
22
+ metrics:
23
+ - type: mean_reward
24
+ value: 12055.93 +/- 76.91
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **HalfCheetah-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 **HalfCheetah-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="HalfCheetah", exp_name="HalfCheetah-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/HalfCheetah-v3-SAC")
106
+ # Instantiate the agent
107
+ agent = SACAgent(env="HalfCheetah", exp_name="HalfCheetah-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="HalfCheetah", exp_name="HalfCheetah-v3-SAC")
134
+ # Train the agent
135
+ return_ = agent.train(step=int(5000000))
136
+ # Push model to huggingface hub
137
+ push_model_to_hub(
138
+ agent=agent.best,
139
+ env_name="OpenAI/Gym/MuJoCo",
140
+ task_name="HalfCheetah-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/halfcheetah_sac_deploy.py",
170
+ usage_file_by_huggingface_ding="./sac/halfcheetah_sac_download.py",
171
+ train_file="./sac/halfcheetah_sac.py",
172
+ repo_id="OpenDILabCommunity/HalfCheetah-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': 12000,
197
+ 'env_id': 'HalfCheetah-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
+ 'twin_critic': True,
211
+ 'action_space': 'reparameterization',
212
+ 'obs_shape': 17,
213
+ 'action_shape': 6,
214
+ 'actor_head_hidden_size': 256,
215
+ 'critic_head_hidden_size': 256
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_q': 0.001,
235
+ 'learning_rate_policy': 0.001,
236
+ 'learning_rate_alpha': 0.0003,
237
+ 'target_theta': 0.005,
238
+ 'discount_factor': 0.99,
239
+ 'alpha': 0.2,
240
+ 'auto_alpha': False,
241
+ 'log_space': True,
242
+ 'target_entropy': None,
243
+ 'ignore_done': True,
244
+ 'init_w': 0.003,
245
+ 'reparameterization': True
246
+ },
247
+ 'collect': {
248
+ 'collector': {},
249
+ 'n_sample': 1,
250
+ 'unroll_len': 1,
251
+ 'collector_logit': False
252
+ },
253
+ 'eval': {
254
+ 'evaluator': {
255
+ 'eval_freq': 1000,
256
+ 'render': {
257
+ 'render_freq': -1,
258
+ 'mode': 'train_iter'
259
+ },
260
+ 'cfg_type': 'InteractionSerialEvaluatorDict',
261
+ 'n_episode': 8,
262
+ 'stop_value': 12000
263
+ }
264
+ },
265
+ 'other': {
266
+ 'replay_buffer': {
267
+ 'replay_buffer_size': 1000000
268
+ }
269
+ },
270
+ 'on_policy': False,
271
+ 'cuda': False,
272
+ 'multi_gpu': False,
273
+ 'bp_update_sync': True,
274
+ 'traj_len_inf': False,
275
+ 'type': 'sac',
276
+ 'priority': False,
277
+ 'priority_IS_weight': False,
278
+ 'random_collect_size': 10000,
279
+ 'transition_with_policy_data': True,
280
+ 'multi_agent': False,
281
+ 'cfg_type': 'SACPolicyDict',
282
+ 'command': {}
283
+ },
284
+ 'exp_name': 'HalfCheetah-v3-SAC',
285
+ 'seed': 0,
286
+ 'wandb_logger': {
287
+ 'gradient_logger': True,
288
+ 'video_logger': True,
289
+ 'plot_logger': True,
290
+ 'action_logger': True,
291
+ 'return_logger': False
292
+ }
293
+ }
294
+
295
+ ```
296
+ </details>
297
+
298
+ **Training Procedure**
299
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
300
+ - **Weights & Biases (wandb):** [monitor link](https://wandb.ai/zhangpaipai/HalfCheetah-v3-SAC)
301
+
302
+ ## Model Information
303
+ <!-- Provide the basic links for the model. -->
304
+ - **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
305
+ - **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/sac.html)
306
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/HalfCheetah-v3-SAC/blob/main/policy_config.py)
307
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/HalfCheetah-v3-SAC/blob/main/replay.mp4)
308
+ <!-- Provide the size information for the model. -->
309
+ - **Parameters total size:** 851.05 KB
310
+ - **Last Update Date:** 2023-04-15
311
+
312
+ ## Environments
313
+ <!-- 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. -->
314
+ - **Benchmark:** OpenAI/Gym/MuJoCo
315
+ - **Task:** HalfCheetah-v3
316
+ - **Gym version:** 0.25.1
317
+ - **DI-engine version:** v0.4.7
318
+ - **PyTorch version:** 1.7.1
319
+ - **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/mujoco.html)