MCPcopy Create free account
hub / github.com/UCSC-VLAA/OpenVision / load

Function load

src/models/text_decoder_v2.py:494–518  ·  view source on GitHub ↗

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] = ())

Source from the content-addressed store, hash-verified

492
493
494def 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected