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(env_id="Pendulum-v1", exp_name="Pendulum-v1-DDPG", cfg=cfg.exp_config, policy_state_dict=policy_state_dict)
11# Continue training
12agent.train(step=5000)
13# Render the new agent performance
14agent.deploy(enable_save_replay=True)
151# 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/Pendulum-v1-DDPG")
6# Instantiate the agent
7agent = DDPGAgent(env_id="Pendulum-v1", exp_name="Pendulum-v1-DDPG", cfg=cfg.exp_config, policy_state_dict=policy_state_dict)
8# Continue training
9agent.train(step=5000)
10# Render the new agent performance
11agent.deploy(enable_save_replay=True)
121#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="Pendulum-v1", exp_name="Pendulum-v1-DDPG")
6# Train the agent
7return_ = agent.train(step=int(4000000))
8# Push model to huggingface hub
9push_model_to_hub(
10 agent=agent.best,
11 env_name="OpenAI/Gym/ClassicControl",
12 task_name="Pendulum-v1",
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/pendulum.html",
18 installation_guide="pip3 install DI-engine[common_env]",
19 usage_file_by_git_clone="./ddpg/pendulum_ddpg_deploy.py",
20 usage_file_by_huggingface_ding="./ddpg/pendulum_ddpg_download.py",
21 train_file="./ddpg/pendulum_ddpg.py",
22 repo_id="OpenDILabCommunity/Pendulum-v1-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': -250,
14 'n_evaluator_episode': 5,
15 'env_id': 'Pendulum-v1',
16 'collector_env_num': 8,
17 'evaluator_env_num': 5,
18 'act_scale': True
19 },
20 'policy': {
21 'model': {
22 'obs_shape': 3,
23 'action_shape': 1,
24 'twin_critic': False,
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': True,
47 'target_theta': 0.005,
48 'discount_factor': 0.99,
49 'actor_update_freq': 1,
50 'noise': False
51 },
52 'collect': {
53 'collector': {
54 'collect_print_freq': 1000
55 },
56 'unroll_len': 1,
57 'noise_sigma': 0.1,
58 'n_sample': 48
59 },
60 'eval': {
61 'evaluator': {
62 'eval_freq': 100,
63 'render': {
64 'render_freq': -1,
65 'mode': 'train_iter'
66 },
67 'figure_path': None,
68 'cfg_type': 'InteractionSerialEvaluatorDict',
69 'stop_value': -250,
70 'n_episode': 5
71 }
72 },
73 'other': {
74 'replay_buffer': {
75 'replay_buffer_size': 20000,
76 'max_use': 16
77 }
78 },
79 'on_policy': False,
80 'cuda': False,
81 'multi_gpu': False,
82 'bp_update_sync': True,
83 'traj_len_inf': False,
84 'type': 'ddpg',
85 'priority': False,
86 'priority_IS_weight': False,
87 'random_collect_size': 800,
88 'transition_with_policy_data': False,
89 'action_space': 'continuous',
90 'reward_batch_norm': False,
91 'multi_agent': False,
92 'cfg_type': 'DDPGPolicyDict'
93 },
94 'exp_name': 'Pendulum-v1-DDPG',
95 'seed': 0,
96 'wandb_logger': {
97 'gradient_logger': True,
98 'video_logger': True,
99 'plot_logger': True,
100 'action_logger': True,
101 'return_logger': False
102 }
103}
104