deepmd.pt_expt.model#
Submodules#
- deepmd.pt_expt.model.dipole_model
- deepmd.pt_expt.model.dos_model
- deepmd.pt_expt.model.dp_linear_model
- deepmd.pt_expt.model.dp_zbl_model
- deepmd.pt_expt.model.dpa4_model
- deepmd.pt_expt.model.edge_transform_output
- deepmd.pt_expt.model.ener_model
- deepmd.pt_expt.model.frozen
- deepmd.pt_expt.model.get_model
- deepmd.pt_expt.model.graph_lower
- deepmd.pt_expt.model.make_model
- deepmd.pt_expt.model.model
- deepmd.pt_expt.model.native_spin_model
- deepmd.pt_expt.model.polar_model
- deepmd.pt_expt.model.property_model
- deepmd.pt_expt.model.spin_ener_model
- deepmd.pt_expt.model.spin_model
- deepmd.pt_expt.model.transform_output
- deepmd.pt_expt.model.unimol_pretrain_model
Classes#
Common methods for DP models. | |
Common methods for DP models. | |
Common methods for DP models. | |
Common methods for DP models. | |
Energy model for the DPA4/SeZM descriptor family. | |
Common methods for DP models. | |
Load model from a frozen model file, which cannot be trained. | |
Base class for pt_expt models. | |
pt_expt native-spin energy model. | |
Common methods for DP models. | |
Common methods for DP models. | |
A spin model for energy. | |
Uni-Mol v1 self-supervised pretraining on the PyTorch-Exportable backend. |
Functions#
| Make a model that can compute Hessian. |
| Get a model from a config dictionary. |
Package Contents#
- deepmd.pt_expt.model.make_hessian_model(T_Model: type) type[source]#
Make a model that can compute Hessian.
With the JAX-mirrored approach, hessian is computed in
forward_common_atomic(in make_model.py) on extended coordinates. This wrapper only needs to overrideatomic_output_def()to setr_hessian=True, andcommunicate_extended_outputin dpmodel naturally maps it from nall to nloc.- Parameters:
- T_Model
The model. Should provide the
atomic_output_defmethod.
- Returns:
Themodelthatcomputeshessian.
- class deepmd.pt_expt.model.DipoleModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPDipoleModel_Common methods for DP models.
This class provides common functionality for DeepPot models, including neighbor selection updates and fitting network access.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Default forward delegates to call().
Subclasses (e.g. EnergyModel) override this with output translation.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
- class deepmd.pt_expt.model.DOSModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPDOSModel_Common methods for DP models.
This class provides common functionality for DeepPot models, including neighbor selection updates and fitting network access.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Default forward delegates to call().
Subclasses (e.g. EnergyModel) override this with output translation.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
- class deepmd.pt_expt.model.LinearEnergyModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPLinearModel_Common methods for DP models.
This class provides common functionality for DeepPot models, including neighbor selection updates and fitting network access.
- compute_fitting_input_stats(sampled_func: collections.abc.Callable[[], list[dict]]) None[source]#
Recompute the input statistics of every learned sub-model’s fitting net.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Default forward delegates to call().
Subclasses (e.g. EnergyModel) override this with output translation.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
- class deepmd.pt_expt.model.DPZBLModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPZBLModel_Common methods for DP models.
This class provides common functionality for DeepPot models, including neighbor selection updates and fitting network access.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Default forward delegates to call().
Subclasses (e.g. EnergyModel) override this with output translation.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
- class deepmd.pt_expt.model.DPA4EnergyModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.pt_expt.model.ener_model.EnergyModelEnergy model for the DPA4/SeZM descriptor family.
Behaviorally identical to
EnergyModel; additionally owns the pt-checkpoint interop: pt’sSeZMModelserialises with a model-level wrapper ({type: "SeZM", atomic_model: <sezm_atomic dict>, bridging_method, bridging_r_*, lora}) whose atomic dict carries pt-only extras –deserialize()recognises those layouts, normalises them to the standard flat dict, and delegates to the generic path.- static _unwrap_pt_sezm_model(data: dict[str, Any]) dict[str, Any][source]#
Unwrap pt’s
SeZMModelserialization to the inner atomic dict.
- static _normalize_pt_sezm_atomic(data: dict[str, Any]) dict[str, Any][source]#
Convert a pt
sezm_atomicdict to a standard atomic dict.Strips the pt-only
denshead state (dens_fitting/active_mode/ thedens_force_rmsd@variable) and rewrites thetype/@versionso the generic dpmodel atomic-model deserialize accepts it. A non-energy active mode or a populated dens head is rejected because pt_expt only implements the energy path.
- class deepmd.pt_expt.model.EnergyModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPEnergyModel_Common methods for DP models.
This class provides common functionality for DeepPot models, including neighbor selection updates and fitting network access.
- _to_public_keys(model_ret: dict[str, torch.Tensor], do_atomic_virial: bool) dict[str, torch.Tensor][source]#
Rename one
call_commonresult to the public energy-model keys.The renaming is a property of the output definition, not of the node axis, so it serves the rectangular and the ragged entry alike.
- Parameters:
- model_ret
dict[str,torch.Tensor] A
call_commonresult, in internal<var>_<derivative>keys.- do_atomic_virialbool
Whether the per-atom virial was requested and should be carried.
- model_ret
- Returns:
dict[str,torch.Tensor]The same tensors under the public names.
- _translate_eager_call(model_ret: dict[str, torch.Tensor], atype: torch.Tensor, do_atomic_virial: bool = False) dict[str, torch.Tensor][source]#
Translate internal energy outputs at the public model boundary.
- Parameters:
- model_ret
dict[str,torch.Tensor] Result returned by a
call_commonentry.- atype
torch.Tensor Atom types on the same node axis as the atomic outputs.
- do_atomic_virialbool, default:
False Whether the per-atom virial was requested.
- model_ret
- Returns:
dict[str,torch.Tensor]Public model outputs.
Notes
Native-spin models override this translation to add
force_magandmask_mag. Keeping the dispatch here lets rectangular and ragged forwards share one implementation without duplicating a spin-specificforward_ragged.
- forward_lower_canonical_graph(atype: torch.Tensor, n_node: torch.Tensor, n_local: torch.Tensor, source: torch.Tensor, edge_vec: torch.Tensor, destination_row_ptr: torch.Tensor, source_row_ptr: torch.Tensor, source_order: torch.Tensor, *, do_atomic_virial: bool, spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Evaluate an eligible compressed canonical deployment graph.
- Parameters:
- atype
Flat local-plus-halo atom types with shape
(N,), int64.- n_node
Per-frame total node counts with shape
(nf,), int64.- n_local
Per-frame owned node counts with shape
(nf,), int64.- source
Source-node indices with shape
(S,), uint32.- edge_vec
Destination-major edge vectors with shape
(S, 3), float32.- destination_row_ptr
Destination CSR offsets with shape
(N + 1,), int64.- source_row_ptr
Source CSR offsets with shape
(N + 1,), int64.- source_order
Source-grouped edge positions with shape
(S,)and the same dtype assource.- do_atomic_virial
Whether to return the per-node virial.
- spin
Per-node magnetic moments with shape
(N, 3)for a native-spin model, orNone. Ghost rows carry their owner’s moment.
- Returns:
dict[str,torch.Tensor]Public energy-model outputs on the flat node axis.
- forward_lower_canonical_graph_exportable(atype: torch.Tensor, n_node: torch.Tensor, n_local: torch.Tensor, source: torch.Tensor, edge_vec: torch.Tensor, destination_row_ptr: torch.Tensor, source_row_ptr: torch.Tensor, source_order: torch.Tensor, *, do_atomic_virial: bool, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace the compact canonical deployment forward with
make_fx.- Parameters:
- atype, n_node, n_local, source, edge_vec
Compact graph node and edge tensors.
- destination_row_ptr, source_row_ptr, source_order
Compact dual-CSR topology.
- do_atomic_virial
Whether the traced output includes per-node virial.
- **make_fx_kwargs
Additional arguments passed to
make_fx().
- Returns:
torch.nn.ModuleTraced eight-input compact deployment module.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, neighbor_list: deepmd.dpmodel.utils.neighbor_list.NeighborList | None = None) dict[str, torch.Tensor][source]#
Evaluate the energy model.
Most arguments share the meaning of
call_common().- Parameters:
- coord
Atomic coordinates.
- atype
Atomic type indices.
- box
Simulation-cell vectors, or
Nonefor a non-periodic system.- fparam
Optional frame parameters.
- aparam
Optional atomic parameters.
- do_atomic_virial
Whether to return per-atom virials.
- charge_spin
Optional frame-level charge and spin conditioning.
- neighbor_list
The neighbor-list construction strategy forwarded to
call_common().Noneuses the default all-pairs builder (DefaultNeighborList), reproducing the historical behavior; an alternative strategy (e.g. thevesinO(N) cell list) may be injected to accelerate neighbor-list construction without changing the model outputs.
- forward_ragged(coord: torch.Tensor, atype: torch.Tensor, n_node: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Evaluate the energy model over a batch whose node axis is flat.
The counterpart of
forward()for frames held concatenated rather than padded to a common atom count. Arguments and results share their meaning withcall_common_ragged(), whose per-atom outputs keep the flat axis; only the keys are the public ones.- Parameters:
- coord
torch.Tensor Local coordinates with shape
(N, 3), frame-major overn_node.- atype
torch.Tensor Local atom types with shape
(N,).- n_node
torch.Tensor Atoms per frame with shape
(nf,).- box
torch.TensororNone,optional Simulation cell with shape
(nf, 3, 3).- fparam
torch.TensororNone,optional Frame parameters with shape
(nf, ndf).- aparam
torch.TensororNone,optional Atomic parameters with shape
(N, nda).- do_atomic_virialbool, default:
False Whether to return per-atom virials.
- charge_spin
torch.TensororNone,optional Frame-level charge and spin conditioning with shape
(nf, 2).- spin
torch.TensororNone,optional Per-atom native spin with shape
(N, 3).
- coord
- Returns:
dict[str,torch.Tensor]Public energy-model keys; per-atom entries have leading dimension
Nand per-frame entriesnf.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace
forward_lowerinto an exportable module.Delegates to
forward_common_lower_exportablefor tracing, then translates the internal keys to theforward_lowerconvention.- Parameters:
- extended_coord
Extended-coordinate sample used for tracing.
- extended_atype
Extended atom-type sample used for tracing.
- nlist
Neighbor-list sample used for tracing.
- mapping
Extended-to-local mapping sample used for tracing.
- fparam
Optional frame-parameter sample.
- aparam
Optional atomic-parameter sample.
- do_atomic_virial
Whether the traced module returns per-atom virials.
- charge_spin
Optional charge/spin conditioning sample.
- **make_fx_kwargs
Extra keyword arguments forwarded to
make_fx(e.g.tracing_mode="symbolic").
- Returns:
torch.nn.ModuleA traced module whose
forwardaccepts(extended_coord, extended_atype, nlist, mapping, fparam, aparam)and returns a dict with the same keys asforward_lower.
- forward_lower_graph_exportable(atype: torch.Tensor, n_node: torch.Tensor, n_local: torch.Tensor, edge_index: torch.Tensor, edge_vec: torch.Tensor, edge_mask: torch.Tensor, destination_order: torch.Tensor, destination_row_ptr: torch.Tensor, source_order: torch.Tensor, source_row_ptr: torch.Tensor, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, destination_sorted: bool = False, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace
forward_common_lower_graphinto an exportable module with public output keys.Delegates to
forward_common_lower_graph_exportablefor tracing, then translates the internal keys to theforward_lowerconvention.- Parameters:
- atype
(N,) flat local-plus-halo atom types,
N == sum(n_node).- n_node
(nf,) per-frame total node counts.
- n_local
(nf,) per-frame owned node counts.
- edge_index
(2, E)
[src, dst]edge endpoints (flat local indices).- edge_vec
(E, 3) neighbor-minus-center edge vectors (sample for tracing).
- edge_mask
(E,) valid-edge mask (sample for tracing).
- destination_order
(E,) destination-grouped edge permutation.
- source_order
(E,) source-grouped edge permutation.
- destination_row_ptr, source_row_ptr
(N + 1,) destination/source CSR offsets.
- destination_sorted
Static export-time assertion that the payload is destination-major and
destination_orderis identity.- fparam, aparam, do_atomic_virial, charge_spin
As in
forward_lower.- **make_fx_kwargs
Extra keyword arguments forwarded to
make_fx(e.g.tracing_mode="symbolic").
- Returns:
torch.nn.ModuleA traced module whose
forwardaccepts(atype, n_node, n_local, edge_index, edge_vec, edge_mask, destination_order, destination_row_ptr, source_order, source_row_ptr, fparam, aparam, charge_spin)and returns a dict with the public keys:atom_energy,energy,force,virial,atom_virial(the last only whendo_atomic_virial). Unlike the denseforward_lower_exportable()(which emitsextended_force/extended_virial), the graph path emitsforceandatom_virialdirectly on the local-plus-halo node axis.
- forward_lower_graph_exportable_with_comm(atype: torch.Tensor, n_node: torch.Tensor, n_local: torch.Tensor, edge_index: torch.Tensor, edge_vec: torch.Tensor, edge_mask: torch.Tensor, destination_order: torch.Tensor, destination_row_ptr: torch.Tensor, source_order: torch.Tensor, source_row_ptr: torch.Tensor, fparam: torch.Tensor | None, aparam: torch.Tensor | None, charge_spin: torch.Tensor | None, send_list: torch.Tensor, send_proc: torch.Tensor, recv_proc: torch.Tensor, send_num: torch.Tensor, recv_num: torch.Tensor, communicator: torch.Tensor, nlocal: torch.Tensor, nghost: torch.Tensor, do_atomic_virial: bool = False, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace
forward_common_lower_graphwith comm_dict tensors as additional positional inputs – the with-comm counterpart offorward_lower_graph_exportable()for message-passing graph descriptors (dpa2’s repformer block drives cross-rank ghost refresh viadeepmd_export::border_op, see_exchange_ghosts_graph()).Mirrors the dense
forward_common_lower_exportable_with_comm(pt_expt/model/make_model.py): packs the 8 trailing positional comm tensors into acomm_dictinside the traced function. Also derivesn_local(the per-frame OWNED node count, reshaped to(1,); single-frame – LAMMPS always drives inference withnf=1) from the scalarnlocaltensor, so the differentiated reduction excludes ghost (not-owned) nodes (seeforward_common_lower_graph()’sn_localparameter). Unlike the plain-graph export path (which tracesforward_common_lower_graph_exportableand then wraps a SECOND make_fx trace around the key-translation closure), this method traces ONCE: the comm-dict packing,n_localderivation, theforward_common_lower_graphcall and the key translation all live in a single tracedfn– following the dense with-comm precedent, which is also a single trace.- Parameters:
- atype, n_node, edge_index, edge_vec, edge_mask, fparam, aparam, charge_spin, do_atomic_virial
- destination_order
Destination-major edge permutation used by fused graph operators.
- destination_row_ptr
Destination CSR row pointers.
- source_order
Source-major edge permutation used by force assembly.
- source_row_ptr
Source CSR row pointers.
- send_list, send_proc, recv_proc, send_num, recv_num, communicator, nlocal, nghost
The 8 comm tensors (see
_make_comm_sample_inputsinserialization.py), packed intocomm_dictinside the traced function.Runtime device contract: ALL 8 stay on CPU, symmetric with the dense with-comm artifact – they are consumed only by the opaque
border_opwhose HOST code dereferences theirdata_ptr(send_listcarries raw host pointers) and readsnlocal/nghostvia cheap host.item()calls. Deriving the in-graph owned count from a device-placednlocalinstead (the previous design) made every per-layerborder_opforward AND custom backward pull the scalars back with synchronizing D2H reads (4 * nlayersper MD step). The C++run_model_graph_with_commimplements this placement.- n_local
(1,) int64 ON THE MODEL DEVICE: the per-frame OWNED node count consumed IN-GRAPH by the owned-node energy mask (it becomes a device kernel operand after
move_to_device_pass, liken_node; a CPU tensor fed there is read as a device pointer – CUDA illegal memory access). Carries the same value as thenlocalcomm tensor; the two inputs exist precisely to separate the device-compute role from the host-MPI-control role.- **make_fx_kwargs
Extra keyword arguments forwarded to
make_fx(e.g.tracing_mode="symbolic").
- Returns:
torch.nn.ModuleA traced module whose
forwardaccepts(atype, n_node, n_local, edge_index, edge_vec, edge_mask, destination_order, destination_row_ptr, source_order, source_row_ptr, fparam, aparam, charge_spin, send_list, send_proc, recv_proc, send_num, recv_num, communicator, nlocal, nghost)and returns a dict with the SAME public keys asforward_lower_graph_exportable()(atom_energy,energy,force,virial,atom_virialwhendo_atomic_virial).
- class deepmd.pt_expt.model.FrozenModel(model_file: str, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.frozen.FrozenModelLoad model from a frozen model file, which cannot be trained.
The frozen model delegates all operations to the deserialized inner model.
serialize()returns the inner model’s data, anddeserialize()dispatches to the appropriate model class viaBaseModel.deserialize.- Parameters:
- model_file
str The path to the frozen model file.
- model_file
- deepmd.pt_expt.model.get_model(data: dict) deepmd.pt_expt.model.model.BaseModel[source]#
Get a model from a config dictionary.
- Parameters:
- data
dict The data to construct the model.
- data
- class deepmd.pt_expt.model.BaseModel[source]#
Bases:
make_base_model()Base class for pt_expt models.
Provides the plugin registry so that model classes can be registered with
@BaseModel.register("ener")etc. Deserialization is pure registry dispatch: descriptor-family-specific wire formats (e.g. the pt SeZM checkpoint layouts) are owned by the family’s registered model class (seedeepmd.pt_expt.model.dpa4_model.DPA4EnergyModel), never by this base.See also
deepmd.dpmodel.model.base_model.BaseBaseModelBackend-independent BaseModel class.
- class deepmd.pt_expt.model.NativeSpinEnergyModel(*args: Any, spin: deepmd.utils.spin.Spin, **kwargs: Any)[source]#
Bases:
make_native_spin_model(EnergyModel)pt_expt native-spin energy model.
make_native_spin_modelapplied to THIS backend’sEnergyModel(construction, output defs, serialization all come from the factory; the deserialize closure rebuilds through the pt_expt model class, so a registry round trip yields a realtorch.nn.Module), plus two torch-specific overrides:forward(): the pt_exptcall_commonproduces REAL autogradenergy_derv_r/energy_derv_r_mag/energy_derv_c_redutensors, unlike the dpmodel factory’s energy-onlycall(which is restricted toforce/force_mag/virialasNoneplaceholders because dpmodel has no autograd).forward_lower_graph_exportable(): the graph-spin.pt2positional ABI (spinat index 10) over the inheritedforward_common_lower_graph_exportable.
- forward(coord: torch.Tensor, atype: torch.Tensor, spin: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Return native-spin model predictions with public output keys.
- Parameters:
- coord
The coordinates of the atoms. shape: nf x (nloc x 3)
- atype
The type of atoms. shape: nf x nloc
- spin
The per-local-atom spin. shape: nf x (nloc x 3)
- box
The simulation box. shape: nf x 9
- fparam
frame parameter. nf x ndf
- aparam
atomic parameter. nf x nloc x nda
- do_atomic_virial
If calculate the atomic virial.
- charge_spin
Frame-level charge/spin conditioning, shape nf x 2. Forwarded to the backbone like every other conditioning input; native spin and charge-spin FiLM combine freely (DPA4 declares both capabilities).
- Returns:
ret_dictThe result dict with keys
atom_energy,energy,force,force_mag,virial,mask_mag, and (whendo_atomic_virial)atom_virial.forceandforce_magare real autograd tensors (-dE/dcoordand-dE/dspin), NOT placeholders.
- forward_ragged(coord: torch.Tensor, atype: torch.Tensor, n_node: torch.Tensor, spin: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Return native-spin predictions on a flat, frame-segmented node axis.
- forward_lower_graph_exportable(atype: torch.Tensor, n_node: torch.Tensor, n_local: torch.Tensor, edge_index: torch.Tensor, edge_vec: torch.Tensor, edge_mask: torch.Tensor, destination_order: torch.Tensor, destination_row_ptr: torch.Tensor, source_order: torch.Tensor, source_row_ptr: torch.Tensor, spin: torch.Tensor, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, charge_spin: torch.Tensor | None = None, do_atomic_virial: bool = False, destination_sorted: bool = False, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace the graph-spin lower into an exportable module.
THIS METHOD OWNS the positional
.pt2ABI for graph-spin models (mirrored verbatim by the C++ / serialization seams):spinsits at index 10, right after the sharedNeighborGraphCSR block and before the conditionalfparam/aparamtail; the conditionalcharge_spintail follows at index 13 (combined native-spin + charge-spin FiLM models, review 3638047227;Noneotherwise).forward_lower_graph_exportable_with_comm()extends this SAME prefix with the 8 comm tensors for multi-rank.Two-layer make_fx trace, mirroring
forward_lower_graph_exportable(): the inner layer (the inheritedforward_common_lower_graph_exportable()) tracesforward_common_lower_graphwithspinas a SECOND autograd leaf next toedge_vec(charge_spinis a frame-level conditioning input, not a leaf); this outer layer re-traces with the PUBLIC positional ABI above and translates the internal fitting keys to the public output keys via the shared_translate_eager_call()(the same single owner as the eagerforward(), somask_magis emitted here too).- Parameters:
- atype
(N,) flat local-plus-halo atom types,
N == sum(n_node).- n_node
(nf,) per-frame total node counts.
- n_local
(nf,) per-frame owned node counts.
- edge_index
(2, E)
[src, dst]edge endpoints (flat local indices).- edge_vec
(E, 3) neighbor-minus-center edge vectors (sample for tracing).
- edge_mask
(E,) valid-edge mask (sample for tracing).
- destination_order
(E,) destination-grouped edge permutation.
- destination_row_ptr
(N + 1,) destination CSR offsets.
- source_order
(E,) source-grouped edge permutation.
- source_row_ptr
(N + 1,) source CSR offsets.
- spin
(N, 3) per-node native spin (sample for tracing). ALWAYS present in this ABI, unlike the energy model’s optional
charge_spin.- fparam
Frame parameter,
(nf, ndf), orNonewhendim_fparam == 0.- aparam
Atomic parameter,
(N, nda), orNonewhendim_aparam == 0.- charge_spin
Frame-level charge/spin FiLM conditioning,
(nf, dim_chg_spin), orNonewhen the descriptor has noadd_chg_spin_ebd(conditional tail, slot 13).- do_atomic_virial
Whether to also return
atom_virial.- destination_sorted
Static export-time assertion that the payload is destination-major and
destination_orderis identity.- **make_fx_kwargs
Extra keyword arguments forwarded to
make_fx(e.g.tracing_mode="symbolic").
- Returns:
torch.nn.ModuleA traced module whose
forwardaccepts(atype, n_node, n_local, edge_index, edge_vec, edge_mask, destination_order, destination_row_ptr, source_order, source_row_ptr, spin, fparam, aparam, charge_spin)and returns a dict with the public keysatom_energy,energy,force,force_mag,virial,mask_mag, and (whendo_atomic_virial)atom_virial.
- forward_lower_canonical_graph_exportable(atype: torch.Tensor, n_node: torch.Tensor, n_local: torch.Tensor, source: torch.Tensor, edge_vec: torch.Tensor, destination_row_ptr: torch.Tensor, source_row_ptr: torch.Tensor, source_order: torch.Tensor, spin: torch.Tensor, *, do_atomic_virial: bool, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace the compact canonical spin lower into an exportable module.
THIS METHOD OWNS the positional
.pt2ABI for compact canonical spin models (mirrored verbatim by the C++ / serialization seams):spinsits at index 8, directly after the dual-CSR block, which is the same placement rule the graph ABI uses at index 10. The compact ABI has no conditional tail, so index 8 is the last slot.The magnetic force is a value here rather than an autograd result: the fused operator emits the on-site half from the node kernel and the neighbour half per edge, and the deployment path reduces the second onto source nodes.
mask_magis derived from the types by the same single owner the eager translation uses.- Parameters:
- atype, n_node, n_local, source, edge_vec
Compact graph node and edge tensors.
- destination_row_ptr, source_row_ptr, source_order
Compact dual-CSR topology.
- spin
(N, 3)per-node moment. Ghost rows carry their owner’s moment.- do_atomic_virial
Whether the traced output includes per-node virial.
- **make_fx_kwargs
Additional arguments passed to
make_fx().
- Returns:
torch.nn.ModuleTraced nine-input compact deployment module whose output dict adds
force_magandmask_magto the spin-free key set.
- forward_lower_graph_exportable_with_comm(atype: torch.Tensor, n_node: torch.Tensor, n_local: torch.Tensor, edge_index: torch.Tensor, edge_vec: torch.Tensor, edge_mask: torch.Tensor, destination_order: torch.Tensor, destination_row_ptr: torch.Tensor, source_order: torch.Tensor, source_row_ptr: torch.Tensor, spin: torch.Tensor, fparam: torch.Tensor | None, aparam: torch.Tensor | None, charge_spin: torch.Tensor | None, send_list: torch.Tensor, send_proc: torch.Tensor, recv_proc: torch.Tensor, send_num: torch.Tensor, recv_num: torch.Tensor, communicator: torch.Tensor, nlocal: torch.Tensor, nghost: torch.Tensor, do_atomic_virial: bool = False, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace the multi-rank graph-spin lower into an exportable module.
The with-comm counterpart of
forward_lower_graph_exportable(): same positional prefix,spinstill at index 10, then the 8 comm tensors appended after the conditionalfparam/aparam/charge_spintail (indices 14-21) – exactly howforward_lower_graph_exportable_with_comm()appends them for the energy model.spinis the EXTENDED per-node spin(N, 3): ghost rows carry their owner’s spin, delivered by the LAMMPSspforward-comm before the call, so the descriptor’s spin embedding sees the same value on every rank that holds the node. The per-block ghost FEATURE refresh ridesdeepmd_export::border_opexactly as in the energy model; spin needs no border exchange of its own because it is an input, not a derived feature.Single make_fx trace (the energy with-comm precedent), unlike the two-layer trace of the non-comm spin path: the comm-dict packing, the
forward_common_lower_graphcall withspinas a second autograd leaf, and the public-key translation all live in one tracedfn.- Parameters:
- atype, n_node, n_local, edge_index, edge_vec, edge_mask, destination_order, destination_row_ptr, source_order, source_row_ptr, spin, fparam, aparam, charge_spin
- send_list, send_proc, recv_proc, send_num, recv_num, communicator, nlocal, nghost
The 8 comm tensors, packed into
comm_dictinside the traced function. Same runtime device contract as the energy model’s: ALL 8 stay on CPU (host control metadata forborder_op), while the device-side owned count is the separaten_localinput at slot 2.- do_atomic_virial
Whether to also return
atom_virial.- **make_fx_kwargs
Extra keyword arguments forwarded to
make_fx.
- Returns:
torch.nn.ModuleA traced module accepting the 22-input ABI above and returning the same public keys as
forward_lower_graph_exportable()(atom_energy,energy,force,force_mag,virial,mask_mag, plusatom_virialwhen requested).
- class deepmd.pt_expt.model.PolarModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPPolarModel_Common methods for DP models.
This class provides common functionality for DeepPot models, including neighbor selection updates and fitting network access.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Default forward delegates to call().
Subclasses (e.g. EnergyModel) override this with output translation.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
- class deepmd.pt_expt.model.PropertyModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPPropertyModel_Common methods for DP models.
This class provides common functionality for DeepPot models, including neighbor selection updates and fitting network access.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Default forward delegates to call().
Subclasses (e.g. EnergyModel) override this with output translation.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
- class deepmd.pt_expt.model.SpinEnergyModel(backbone_model: deepmd.dpmodel.atomic_model.dp_atomic_model.DPAtomicModel, spin: deepmd.utils.spin.Spin)[source]#
Bases:
deepmd.pt_expt.model.spin_model.SpinModelA spin model for energy.
- translated_output_def() dict[str, Any][source]#
Get the translated output definition.
Maps internal output names to user-facing names, e.g.
energy->atom_energy,energy_redu->energy,energy_derv_r->force,energy_derv_r_mag->force_mag.
- forward(coord: torch.Tensor, atype: torch.Tensor, spin: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, extended_spin: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
- forward_lower_exportable(extended_coord: torch.Tensor, extended_atype: torch.Tensor, extended_spin: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None, **make_fx_kwargs: Any) torch.nn.Module[source]#
Trace
forward_lowerinto an exportable module.Delegates to
forward_common_lower_exportablefor tracing, then translates the internal keys to theforward_lowerconvention.- Parameters:
- extended_coord, extended_atype, extended_spin, nlist, mapping, fparam, aparam, do_atomic_virial, charge_spin
Sample inputs with representative shapes (used for tracing).
- **make_fx_kwargs
Extra keyword arguments forwarded to
make_fx(e.g.tracing_mode="symbolic").
- Returns:
torch.nn.ModuleA traced module whose
forwardaccepts(extended_coord, extended_atype, extended_spin, nlist, mapping, fparam, aparam, charge_spin)and returns a dict with the same keys asforward_lower.
- class deepmd.pt_expt.model.UniMolPretrainModel(*args: Any, **kwargs: Any)[source]#
Bases:
deepmd.dpmodel.model.dp_model.DPModelCommon,DPUniMolPretrainModel_Uni-Mol v1 self-supervised pretraining on the PyTorch-Exportable backend.
- forward(coord: torch.Tensor, atype: torch.Tensor, box: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Evaluate the pretraining heads on a frame.
- Raises:
ValueErrorIf a periodic cell is supplied; Uni-Mol is molecular.
- forward_lower(extended_coord: torch.Tensor, extended_atype: torch.Tensor, nlist: torch.Tensor, mapping: torch.Tensor | None = None, fparam: torch.Tensor | None = None, aparam: torch.Tensor | None = None, do_atomic_virial: bool = False, comm_dict: dict[str, torch.Tensor] | None = None, charge_spin: torch.Tensor | None = None) dict[str, torch.Tensor][source]#
Evaluate the pretraining heads on an extended frame.
- translated_output_def() dict[str, deepmd.dpmodel.output_def.OutputVariableDef][source]#
The head outputs, passed through under their own names.