MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / load_weights

Function load_weights

lit_gpt/utils.py:563–585  ·  view source on GitHub ↗

Loads the model weights from the specified path.

(
        path: Path,
        add_prefix: bool = False,
        remove_prefix: bool = False
    )

Source from the content-addressed store, hash-verified

561
562
563def load_weights(
564 path: Path,
565 add_prefix: bool = False,
566 remove_prefix: bool = False
567 ) -> Dict[str, torch.Tensor]:
568 """
569 Loads the model weights from the specified path.
570 """
571 assert not (remove_prefix and add_prefix), \
572 'Cannot add and remove model prefix to the state dict simultaneously.'
573
574 state = torch.load(path)
575
576 # Handle cases where state_dict has 'model' key
577 state = state.get('model', state)
578
579 if remove_prefix:
580 remove_model_prefix(state)
581
582 if add_prefix:
583 add_model_prefix(state)
584
585 return state

Callers 1

get_lit_inferencesFunction · 0.90

Calls 3

remove_model_prefixFunction · 0.85
add_model_prefixFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected