(self, path: str | Path)
| 26 | bottleneck_dim: int |
| 27 | |
| 28 | def save(self, path: str | Path) -> None: |
| 29 | path = Path(path) |
| 30 | path.parent.mkdir(parents=True, exist_ok=True) |
| 31 | state = { |
| 32 | "hidden_dim": self.hidden_dim, |
| 33 | "bottleneck_dim": self.bottleneck_dim, |
| 34 | "router_layers": {}, |
| 35 | } |
| 36 | for layer_idx, router in self.routers.items(): |
| 37 | state["router_layers"][layer_idx] = router.state_dict() |
| 38 | torch.save(state, path) |
| 39 | |
| 40 | @classmethod |
| 41 | def load(cls, path: str | Path, device: str = "cpu") -> RouterCheckpoint: |
no outgoing calls