| 638 | checkpoint_engine.save(state_dict=final_state_dict, path=model_ckpt_path) |
| 639 | |
| 640 | def load_state_dir(self, load_dir, checkpoint_engine, strict=True): |
| 641 | for idx, layer in enumerate(self.forward_funcs): |
| 642 | # Functions, etc. will not have state_dicts |
| 643 | if not hasattr(layer, 'load_state_dict'): |
| 644 | continue |
| 645 | |
| 646 | # get all checkpoint files for the layer. |
| 647 | model_ckpt_list = self.ckpt_layer_path_list(load_dir, idx) |
| 648 | mp_rank = self._grid.get_slice_parallel_rank() |
| 649 | mp_world_size = self._grid.get_slice_parallel_world_size() |
| 650 | |
| 651 | sd_loader = SDLoaderFactory.get_sd_loader(model_ckpt_list, |
| 652 | version=2.0, |
| 653 | checkpoint_engine=checkpoint_engine) |
| 654 | load_path, checkpoint, _ = sd_loader.load(mp_world_size, mp_rank, module_key=None, is_pipe_parallel=True) |
| 655 | |
| 656 | layer.load_state_dict(checkpoint, strict=strict) |
| 657 | |
| 658 | self._synchronize_tied_weights() |
| 659 | |
| 660 | def _is_checkpointable(self, funcs): |
| 661 | |