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
5
6sudo apt update -y && sudo apt install -y build-essential libgl1-mesa-dev libgl1-mesa-glx libglew-dev libosmesa6-dev libglfw3 libglfw3-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-dev patchelf
7
8mkdir -p ~/.mujoco
9wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz -O mujoco.tar.gz
10tar -xf mujoco.tar.gz -C ~/.mujoco
11echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin" >> ~/.bashrc
12export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin
13pip3 install "cython<3"
14pip3 install DI-engine[common_env]
151# 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="Walker2d-v3", exp_name="Walker2d-v3-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/Walker2d-v3-DDPG")
6# Instantiate the agent
7agent = DDPGAgent(env_id="Walker2d-v3", exp_name="Walker2d-v3-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="Walker2d-v3", exp_name="Walker2d-v3-DDPG")
6# Train the agent
7return_ = agent.train(step=int(5000000))
8# Push model to huggingface hub
9push_model_to_hub(
10 agent=agent.best,
11 env_name="OpenAI/Gym/MuJoCo",
12 task_name="Walker2d-v3",
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/mujoco.html",
18 installation_guide='''
19sudo apt update -y \
20 && sudo apt install -y \
21 build-essential \
22 libgl1-mesa-dev \
23 libgl1-mesa-glx \
24 libglew-dev \
25 libosmesa6-dev \
26 libglfw3 \
27 libglfw3-dev \
28 libsdl2-dev \
29 libsdl2-image-dev \
30 libglm-dev \
31 libfreetype6-dev \
32 patchelf
33
34mkdir -p ~/.mujoco
35wget https://mujoco.org/download/mujoco210-linux-x86_64.tar.gz -O mujoco.tar.gz
36tar -xf mujoco.tar.gz -C ~/.mujoco
37echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin" >> ~/.bashrc
38export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mjpro210/bin:~/.mujoco/mujoco210/bin
39pip3 install "cython<3"
40pip3 install DI-engine[common_env]
41''',
42 usage_file_by_git_clone="./ddpg/walker2d_ddpg_deploy.py",
43 usage_file_by_huggingface_ding="./ddpg/walker2d_ddpg_download.py",
44 train_file="./ddpg/walker2d_ddpg.py",
45 repo_id="OpenDILabCommunity/Walker2d-v3-DDPG",
46 create_repo=False
47)
481exp_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': 6000,
14 'n_evaluator_episode': 8,
15 'env_id': 'Walker2d-v3',
16 'norm_obs': {
17 'use_norm': False
18 },
19 'norm_reward': {
20 'use_norm': False
21 },
22 'collector_env_num': 1,
23 'evaluator_env_num': 8,
24 'env_wrapper': 'mujoco_default'
25 },
26 'policy': {
27 'model': {
28 'obs_shape': 17,
29 'action_shape': 6,
30 'twin_critic': False,
31 'actor_head_hidden_size': 256,
32 'critic_head_hidden_size': 256,
33 'action_space': 'regression'
34 },
35 'learn': {
36 'learner': {
37 'train_iterations': 1000000000,
38 'dataloader': {
39 'num_workers': 0
40 },
41 'log_policy': True,
42 'hook': {
43 'load_ckpt_before_run': '',
44 'log_show_after_iter': 100,
45 'save_ckpt_after_iter': 10000,
46 'save_ckpt_after_run': True
47 },
48 'cfg_type': 'BaseLearnerDict'
49 },
50 'update_per_collect': 1,
51 'batch_size': 256,
52 'learning_rate_actor': 0.001,
53 'learning_rate_critic': 0.001,
54 'ignore_done': False,
55 'target_theta': 0.005,
56 'discount_factor': 0.99,
57 'actor_update_freq': 1,
58 'noise': False
59 },
60 'collect': {
61 'collector': {},
62 'unroll_len': 1,
63 'noise_sigma': 0.1,
64 'n_sample': 1
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': 6000,
76 'n_episode': 8
77 }
78 },
79 'other': {
80 'replay_buffer': {
81 'replay_buffer_size': 1000000
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': 'ddpg',
90 'priority': False,
91 'priority_IS_weight': False,
92 'random_collect_size': 25000,
93 'transition_with_policy_data': False,
94 'action_space': 'continuous',
95 'reward_batch_norm': False,
96 'multi_agent': False,
97 'cfg_type': 'DDPGPolicyDict'
98 },
99 'exp_name': 'Walker2d-v3-DDPG',
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