v0.1.5 prev1; Add ACMoE

This commit is contained in:
wty-yy
2026-01-06 23:38:32 +08:00
parent ddd7119050
commit 05e1e81d64
13 changed files with 601 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
from legged_gym import LEGGED_GYM_ROOT_DIR, LEGGED_GYM_ENVS_DIR
from legged_gym.envs.go2.go2_env import Go2Robot
from legged_gym.envs.go2.go2_config import GO2Cfg, GO2CfgPPO, GO2CfgCTS, GO2CfgMoECTS, GO2CfgMCPCTS
from legged_gym.envs.go2.go2_config import GO2Cfg, GO2CfgPPO, GO2CfgCTS, GO2CfgMoECTS, GO2CfgMCPCTS, GO2CfgACMoECTS
from .base.legged_robot import LeggedRobot
from legged_gym.utils.task_registry import task_registry
@@ -10,3 +10,4 @@ task_registry.register("go2", Go2Robot, GO2Cfg(), GO2CfgPPO())
task_registry.register("go2_cts", Go2Robot, GO2Cfg(), GO2CfgCTS())
task_registry.register("go2_moe_cts", Go2Robot, GO2Cfg(), GO2CfgMoECTS())
task_registry.register("go2_mcp_cts", Go2Robot, GO2Cfg(), GO2CfgMCPCTS())
task_registry.register("go2_ac_moe_cts", Go2Robot, GO2Cfg(), GO2CfgACMoECTS())

View File

@@ -368,3 +368,11 @@ class LeggedRobotCfgMCPCTS(LeggedRobotCfgCTS):
class runner(LeggedRobotCfgCTS.runner):
policy_class_name = 'ActorCriticMCPCTS'
algorithm_class_name = 'MCPCTS'
class LeggedRobotCfgACMoECTS(LeggedRobotCfgCTS):
class policy(LeggedRobotCfgCTS.policy):
expert_num = 8 # number of experts in the student model
class runner(LeggedRobotCfgCTS.runner):
policy_class_name = 'ActorCriticACMoECTS'
algorithm_class_name = 'ACMoECTS'

View File

@@ -1,5 +1,5 @@
import math
from legged_gym.envs.base.legged_robot_config import LeggedRobotCfg, LeggedRobotCfgPPO, LeggedRobotCfgCTS, LeggedRobotCfgMoECTS, LeggedRobotCfgMoECTS, LeggedRobotCfgMCPCTS
from legged_gym.envs.base.legged_robot_config import LeggedRobotCfg, LeggedRobotCfgPPO, LeggedRobotCfgCTS, LeggedRobotCfgMoECTS, LeggedRobotCfgMoECTS, LeggedRobotCfgMCPCTS, LeggedRobotCfgACMoECTS
class GO2Cfg(LeggedRobotCfg):
class init_state(LeggedRobotCfg.init_state):
@@ -275,3 +275,13 @@ class GO2CfgMCPCTS(LeggedRobotCfgMCPCTS):
experiment_name = 'go2_mcp_cts'
max_iterations = 150000
save_interval = 500
class GO2CfgACMoECTS(LeggedRobotCfgACMoECTS):
class policy(LeggedRobotCfgACMoECTS.policy):
expert_num = 8 # number of experts in the student model
class runner(LeggedRobotCfgACMoECTS.runner):
run_name = ''
experiment_name = 'go2_ac_moe_cts'
max_iterations = 150000
save_interval = 500

View File

@@ -85,6 +85,9 @@ class _TorchPolicyExporter(torch.nn.Module):
self.actor = copy.deepcopy(policy.actor_mcp)
self.obs_no_goal_mask = copy.deepcopy(policy.obs_no_goal_mask).cpu()
self.forward = self.forward_mcp_cts
elif hasattr(policy, "actor_moe"):
self.actor = copy.deepcopy(policy.actor_moe)
self.forward = self.forward_ac_moe
elif hasattr(policy, "actor"):
self.actor = copy.deepcopy(policy.actor)
if self.is_recurrent:
@@ -144,6 +147,14 @@ class _TorchPolicyExporter(torch.nn.Module):
mean_action, _, weights = self.actor(x, x_no_goal)
return mean_action, (weights, latent)
def forward_ac_moe(self, x): # x is single observations
x = self.normalizer(x)
self.history = torch.cat([self.history[:, 1:], x.unsqueeze(1)], dim=1)
latent = self.student_encoder(self.history.flatten(1))
x = torch.cat([latent, x], dim=1)
mean, weights = self.actor(x)
return mean, (weights, latent)
@torch.jit.export
def reset(self):
if hasattr(self, 'history'):