torchani.compile#
Ahead-of-time compilation of models into AOTInductor packages
Warning
This module is experimental. Its API and behavior may change without warning.
The compiled package holds one model per entrypoint, device and precision, named
"<entrypoint>/<device>/<precision>" (e.g. "single_point_pbc/cuda/f32"). The
models can be loaded without Python, from C++, using
torch::inductor::AOTIModelPackageLoader(package_path, model_name), or from Python,
using torch._inductor.package.load_package(package_path, model_name). The
entrypoints and their signatures are:
"single_point":(species, coords, net_charge, spin_mult) -> (energies, forces, atomic_charges)"single_point_pbc":(species, coords, cell, pbc, net_charge, spin_mult) -> (energies, forces, atomic_charges)"external_neighbors":(species, coords, neighbor_idxs, shifts, net_charge, spin_mult) -> (energies, forces, atomic_charges)"custom_mlmm":(species, coords, mm_coords, mm_charges, net_charge, spin_mult, mm_cutoff) -> (energies, forces, mm_forces, atomic_charges)"multipole_mlmm":(species, coords, mm_coords, mm_charges, mm_dipoles, mm_quads, net_charge, spin_mult, mm_cutoff) -> (energies, forces, mm_forces, atomic_charges)
with input shapes species: (1, A), coords: (1, A, 3), cell: (3, 3),
pbc: (3,), net_charge: (1,), spin_mult: (1,), neighbor_idxs: (2, P),
shifts: (P, 3), mm_coords: (1, M, 3), mm_charges: (1, M),
mm_dipoles: (1, M, 3), mm_quads: (1, M, 3, 3) and mm_cutoff: (1,), and
output shapes (1,), (1, A, 3), (1, M, 3) (mm_forces) and (1, A).
If the model doesn’t predict atomic charges, they are an empty tensor of shape
(1, 0). The "custom_mlmm" entrypoint requires a model that exports a
compute_mlmm method, which accepts spin_mult and mm_cutoff keyword
arguments and returns either the energies or a tuple (energies, atomic_charges).
Models may also output a dict with the "energies" key and, optionally,
"atomic_charges".
The "multipole_mlmm" entrypoint is the same, but it requires a
compute_multipole_mlmm method, which also takes mm_dipoles and mm_quads
after mm_charges.
All inputs must be contiguous, and for "external_neighbors" the coords must be
mapped to the central cell. The CUDA models use cuAEV if the model supports it, and ANI
CPU models use pyaev. If a model uses cuAEV or FastCellList, the corresponding
extension must be loaded by the process before running the package.
Functions
Compile a model's energies and forces into an AOTInductor package |
- torchani.compile.compile_model(model, package_path, device=('cpu', 'cuda'), precision=('f32', 'f64'), configs=None, symbols=None, cutoff=None)[source]#
Compile a model’s energies and forces into an AOTInductor package
The model is compiled once for each combination of entrypoint, device and precision, and each compiled model is stored in the package under the name
"<entrypoint>/<device>/<precision>", e.g."single_point_pbc/cuda/f32". See the module docstring for the signatures of the entrypoints. The input model is not modified.- Parameters:
model (Module) – The model to compile.
package_path (str | Path) – Path of the output
.pt2package.device ('cpu' | 'cuda' | tuple['cpu' | 'cuda', ...]) – Device, or tuple of devices, to compile for.
precision ('f32' | 'f64' | tuple['f32' | 'f64', ...]) – Precision, or tuple of precisions, to compile for.
configs ('single_point' | 'single_point_pbc' | 'external_neighbors' | 'custom_mlmm' | 'multipole_mlmm' | tuple['single_point' | 'single_point_pbc' | 'external_neighbors' | 'custom_mlmm' | 'multipole_mlmm', ...] | None) – Entrypoint, or tuple of entrypoints, to compile.
"custom_mlmm"requires a model with acompute_mlmmmethod, and"multipole_mlmm"one with acompute_multipole_mlmmmethod. IfNone,"single_point"and"single_point_pbc"are always compiled,"external_neighbors"is compiled if the model has acompute_from_external_neighborsmethod,"custom_mlmm"if it has acompute_mlmmmethod, and"multipole_mlmm"if it has acompute_multipole_mlmmmethod.symbols (Sequence[str] | None) – Chemical symbols supported by the model, used to build the example inputs. If
None,model.symbolsis used.cutoff (float | None) – Cutoff of the model, used to build the example inputs. If
None,model.cutoffis used.
- Returns:
The path of the package.
- Return type: