MCPcopy Create free account
hub / github.com/RoboVerseOrg/RoboVerse / build_actor

Function build_actor

scripts/eval_go1_cross_sim.py:23–42  ·  view source on GitHub ↗

Reconstruct rsl_rl ActorCritic MLP from state_dict. Expected keys: ``mlp.{0,2,4,6}.{weight,bias}`` (Linear layers, with ELU between).

(state_dict: dict, device: torch.device)

Source from the content-addressed store, hash-verified

21
22
23def build_actor(state_dict: dict, device: torch.device) -> nn.Module:
24 """Reconstruct rsl_rl ActorCritic MLP from state_dict.
25
26 Expected keys: ``mlp.{0,2,4,6}.{weight,bias}`` (Linear layers, with ELU between).
27 """
28 keys = sorted(
29 [k for k in state_dict if k.startswith("mlp.") and k.endswith(".weight")],
30 key=lambda k: int(k.split(".")[1]),
31 )
32 mods = []
33 for i, k in enumerate(keys):
34 w = state_dict[k]
35 mods.append(nn.Linear(w.shape[1], w.shape[0]))
36 if i < len(keys) - 1:
37 mods.append(nn.ELU())
38 actor = nn.Sequential(*mods).to(device)
39 stripped = {k[len("mlp.") :]: v for k, v in state_dict.items() if k.startswith("mlp.")}
40 actor.load_state_dict(stripped, strict=False)
41 actor.eval()
42 return actor
43
44
45def rollout(sim: str, n_envs: int, ckpt_path: str, steps: int, task_name: str, robot_name: str):

Callers 1

rolloutFunction · 0.70

Calls 2

toMethod · 0.80
itemsMethod · 0.80

Tested by

no test coverage detected