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

Function remove_model_prefix

lit_gpt/utils.py:540–549  ·  view source on GitHub ↗

Handles the case where the LightningModule wrapper (FullPintsTransformer) prepends 'model.' to all keys in the state dict. Removes the prefix in-place.

(state_dict: Dict[str, torch.Tensor])

Source from the content-addressed store, hash-verified

538
539
540def remove_model_prefix(state_dict: Dict[str, torch.Tensor]) -> None:
541 """
542 Handles the case where the LightningModule wrapper (FullPintsTransformer) prepends 'model.'
543 to all keys in the state dict. Removes the prefix in-place.
544 """
545 keys = list(state_dict.keys())
546 for key in keys:
547 new_key = key.removeprefix('model.')
548 if new_key != key:
549 state_dict[new_key] = state_dict.pop(key)
550
551
552def add_model_prefix(state_dict: Dict[str, torch.Tensor]) -> None:

Callers 1

load_weightsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected