Models¶
Most of the code in metatomic.torch is here to define and export
models and to store model metadata. The corresponding classes are documented
below:
We also provide a couple of functions to work with the models:
- metatomic.torch.read_model_metadata(path: str) ModelMetadata[source]¶
Read metadata of a saved atomistic model.
This function allows to access the metadata of a model without loading it in advance.
- Parameters:
path (str) – path to the exported model file
- Return type:
- metatomic.torch.load_atomistic_model(path, extensions_directory=None) AtomisticModel[source]¶
Check and then load the metatomic model at the given path.
This function calls
metatomic.torch.check_atomistic_model()andmetatomic.torch.load_model_extensions()before attempting to load the model.- Parameters:
path – path to an exported metatensor model
extensions_directory – path to a directory containing all extensions required by the exported model
- Return type:
- metatomic.torch.check_atomistic_model(path: str)[source]¶
Check that the file at
pathcontains an exported atomistic model, and that this model can be loaded in the current process.This function should be called before
torch.jit.load()when loading an existing model.- Parameters:
path (str) – path to the exported model file
- metatomic.torch.load_model_extensions(path: str, extensions_directory: str | None = None)[source]¶
Load the TorchScript extensions (and their dependencies) that the model at
pathuses.If
extensions_directoryis provided, we look for the extensions and their dependencies in there first. If this function fails to load some library, it will produce a warning using Torch’s warnings infrastructure. Users can set theMETATENSOR_DEBUG_EXTENSIONS_LOADINGenvironment variable to get more informations about a failure in the standard error output.- Parameters:
path (str) – path to the exported model file
extensions_directory (str | None) – path to a directory containing the extensions. This directory will typically be created by calling
AtomisticModel.export()withcollect_extensions=extensions_directory.