zjowowen commited on
Commit
9f723d8
1 Parent(s): b416270

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +303 -0
README.md ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - Pendulum-v1
10
+ benchmark_name: OpenAI/Gym/Box2d
11
+ task_name: Pendulum-v1
12
+ pipeline_tag: reinforcement-learning
13
+ model-index:
14
+ - name: EfficientZero
15
+ results:
16
+ - task:
17
+ type: reinforcement-learning
18
+ name: reinforcement-learning
19
+ dataset:
20
+ name: Pendulum-v1
21
+ type: Pendulum-v1
22
+ metrics:
23
+ - type: mean_reward
24
+ value: -143.67 +/- 103.49
25
+ name: mean_reward
26
+ ---
27
+
28
+ # Play **Pendulum-v1** with **EfficientZero** Policy
29
+
30
+ ## Model Description
31
+ <!-- Provide a longer summary of what this model is. -->
32
+
33
+ This implementation applies **EfficientZero** to the OpenAI/Gym/Box2d **Pendulum-v1** environment using [LightZero](https://github.com/opendilab/LightZero) and [DI-engine](https://github.com/opendilab/di-engine).
34
+
35
+ **LightZero** is an efficient, easy-to-understand open-source toolkit that merges Monte Carlo Tree Search (MCTS) with Deep Reinforcement Learning (RL), simplifying their integration for developers and researchers. More details are in paper [LightZero: A Unified Benchmark for Monte Carlo Tree Search in General Sequential Decision Scenarios](https://huggingface.co/papers/2310.08348).
36
+
37
+ ## Model Usage
38
+ ### Install the Dependencies
39
+ <details close>
40
+ <summary>(Click for Details)</summary>
41
+
42
+ ```shell
43
+ # install huggingface_ding
44
+ git clone https://github.com/opendilab/huggingface_ding.git
45
+ pip3 install -e ./huggingface_ding/
46
+ # install environment dependencies if needed
47
+
48
+ pip3 install DI-engine[common_env,video]
49
+ pip3 install LightZero
50
+
51
+ ```
52
+ </details>
53
+
54
+ ### Git Clone from Huggingface and Run the Model
55
+
56
+ <details close>
57
+ <summary>(Click for Details)</summary>
58
+
59
+ ```shell
60
+ # running with trained model
61
+ python3 -u run.py
62
+ ```
63
+ **run.py**
64
+ ```python
65
+ from lzero.agent import EfficientZeroAgent
66
+ from ding.config import Config
67
+ from easydict import EasyDict
68
+ import torch
69
+
70
+ # Pull model from files which are git cloned from huggingface
71
+ policy_state_dict = torch.load("pytorch_model.bin", map_location=torch.device("cpu"))
72
+ cfg = EasyDict(Config.file_to_dict("policy_config.py").cfg_dict)
73
+ # Instantiate the agent
74
+ agent = EfficientZeroAgent(
75
+ env_id="Pendulum-v1", exp_name="Pendulum-v1-EfficientZero", cfg=cfg.exp_config, policy_state_dict=policy_state_dict
76
+ )
77
+ # Continue training
78
+ agent.train(step=5000)
79
+ # Render the new agent performance
80
+ agent.deploy(enable_save_replay=True)
81
+
82
+ ```
83
+ </details>
84
+
85
+ ### Run Model by Using Huggingface_ding
86
+
87
+ <details close>
88
+ <summary>(Click for Details)</summary>
89
+
90
+ ```shell
91
+ # running with trained model
92
+ python3 -u run.py
93
+ ```
94
+ **run.py**
95
+ ```python
96
+ from lzero.agent import EfficientZeroAgent
97
+ from huggingface_ding import pull_model_from_hub
98
+
99
+ # Pull model from Hugggingface hub
100
+ policy_state_dict, cfg = pull_model_from_hub(repo_id="OpenDILabCommunity/Pendulum-v1-EfficientZero")
101
+ # Instantiate the agent
102
+ agent = EfficientZeroAgent(
103
+ env_id="Pendulum-v1", exp_name="Pendulum-v1-EfficientZero", cfg=cfg.exp_config, policy_state_dict=policy_state_dict
104
+ )
105
+ # Continue training
106
+ agent.train(step=5000)
107
+ # Render the new agent performance
108
+ agent.deploy(enable_save_replay=True)
109
+
110
+ ```
111
+ </details>
112
+
113
+ ## Model Training
114
+
115
+ ### Train the Model and Push to Huggingface_hub
116
+
117
+ <details close>
118
+ <summary>(Click for Details)</summary>
119
+
120
+ ```shell
121
+ #Training Your Own Agent
122
+ python3 -u train.py
123
+ ```
124
+ **train.py**
125
+ ```python
126
+ from lzero.agent import EfficientZeroAgent
127
+ from huggingface_ding import push_model_to_hub
128
+
129
+ # Instantiate the agent
130
+ agent = EfficientZeroAgent(env_id="Pendulum-v1", exp_name="Pendulum-v1-EfficientZero")
131
+ # Train the agent
132
+ return_ = agent.train(step=int(500000))
133
+ # Push model to huggingface hub
134
+ push_model_to_hub(
135
+ agent=agent.best,
136
+ env_name="OpenAI/Gym/Box2d",
137
+ task_name="Pendulum-v1",
138
+ algo_name="EfficientZero",
139
+ github_repo_url="https://github.com/opendilab/LightZero",
140
+ github_doc_model_url=None,
141
+ github_doc_env_url=None,
142
+ installation_guide='''
143
+ pip3 install DI-engine[common_env,video]
144
+ pip3 install LightZero
145
+ ''',
146
+ usage_file_by_git_clone="./efficientzero/pendulum_efficientzero_deploy.py",
147
+ usage_file_by_huggingface_ding="./efficientzero/pendulum_efficientzero_download.py",
148
+ train_file="./efficientzero/pendulum_efficientzero.py",
149
+ repo_id="OpenDILabCommunity/Pendulum-v1-EfficientZero",
150
+ platform_info="[LightZero](https://github.com/opendilab/LightZero) and [DI-engine](https://github.com/opendilab/di-engine)",
151
+ model_description="**LightZero** is an efficient, easy-to-understand open-source toolkit that merges Monte Carlo Tree Search (MCTS) with Deep Reinforcement Learning (RL), simplifying their integration for developers and researchers. More details are in paper [LightZero: A Unified Benchmark for Monte Carlo Tree Search in General Sequential Decision Scenarios](https://huggingface.co/papers/2310.08348).",
152
+ create_repo=True
153
+ )
154
+
155
+ ```
156
+ </details>
157
+
158
+ **Configuration**
159
+ <details close>
160
+ <summary>(Click for Details)</summary>
161
+
162
+
163
+ ```python
164
+ exp_config = {
165
+ 'main_config': {
166
+ 'exp_name': 'Pendulum-v1-EfficientZero',
167
+ 'seed': 0,
168
+ 'env': {
169
+ 'env_id': 'Pendulum-v1',
170
+ 'continuous': False,
171
+ 'manually_discretization': True,
172
+ 'each_dim_disc_size': 11,
173
+ 'collector_env_num': 8,
174
+ 'evaluator_env_num': 3,
175
+ 'n_evaluator_episode': 3,
176
+ 'manager': {
177
+ 'shared_memory': False
178
+ }
179
+ },
180
+ 'policy': {
181
+ 'on_policy': False,
182
+ 'cuda': True,
183
+ 'multi_gpu': False,
184
+ 'bp_update_sync': True,
185
+ 'traj_len_inf': False,
186
+ 'model': {
187
+ 'observation_shape': 3,
188
+ 'action_space_size': 11,
189
+ 'model_type': 'mlp',
190
+ 'lstm_hidden_size': 128,
191
+ 'latent_state_dim': 128
192
+ },
193
+ 'use_rnd_model': False,
194
+ 'sampled_algo': False,
195
+ 'gumbel_algo': False,
196
+ 'mcts_ctree': True,
197
+ 'collector_env_num': 8,
198
+ 'evaluator_env_num': 3,
199
+ 'env_type': 'not_board_games',
200
+ 'action_type': 'fixed_action_space',
201
+ 'battle_mode': 'play_with_bot_mode',
202
+ 'monitor_extra_statistics': True,
203
+ 'game_segment_length': 50,
204
+ 'transform2string': False,
205
+ 'gray_scale': False,
206
+ 'use_augmentation': False,
207
+ 'augmentation': ['shift', 'intensity'],
208
+ 'ignore_done': False,
209
+ 'update_per_collect': 200,
210
+ 'model_update_ratio': 0.1,
211
+ 'batch_size': 256,
212
+ 'optim_type': 'Adam',
213
+ 'learning_rate': 0.003,
214
+ 'target_update_freq': 100,
215
+ 'target_update_freq_for_intrinsic_reward': 1000,
216
+ 'weight_decay': 0.0001,
217
+ 'momentum': 0.9,
218
+ 'grad_clip_value': 10,
219
+ 'n_episode': 8,
220
+ 'num_simulations': 50,
221
+ 'discount_factor': 0.997,
222
+ 'td_steps': 5,
223
+ 'num_unroll_steps': 5,
224
+ 'reward_loss_weight': 1,
225
+ 'value_loss_weight': 0.25,
226
+ 'policy_loss_weight': 1,
227
+ 'policy_entropy_loss_weight': 0,
228
+ 'ssl_loss_weight': 2,
229
+ 'lr_piecewise_constant_decay': False,
230
+ 'threshold_training_steps_for_final_lr': 50000,
231
+ 'manual_temperature_decay': False,
232
+ 'threshold_training_steps_for_final_temperature': 100000,
233
+ 'fixed_temperature_value': 0.25,
234
+ 'use_ture_chance_label_in_chance_encoder': False,
235
+ 'use_priority': True,
236
+ 'priority_prob_alpha': 0.6,
237
+ 'priority_prob_beta': 0.4,
238
+ 'root_dirichlet_alpha': 0.3,
239
+ 'root_noise_weight': 0.25,
240
+ 'random_collect_episode_num': 0,
241
+ 'eps': {
242
+ 'eps_greedy_exploration_in_collect': False,
243
+ 'type': 'linear',
244
+ 'start': 1.0,
245
+ 'end': 0.05,
246
+ 'decay': 100000
247
+ },
248
+ 'cfg_type': 'EfficientZeroPolicyDict',
249
+ 'lstm_horizon_len': 5,
250
+ 'reanalyze_ratio': 0,
251
+ 'eval_freq': 2000,
252
+ 'replay_buffer_size': 1000000
253
+ },
254
+ 'wandb_logger': {
255
+ 'gradient_logger': False,
256
+ 'video_logger': False,
257
+ 'plot_logger': False,
258
+ 'action_logger': False,
259
+ 'return_logger': False
260
+ }
261
+ },
262
+ 'create_config': {
263
+ 'env': {
264
+ 'type':
265
+ 'pendulum_lightzero',
266
+ 'import_names':
267
+ ['zoo.classic_control.pendulum.envs.pendulum_lightzero_env']
268
+ },
269
+ 'env_manager': {
270
+ 'type': 'subprocess'
271
+ },
272
+ 'policy': {
273
+ 'type': 'efficientzero',
274
+ 'import_names': ['lzero.policy.efficientzero']
275
+ }
276
+ }
277
+ }
278
+
279
+ ```
280
+ </details>
281
+
282
+ **Training Procedure**
283
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
284
+ - **Weights & Biases (wandb):** [monitor link](<TODO>)
285
+
286
+ ## Model Information
287
+ <!-- Provide the basic links for the model. -->
288
+ - **Github Repository:** [repo link](https://github.com/opendilab/LightZero)
289
+ - **Doc**: [Algorithm link](<TODO>)
290
+ - **Configuration:** [config link](https://huggingface.co/OpenDILabCommunity/Pendulum-v1-EfficientZero/blob/main/policy_config.py)
291
+ - **Demo:** [video](https://huggingface.co/OpenDILabCommunity/Pendulum-v1-EfficientZero/blob/main/replay.mp4)
292
+ <!-- Provide the size information for the model. -->
293
+ - **Parameters total size:** 14069.29 KB
294
+ - **Last Update Date:** 2024-01-03
295
+
296
+ ## Environments
297
+ <!-- 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. -->
298
+ - **Benchmark:** OpenAI/Gym/Box2d
299
+ - **Task:** Pendulum-v1
300
+ - **Gym version:** 0.25.1
301
+ - **DI-engine version:** v0.5.0
302
+ - **PyTorch version:** 2.0.1+cu117
303
+ - **Doc**: [Environments link](<TODO>)