(self, load_dir, load_module_strict=True, tag=None)
| 442 | return ckpt_name |
| 443 | |
| 444 | def _load_checkpoint(self, load_dir, load_module_strict=True, tag=None): |
| 445 | is_pipe_parallel = isinstance(self.module, PipelineModule) |
| 446 | if is_pipe_parallel: |
| 447 | raise RuntimeError('pipeline parallelism is currently not supported in inference.') |
| 448 | if not isinstance(load_dir, dict) and os.path.isdir(load_dir): |
| 449 | if tag is None: |
| 450 | latest_path = os.path.join(load_dir, "latest") |
| 451 | if os.path.isfile(latest_path): |
| 452 | with open(latest_path, "r") as fd: |
| 453 | tag = fd.read().strip() |
| 454 | |
| 455 | ckpt_list = self._get_all_ckpt_names(load_dir, tag) |
| 456 | sd_loader = SDLoaderFactory.get_sd_loader(ckpt_list, self.checkpoint_engine) |
| 457 | else: |
| 458 | sd_loader = SDLoaderFactory.get_sd_loader_json(load_dir, self.checkpoint_engine) |
| 459 | |
| 460 | checkpoint = sd_loader['checkpoints'] |
| 461 | |
| 462 | if type(checkpoint) is list: |
| 463 | self.sd = torch.load(checkpoint[0], map_location='cpu', weights_only=False) |
| 464 | self.key_list = list(self.sd.keys()) |
| 465 | |
| 466 | self.load_model_with_checkpoint(self.module) |
| 467 | |
| 468 | for i in range(1, len(checkpoint)): |
| 469 | if not dist.is_initialized() or dist.get_rank() == 0: |
| 470 | print(f"loading checkpoint ({i})") |
| 471 | self.sd = torch.load(checkpoint[i], map_location=get_accelerator().device_name(), weights_only=False) |
| 472 | self.key_list = list(self.sd.keys()) |
| 473 | self.load_model_with_checkpoint(self.module) |
| 474 | else: |
| 475 | mp_rank = 0 if self.mpu is None else self.mpu.get_model_parallel_rank() |
| 476 | |
| 477 | load_path, checkpoint, quantize_config = sd_loader.load(self._config.tensor_parallel.tp_size, |
| 478 | mp_rank, |
| 479 | is_pipe_parallel=is_pipe_parallel, |
| 480 | quantize=(self._config.dtype is torch.int8), |
| 481 | quantize_groups=self.quantize_groups, |
| 482 | mlp_extra_grouping=self.mlp_extra_grouping) |
| 483 | |
| 484 | self.quantization_scales, self.quantize_merge_count = quantize_config |
| 485 | |
| 486 | moe, _ = has_moe_layers(self.module) |
| 487 | if moe: |
| 488 | from deepspeed.runtime.engine import DeepSpeedEngine |
| 489 | old_moe_load = False |
| 490 | if not isinstance(checkpoint['num_experts'], list): |
| 491 | old_moe_load = True |
| 492 | DeepSpeedEngine.load_moe_state_dict(load_dir, |
| 493 | tag, |
| 494 | state_dict=checkpoint[self._choose_module_key(checkpoint)], |
| 495 | old_moe_load=old_moe_load, |
| 496 | model=self.module, |
| 497 | mpu=self.mpu, |
| 498 | checkpoint_engine=self.checkpoint_engine, |
| 499 | autoep_layers=None) |
| 500 | |
| 501 | self.module.load_state_dict(state_dict=checkpoint[self._choose_module_key(checkpoint)], |
nothing calls this directly
no test coverage detected