xnn.common.models.registry.prepare_model#

xnn.common.models.registry.prepare_model(cfg)[source]#

Build a model and the config that rebuilds it.

The same as build_model(), also returning the resolved ModelConfig: with a "pretrained" source the architecture keys are taken from the checkpoint and recorded in place of the source, so the returned config rebuilds the model from its weights alone (what the trainer writes into its checkpoints).

extra["pretrained"] names any source from_pretrained() accepts (registry name, local checkpoint or model directory, URL, Zenodo DOI); extra["head"] picks the head of a multi-head source; extra["dtype"] casts the weights. cfg.cutoff must equal the checkpoint’s (the data pipeline follows it), and the only other keys allowed beside the source are heads, lora, atomic_energies (new reference energies, applied after the weights are loaded) and, when the checkpoint has none, dispersion / long_range. A reference-energy marker (atomic_energies: estimated / average) needs data and is resolved by the Trainer; here it is an error.

Parameters:

cfg (ModelConfig) – The model configuration.

Returns:

The model and the resolved config.

Return type:

tuple of (InteratomicPotential, ModelConfig)

Raises:
  • KeyError – If the model name is not registered.

  • ValueError – For an inconsistent pretrained config, or a reference-energy marker.