Views
No views yet
1# install huggingface_ding
2git clone https://github.com/opendilab/huggingface_ding.git
3pip3 install -e ./huggingface_ding/
4# install environment dependencies if needed
5pip3 install DI-engine[common_env]1# running with trained model
2python3 -u run.py1from ding.bonus import DDPGAgent
2from ding.config import Config
3from easydict import EasyDict
4import torch
5
6# Pull model from files which are git cloned from huggingface
7policy_state_dict = torch.load("pytorch_model.bin", map_location=torch.device("cpu"))
8cfg = EasyDict(Config.file_to_dict("policy_config.py").cfg_dict)
9# Instantiate the agent
10agent = DDPGAgent(
11 env_id="LunarLanderContinuous-v2",
12 exp_name="LunarLander-v2-DDPG",
13 cfg=cfg.exp_config,
14 policy_state_dict=policy_state_dict
15)
16# Continue training
17agent.train(step=5000)
18# Render the new agent performance
19agent.deploy(enable_save_replay=True)
201# running with trained model
2python3 -u run.py1from ding.bonus import DDPGAgent
2from huggingface_ding import pull_model_from_hub
3
4# Pull model from Hugggingface hub
5policy_state_dict, cfg = pull_model_from_hub(repo_id="OpenDILabCommunity/LunarLander-v2-DDPG")
6# Instantiate the agent
7agent = DDPGAgent(
8 env_id="LunarLanderContinuous-v2",
9 exp_name="LunarLander-v2-DDPG",
10 cfg=cfg.exp_config,
11 policy_state_dict=policy_state_dict
12)
13# Continue training
14agent.train(step=5000)
15# Render the new agent performance
16agent.deploy(enable_save_replay=True)
171#Training Your Own Agent
2python3 -u train.py1from ding.bonus import DDPGAgent
2from huggingface_ding import push_model_to_hub
3
4# Instantiate the agent
5agent = DDPGAgent(env_id="LunarLanderContinuous-v2", exp_name="LunarLander-v2-DDPG")
6# Train the agent
7return_ = agent.train(step=int(4000000), collector_env_num=4, evaluator_env_num=4)
8# Push model to huggingface hub
9push_model_to_hub(
10 agent=agent.best,
11 env_name="OpenAI/Gym/Box2d",
12 task_name="LunarLander-v2",
13 algo_name="DDPG",
14 wandb_url=return_.wandb_url,
15 github_repo_url="https://github.com/opendilab/DI-engine",
16 github_doc_model_url="https://di-engine-docs.readthedocs.io/en/latest/12_policies/ddpg.html",
17 github_doc_env_url="https://di-engine-docs.readthedocs.io/en/latest/13_envs/lunarlander.html",
18 installation_guide="pip3 install DI-engine[common_env]",
19 usage_file_by_git_clone="./ddpg/lunarlander_ddpg_deploy.py",
20 usage_file_by_huggingface_ding="./ddpg/lunarlander_ddpg_download.py",
21 train_file="./ddpg/lunarlander_ddpg.py",
22 repo_id="OpenDILabCommunity/LunarLander-v2-DDPG",
23 create_repo=False
24)
251exp_config = {
2 'env': {
3 'manager': {
4 'episode_num': float("inf"),
5 'max_retry': 1,
6 'retry_type': 'reset',
7 'auto_reset': True,
8 'step_timeout': None,
9 'reset_timeout': None,
10 'retry_waiting_time': 0.1,
11 'cfg_type': 'BaseEnvManagerDict'
12 },
13 'stop_value': 260,
14 'n_evaluator_episode': 8,
15 'env_id': 'LunarLanderContinuous-v2',
16 'collector_env_num': 8,
17 'evaluator_env_num': 8,
18 'act_scale': True
19 },
20 'policy': {
21 'model': {
22 'obs_shape': 8,
23 'action_shape': 2,
24 'twin_critic': True,
25 'action_space': 'regression'
26 },
27 'learn': {
28 'learner': {
29 'train_iterations': 1000000000,
30 'dataloader': {
31 'num_workers': 0
32 },
33 'log_policy': True,
34 'hook': {
35 'load_ckpt_before_run': '',
36 'log_show_after_iter': 100,
37 'save_ckpt_after_iter': 10000,
38 'save_ckpt_after_run': True
39 },
40 'cfg_type': 'BaseLearnerDict'
41 },
42 'update_per_collect': 2,
43 'batch_size': 128,
44 'learning_rate_actor': 0.001,
45 'learning_rate_critic': 0.001,
46 'ignore_done': False,
47 'target_theta': 0.005,
48 'discount_factor': 0.99,
49 'actor_update_freq': 1,
50 'noise': False,
51 'noise_sigma': 0.1,
52 'noise_range': {
53 'min': -0.5,
54 'max': 0.5
55 }
56 },
57 'collect': {
58 'collector': {
59 'collect_print_freq': 1000
60 },
61 'unroll_len': 1,
62 'noise_sigma': 0.1,
63 'n_sample': 48
64 },
65 'eval': {
66 'evaluator': {
67 'eval_freq': 100,
68 'render': {
69 'render_freq': -1,
70 'mode': 'train_iter'
71 },
72 'figure_path': None,
73 'cfg_type': 'InteractionSerialEvaluatorDict',
74 'stop_value': 260,
75 'n_episode': 8
76 }
77 },
78 'other': {
79 'replay_buffer': {
80 'replay_buffer_size': 20000
81 }
82 },
83 'on_policy': False,
84 'cuda': True,
85 'multi_gpu': False,
86 'bp_update_sync': True,
87 'traj_len_inf': False,
88 'type': 'ddpg',
89 'priority': False,
90 'priority_IS_weight': False,
91 'random_collect_size': 0,
92 'transition_with_policy_data': False,
93 'action_space': 'continuous',
94 'reward_batch_norm': False,
95 'multi_agent': False,
96 'cfg_type': 'DDPGPolicyDict'
97 },
98 'exp_name': 'LunarLander-v2-DDPG',
99 'seed': 0,
100 'wandb_logger': {
101 'gradient_logger': True,
102 'video_logger': True,
103 'plot_logger': True,
104 'action_logger': True,
105 'return_logger': False
106 }
107}
108