zhangpaipai commited on
Commit
d0efe67
1 Parent(s): 222856b

Upload README.md with huggingface_hub

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