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)
| 21 | |
| 22 | |
| 23 | def 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 | |
| 45 | def rollout(sim: str, n_envs: int, ckpt_path: str, steps: int, task_name: str, robot_name: str): |