Skip to content

Commit

Permalink
feature(xyy):add HPT model and test_hpt
Browse files Browse the repository at this point in the history
  • Loading branch information
luodi-7 committed Dec 4, 2024
1 parent f3d5507 commit 25f1d2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 8 additions & 4 deletions dizoo/box2d/lunarlander/entry/lunarlander_dqn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@

def main():
logging.getLogger().setLevel(logging.INFO)
cfg = compile_config(main_config, create_cfg=create_config, auto=True, save_cfg=task.router.node_id == 0)
cfg = compile_config(main_config, create_cfg=create_config,
auto=True, save_cfg=task.router.node_id == 0)
ding_init(cfg)

with task.start(async_mode=False, ctx=OnlineRLContext()):
collector_env = SubprocessEnvManagerV2(
env_fn=[lambda: DingEnvWrapper(gym.make("LunarLander-v2")) for _ in range(cfg.env.collector_env_num)],
env_fn=[lambda: DingEnvWrapper(
gym.make("LunarLander-v2")) for _ in range(cfg.env.collector_env_num)],
cfg=cfg.env.manager
)
evaluator_env = SubprocessEnvManagerV2(
env_fn=[lambda: DingEnvWrapper(gym.make("LunarLander-v2")) for _ in range(cfg.env.evaluator_env_num)],
env_fn=[lambda: DingEnvWrapper(
gym.make("LunarLander-v2")) for _ in range(cfg.env.evaluator_env_num)],
cfg=cfg.env.manager
)

Expand All @@ -38,7 +41,8 @@ def main():
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = DQN(**cfg.policy.model).to(device)

buffer_ = DequeBuffer(size=cfg.policy.other.replay_buffer.replay_buffer_size)
buffer_ = DequeBuffer(
size=cfg.policy.other.replay_buffer.replay_buffer_size)

# Pass the model into Policy
policy = DQNPolicy(cfg.policy, model=model)
Expand Down
15 changes: 10 additions & 5 deletions dizoo/box2d/lunarlander/entry/lunarlander_hpt_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@

def main():
logging.getLogger().setLevel(logging.INFO)
cfg = compile_config(main_config, create_cfg=create_config, auto=True, save_cfg=task.router.node_id == 0)
cfg = compile_config(main_config, create_cfg=create_config,
auto=True, save_cfg=task.router.node_id == 0)
ding_init(cfg)

with task.start(async_mode=False, ctx=OnlineRLContext()):
collector_env = SubprocessEnvManagerV2(
env_fn=[lambda: DingEnvWrapper(gym.make("LunarLander-v2")) for _ in range(cfg.env.collector_env_num)],
env_fn=[lambda: DingEnvWrapper(
gym.make("LunarLander-v2")) for _ in range(cfg.env.collector_env_num)],
cfg=cfg.env.manager
)
evaluator_env = SubprocessEnvManagerV2(
env_fn=[lambda: DingEnvWrapper(gym.make("LunarLander-v2")) for _ in range(cfg.env.evaluator_env_num)],
env_fn=[lambda: DingEnvWrapper(
gym.make("LunarLander-v2")) for _ in range(cfg.env.evaluator_env_num)],
cfg=cfg.env.manager
)

Expand All @@ -39,8 +42,10 @@ def main():
# Migrating models to the GPU
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# HPT introduces a Policy Stem module, which processes the input features using Cross-Attention.
model = HPT(cfg.policy.model.obs_shape, cfg.policy.model.action_shape).to(device)
buffer_ = DequeBuffer(size=cfg.policy.other.replay_buffer.replay_buffer_size)
model = HPT(cfg.policy.model.obs_shape,
cfg.policy.model.action_shape).to(device)
buffer_ = DequeBuffer(
size=cfg.policy.other.replay_buffer.replay_buffer_size)

# Pass the model into Policy
policy = DQNPolicy(cfg.policy, model=model)
Expand Down

0 comments on commit 25f1d2f

Please sign in to comment.