Loads pre-trained model weights from a checkpoint file. Args: init_params: A PyTree of randomly initialized model parameters. init_file: Path to the checkpoint file to load. model_cfg: The model configuration dictionary (unused in this function). dont_load: A seq
(init_params: dict, init_file: str, model_cfg: dict, dont_load: Sequence[str] = ())
| 492 | |
| 493 | |
| 494 | def load(init_params: dict, init_file: str, model_cfg: dict, dont_load: Sequence[str] = ()) -> dict: |
| 495 | """Loads pre-trained model weights from a checkpoint file. |
| 496 | |
| 497 | Args: |
| 498 | init_params: A PyTree of randomly initialized model parameters. |
| 499 | init_file: Path to the checkpoint file to load. |
| 500 | model_cfg: The model configuration dictionary (unused in this function). |
| 501 | dont_load: A sequence of parameter names (or prefixes) to exclude from loading. |
| 502 | |
| 503 | Returns: |
| 504 | A PyTree of parameters with loaded weights. |
| 505 | """ |
| 506 | del model_cfg |
| 507 | restored_params = utils.load_params(filepath=init_file) |
| 508 | |
| 509 | # Merge restored params into the initialized structure, allowing for fine-tuning |
| 510 | # where some parameters (like the output head) might be re-initialized. |
| 511 | restored_params = common.merge_params( |
| 512 | restored_params, init_params, dont_load=dont_load) |
| 513 | |
| 514 | # Ensure dtypes are correctly restored (e.g., from float32 to bfloat16). |
| 515 | restored_params = jax.tree_util.tree_map( |
| 516 | utils.recover_dtype, restored_params) |
| 517 | |
| 518 | return restored_params |
nothing calls this directly
no outgoing calls
no test coverage detected