zjowowen commited on
Commit
cd3306a
1 Parent(s): d423cab

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +281 -0
README.md ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: A2C
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: 277.68 +/- 0.19
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **BipedalWalker-v3** with **A2C** Policy
29
+
30
+ ## Model Description
31
+ <!-- Provide a longer summary of what this model is. -->
32
+ This is a simple **A2C** 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 A2CAgent
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 = A2CAgent(
73
+ env="bipedalwalker", exp_name="BipedalWalker-v3-A2C", 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 A2CAgent
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-A2C")
99
+ # Instantiate the agent
100
+ agent = A2CAgent(
101
+ env="bipedalwalker",
102
+ exp_name="BipedalWalker-v3-A2C",
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 A2CAgent
128
+ from huggingface_ding import push_model_to_hub
129
+
130
+ # Instantiate the agent
131
+ agent = A2CAgent("bipedalwalker", exp_name="BipedalWalker-v3-A2C")
132
+ # Train the agent
133
+ return_ = agent.train(step=int(5000000))
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="A2C",
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/a2c.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="./a2c/bipedalwalker_a2c_deploy.py",
146
+ usage_file_by_huggingface_ding="./a2c/bipedalwalker_a2c_download.py",
147
+ train_file="./a2c/bipedalwalker_a2c.py",
148
+ repo_id="OpenDILabCommunity/BipedalWalker-v3-A2C"
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': 8,
174
+ 'env_id': 'BipedalWalker-v3',
175
+ 'collector_env_num': 8,
176
+ 'evaluator_env_num': 8,
177
+ 'act_scale': True,
178
+ 'rew_clip': True
179
+ },
180
+ 'policy': {
181
+ 'model': {
182
+ 'action_space': 'continuous',
183
+ 'obs_shape': 24,
184
+ 'action_shape': 4
185
+ },
186
+ 'learn': {
187
+ 'learner': {
188
+ 'train_iterations': 1000000000,
189
+ 'dataloader': {
190
+ 'num_workers': 0
191
+ },
192
+ 'log_policy': True,
193
+ 'hook': {
194
+ 'load_ckpt_before_run': '',
195
+ 'log_show_after_iter': 100,
196
+ 'save_ckpt_after_iter': 10000,
197
+ 'save_ckpt_after_run': True
198
+ },
199
+ 'cfg_type': 'BaseLearnerDict'
200
+ },
201
+ 'update_per_collect': 1,
202
+ 'batch_size': 64,
203
+ 'learning_rate': 0.0003,
204
+ 'betas': [0.9, 0.999],
205
+ 'eps': 1e-08,
206
+ 'grad_norm': 0.5,
207
+ 'value_weight': 0.7,
208
+ 'entropy_weight': 0.0005,
209
+ 'adv_norm': True,
210
+ 'ignore_done': False,
211
+ 'discount_factor': 0.99
212
+ },
213
+ 'collect': {
214
+ 'collector': {},
215
+ 'unroll_len': 1,
216
+ 'discount_factor': 0.99,
217
+ 'gae_lambda': 0.95,
218
+ 'n_sample': 64
219
+ },
220
+ 'eval': {
221
+ 'evaluator': {
222
+ 'eval_freq': 1000,
223
+ 'render': {
224
+ 'render_freq': -1,
225
+ 'mode': 'train_iter'
226
+ },
227
+ 'cfg_type': 'InteractionSerialEvaluatorDict',
228
+ 'stop_value': 10000000000,
229
+ 'n_episode': 8
230
+ }
231
+ },
232
+ 'other': {
233
+ 'replay_buffer': {}
234
+ },
235
+ 'on_policy': True,
236
+ 'cuda': True,
237
+ 'multi_gpu': False,
238
+ 'bp_update_sync': True,
239
+ 'traj_len_inf': False,
240
+ 'type': 'a2c',
241
+ 'priority': False,
242
+ 'priority_IS_weight': False,
243
+ 'action_space': 'continuous',
244
+ 'cfg_type': 'A2CPolicyDict'
245
+ },
246
+ 'exp_name': 'BipedalWalker-v3-A2C',
247
+ 'seed': 0,
248
+ 'wandb_logger': {
249
+ 'gradient_logger': True,
250
+ 'video_logger': True,
251
+ 'plot_logger': True,
252
+ 'action_logger': True,
253
+ 'return_logger': False
254
+ }
255
+ }
256
+
257
+ ```
258
+ </details>
259
+
260
+ **Training Procedure**
261
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
262
+ - **Weights & Biases (wandb):** [monitor link](https://wandb.ai/zjowowen/BipedalWalker-v3-A2C)
263
+
264
+ ## Model Information
265
+ <!-- Provide the basic links for the model. -->
266
+ - **Github Repository:** [repo link](https://github.com/opendilab/DI-engine)
267
+ - **Doc**: [DI-engine-docs Algorithm link](https://di-engine-docs.readthedocs.io/en/latest/12_policies/a2c.html)
268
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/BipedalWalker-v3-A2C/blob/main/policy_config.py)
269
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/BipedalWalker-v3-A2C/blob/main/replay.mp4)
270
+ <!-- Provide the size information for the model. -->
271
+ - **Parameters total size:** 395.32 KB
272
+ - **Last Update Date:** 2023-06-06
273
+
274
+ ## Environments
275
+ <!-- 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. -->
276
+ - **Benchmark:** OpenAI/Gym/Box2d
277
+ - **Task:** BipedalWalker-v3
278
+ - **Gym version:** 0.25.1
279
+ - **DI-engine version:** v0.4.8
280
+ - **PyTorch version:** 1.7.1
281
+ - **Doc**: [DI-engine-docs Environments link](https://di-engine-docs.readthedocs.io/en/latest/13_envs/bipedalwalker.html)