mapping_networks.checkpoint.load_checkpoint¶
- mapping_networks.checkpoint.load_checkpoint(path: str | Path, model: MappingModel, *, trainer: MappingTrainer | None = None, map_location: Any = None, strict_latents: bool = True) CheckpointSchema¶
Load a checkpoint and restore model (and optionally trainer) state.
The target’s
ParameterSpecis validated against the checkpoint before any state is applied. If the architecture differs aCheckpointCompatibilityErroris raised and the model is left unchanged.- Parameters:
path – Path to the
.ptcheckpoint file.model – A
MappingModelwhose generator state will be restored.trainer – Optional
MappingTrainerwhose optimizer, scheduler, epoch, and GradScaler state will be restored when present in the checkpoint.map_location – Passed to
torch.loadfor device remapping.strict_latents – When True,
load_state_dictis called in strict mode — every saved latent and buffer key must match the generator. Set to False to allow partial loading (e.g. subsets of layers).
- Returns:
The parsed
CheckpointSchemaso callers can inspectmetadata,config, ortrainer_stateindependently.- Raises:
FileNotFoundError – If the checkpoint file does not exist.
CheckpointCompatibilityError – If schema version or architecture is incompatible.
Example:
schema = load_checkpoint("checkpoints/epoch10.pt", model=model, trainer=trainer) print(f"Resumed from epoch {schema.trainer_state['epoch']}")