r""""This method calls ``load_tensor_parallel_model_state_dict`` (which handles multiple formats / unmatched tensor parallel size) and load the converted checkpoint into a model. Args: model (nn.Module): The model to load the checkpoint into. path (str): A path containin
(
model: nn.Module, path: str, format: str, verbose: bool = False
)
| 297 | |
| 298 | |
| 299 | def load_tensor_parallel_model( |
| 300 | model: nn.Module, path: str, format: str, verbose: bool = False |
| 301 | ) -> Tuple[List[str], List[str]]: |
| 302 | r""""This method calls ``load_tensor_parallel_model_state_dict`` (which |
| 303 | handles multiple formats / unmatched tensor parallel size) and load the |
| 304 | converted checkpoint into a model. |
| 305 | |
| 306 | Args: |
| 307 | model (nn.Module): The model to load the checkpoint into. |
| 308 | path (str): A path containing checkpoint files. |
| 309 | format (str): Format of the checkpoing files. Supported formats: |
| 310 | ``consolidated`` (saved by our framework) and ``meta_ori`` |
| 311 | (original checkpoints released in Meta's LLaMA repo). |
| 312 | verbose (bool): Print verbose information about the loading process |
| 313 | for debug purposes. Default=``False``. |
| 314 | |
| 315 | Returns: |
| 316 | Tuple[List[str], List[str]]: Returns two lists of strings, the first |
| 317 | being the missing keys and the second being the unexpected keys, |
| 318 | following the same convention as |
| 319 | ``torch.nn.Module.load_state_dict``. |
| 320 | """ |
| 321 | assert not format.endswith("_diff"), ( |
| 322 | "A *_diff checkpoint must be used together with the corresponding " |
| 323 | "base checkpoint to obtain the full model weights." |
| 324 | ) |
| 325 | local_state_dict = load_tensor_parallel_model_state_dict( |
| 326 | model, path, format, verbose |
| 327 | ) |
| 328 | load_result = model.load_state_dict(local_state_dict, strict=False) |
| 329 | print('load tensor parallel model result:\n', load_result) |
| 330 | return load_result |
| 331 | |
| 332 | |
| 333 | def infer_checkpoint_format_and_mp_size(path: str) -> str: |
nothing calls this directly
no test coverage detected