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 TD3Agent
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 = TD3Agent(
11 env_id="BipedalWalker-v3", exp_name="BipedalWalker-v3-TD3", cfg=cfg.exp_config, 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# running with trained model
2python3 -u run.py1from ding.bonus import TD3Agent
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/BipedalWalker-v3-TD3")
6# Instantiate the agent
7agent = TD3Agent(
8 env_id="BipedalWalker-v3",
9 exp_name="BipedalWalker-v3-TD3",
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 TD3Agent
2from huggingface_ding import push_model_to_hub
3
4# Instantiate the agent
5agent = TD3Agent(env_id="BipedalWalker-v3", exp_name="BipedalWalker-v3-TD3")
6# Train the agent
7return_ = agent.train(step=int(200000))
8# Push model to huggingface hub
9push_model_to_hub(
10 agent=agent.best,
11 env_name="OpenAI/Gym/Box2d",
12 task_name="BipedalWalker-v3",
13 algo_name="TD3",
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/td3.html",
17 github_doc_env_url="https://di-engine-docs.readthedocs.io/en/latest/13_envs/bipedalwalker.html",
18 installation_guide="pip3 install DI-engine[common_env]",
19 usage_file_by_git_clone="./td3/bipedalwalker_td3_deploy.py",
20 usage_file_by_huggingface_ding="./td3/bipedalwalker_td3_download.py",
21 train_file="./td3/bipedalwalker_td3.py",
22 repo_id="OpenDILabCommunity/BipedalWalker-v3-TD3",
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': 10000000000,
14 'n_evaluator_episode': 5,
15 'env_id': 'BipedalWalker-v3',
16 'collector_env_num': 8,
17 'evaluator_env_num': 5,
18 'act_scale': True,
19 'rew_clip': True
20 },
21 'policy': {
22 'model': {
23 'twin_critic': True,
24 'obs_shape': 24,
25 'action_shape': 4,
26 'action_space': 'regression',
27 'actor_head_hidden_size': 400,
28 'critic_head_hidden_size': 400
29 },
30 'learn': {
31 'learner': {
32 'train_iterations': 1000000000,
33 'dataloader': {
34 'num_workers': 0
35 },
36 'log_policy': True,
37 'hook': {
38 'load_ckpt_before_run': '',
39 'log_show_after_iter': 1000,
40 'save_ckpt_after_iter': 10000,
41 'save_ckpt_after_run': True
42 },
43 'cfg_type': 'BaseLearnerDict'
44 },
45 'update_per_collect': 64,
46 'batch_size': 256,
47 'learning_rate_actor': 0.0003,
48 'learning_rate_critic': 0.0003,
49 'ignore_done': False,
50 'target_theta': 0.005,
51 'discount_factor': 0.99,
52 'actor_update_freq': 2,
53 'noise': True,
54 'noise_sigma': 0.2,
55 'noise_range': {
56 'min': -0.5,
57 'max': 0.5
58 }
59 },
60 'collect': {
61 'collector': {},
62 'unroll_len': 1,
63 'noise_sigma': 0.1,
64 'n_sample': 64
65 },
66 'eval': {
67 'evaluator': {
68 'eval_freq': 5000,
69 'render': {
70 'render_freq': -1,
71 'mode': 'train_iter'
72 },
73 'figure_path': None,
74 'cfg_type': 'InteractionSerialEvaluatorDict',
75 'stop_value': 10000000000,
76 'n_episode': 5
77 }
78 },
79 'other': {
80 'replay_buffer': {
81 'replay_buffer_size': 300000
82 }
83 },
84 'on_policy': False,
85 'cuda': True,
86 'multi_gpu': False,
87 'bp_update_sync': True,
88 'traj_len_inf': False,
89 'type': 'td3',
90 'priority': False,
91 'priority_IS_weight': False,
92 'random_collect_size': 10000,
93 'transition_with_policy_data': False,
94 'action_space': 'continuous',
95 'reward_batch_norm': False,
96 'multi_agent': False,
97 'cfg_type': 'TD3PolicyDict'
98 },
99 'exp_name': 'BipedalWalker-v3-TD3',
100 'seed': 0,
101 'wandb_logger': {
102 'gradient_logger': True,
103 'video_logger': True,
104 'plot_logger': True,
105 'action_logger': True,
106 'return_logger': False
107 }
108}
109