Aron751 commited on
Commit
ec72e79
1 Parent(s): 0db42ef

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +234 -0
README.md ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: PPO
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: 1569.47 +/- 83.96
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **HalfCheetah-v3** with **PPO** Policy
29
+
30
+ ## Model Description
31
+ <!-- Provide a longer summary of what this model is. -->
32
+ This is a simple **PPO** 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 PPOF
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 = PPOF(env="HalfCheetah", exp_name="HalfCheetah-v3-PPO", 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 PPOF
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-PPO")
106
+ # Instantiate the agent
107
+ agent = PPOF(env="HalfCheetah", exp_name="HalfCheetah-v3-PPO", 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 PPOF
130
+ from huggingface_ding import push_model_to_hub
131
+
132
+ # Instantiate the agent
133
+ agent = PPOF(env="HalfCheetah", exp_name="HalfCheetah-v3-PPO")
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="HalfCheetah-v3",
141
+ algo_name="PPO",
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/ppo.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="./ppo/halfcheetah_ppo_deploy.py",
170
+ usage_file_by_huggingface_ding="./ppo/halfcheetah_ppo_download.py",
171
+ train_file="./ppo/halfcheetah_ppo.py",
172
+ repo_id="OpenDILabCommunity/HalfCheetah-v3-PPO"
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
+ 'type': 'ppo',
186
+ 'on_policy': True,
187
+ 'cuda': True,
188
+ 'action_space': 'continuous',
189
+ 'discount_factor': 0.99,
190
+ 'gae_lambda': 0.95,
191
+ 'epoch_per_collect': 10,
192
+ 'batch_size': 320,
193
+ 'learning_rate': 0.0003,
194
+ 'lr_scheduler': None,
195
+ 'weight_decay': 0,
196
+ 'value_weight': 0.5,
197
+ 'entropy_weight': 0.01,
198
+ 'clip_ratio': 0.2,
199
+ 'adv_norm': True,
200
+ 'value_norm': 'baseline',
201
+ 'ppo_param_init': True,
202
+ 'grad_norm': 0.5,
203
+ 'n_sample': 3200,
204
+ 'unroll_len': 1,
205
+ 'deterministic_eval': True,
206
+ 'model': {},
207
+ 'cfg_type': 'PPOFPolicyDict'
208
+ }
209
+
210
+ ```
211
+ </details>
212
+
213
+ **Training Procedure**
214
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
215
+ - **Weights & Biases (wandb):** [monitor link](https://wandb.ai/ruoyugao/HalfCheetah-v3-PPO)
216
+
217
+ ## Model Information
218
+ <!-- Provide the basic links for the model. -->
219
+ - **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
220
+ - **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/ppo.html)
221
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/HalfCheetah-v3-PPO/blob/main/policy_config.py)
222
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/HalfCheetah-v3-PPO/blob/main/replay.mp4)
223
+ <!-- Provide the size information for the model. -->
224
+ - **Parameters total size:** 385.85 KB
225
+ - **Last Update Date:** 2023-06-14
226
+
227
+ ## Environments
228
+ <!-- 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. -->
229
+ - **Benchmark:** OpenAI/Gym/MuJoCo
230
+ - **Task:** HalfCheetah-v3
231
+ - **Gym version:** 0.25.1
232
+ - **DI-engine version:** v0.4.8
233
+ - **PyTorch version:** 1.7.1
234
+ - **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/mujoco.html)