nvalchemi.training.peft.load_peft_checkpoint_into_model#

nvalchemi.training.peft.load_peft_checkpoint_into_model(model, checkpoint_dir, *, checkpoint_index=-1, model_name='main', map_location='cpu', merge=True, strict=True, allowed_import_paths=None, trust_remote_code=False)[source]#

Load PEFT weights from a native checkpoint into a compatible base model.

This mirrors the registration-time order used by FineTuningStrategy: validate the base model, apply the saved PEFT structure, apply saved module patches, then load the checkpointed model state.

Parameters:
  • model (Module) – Base model instance compatible with the checkpoint metadata. The loader mutates this model in place by applying saved PEFT structure, module patches, and checkpointed weights.

  • checkpoint_dir (Path | str) – Root directory containing a checkpoint written by save_checkpoint or CheckpointHook.

  • checkpoint_index (int) – Checkpoint index to read. -1 loads the latest manifest index.

  • model_name (str) – Model entry to load from the checkpoint. Defaults to "main".

  • map_location (str | device | None) – Device mapping used when reading checkpoint tensors.

  • merge (bool) – If True, merge PEFT weights into the model when the backend supports it.

  • strict (bool) – If True, raise on compatibility mismatches. If False, warn and continue for supported soft mismatches.

  • allowed_import_paths (Collection[str] | None) – Additional dotted import paths trusted for custom PEFT metadata and saved module patch classes. Built-in PEFT and supported layer paths are always trusted. Entries may be exact paths or namespace patterns ending in .*. Cannot be provided with trust_remote_code=True.

  • trust_remote_code (bool) – If True, trust checkpoint metadata to import arbitrary custom Python classes. Use only for locally trusted checkpoints. Defaults to False.

Returns:

The input model after PEFT structure and learned weights have been loaded.

Return type:

torch.nn.Module