xnn.common.models.hub.checkpoint.save_pretrained#
- xnn.common.models.hub.checkpoint.save_pretrained(model, save_directory, *, config=None, card=None, verify=True, **card_fields)[source]#
Write a model as a portable directory.
The directory holds
config.yaml(the configuration that rebuilds the architecture),model.pt(the weights, loadable withweights_only=True) andcard.json(theModelCard, with an MD5 per file). The card is written last, so a directory with a card is complete. Nothing in it refers to the machine it was written on.- Parameters:
model (torch.nn.Module or str or pathlib.Path) – A model (bare, or wrapped in
ForceStressOutput) or the path of any checkpointload_checkpoint()reads (e.g. a trainer’sbest.pt), which is then repacked.save_directory (str or pathlib.Path) – Output directory; created if missing.
config (Config or ModelConfig, optional) – The configuration the model was built from. Taken from the checkpoint when
modelis a path; required for a module.card (ModelCard or dict, optional) – Card fields (name, description, license, citation, …). The architecture, cutoff, species, dtype, files and xnn version are filled in from the model.
verify (bool, optional) – Rebuild the architecture from
configand load the weights strictly before writing, so a mismatched config fails here rather than at load time. Defaults toTrue.**card_fields – More card fields, overriding
card.
- Returns:
The model directory.
- Return type:
- Raises:
ValueError – If no config is available, or
configdoes not rebuild the weights.