(self, path: str, checkpointables: Optional[List[str]] = None)
| 84 | return self.load(path, checkpointables=[]) |
| 85 | |
| 86 | def load(self, path: str, checkpointables: Optional[List[str]] = None) -> Dict[str, Any]: |
| 87 | if not path: |
| 88 | # no checkpoint provided |
| 89 | self.logger.info("No checkpoint found. Initializing model from scratch") |
| 90 | return {} |
| 91 | self.logger.info("Loading checkpoint from {}".format(path)) |
| 92 | if not os.path.isfile(path): |
| 93 | path = self.path_manager.get_local_path(path) |
| 94 | assert os.path.isfile(path), "Checkpoint {} not found!".format(path) |
| 95 | |
| 96 | checkpoint = self._load_file(path) |
| 97 | incompatible = self._load_model(checkpoint) |
| 98 | if ( |
| 99 | incompatible is not None |
| 100 | ): # handle some existing subclasses that returns None |
| 101 | self._log_incompatible_keys(incompatible) |
| 102 | |
| 103 | for key in self.checkpointables if checkpointables is None else checkpointables: |
| 104 | if key in checkpoint: |
| 105 | self.logger.info("Loading {} from {}".format(key, path)) |
| 106 | obj = self.checkpointables[key] |
| 107 | obj.load_state_dict(checkpoint.pop(key)) |
| 108 | |
| 109 | # return any further checkpoint data |
| 110 | return checkpoint |
| 111 | |
| 112 | def _load_model(self, checkpoint: Any) -> _IncompatibleKeys: |
| 113 | """ |
no test coverage detected