feat(stat): isolated-atom energy reference through preset_out_bias and vacuum_ref (#6022)
preset_out_biasdocuments that the bias of an assigned atom type is set to the preset value. Inchange-by-statisticmode (fine-tuning,dp change-bias,change_bias_after_training) the preset was fed to the least-squares fit as if it were a shift, so an assigned type ended atpretrained_bias + preset, the residual fitted for the other types subtractednatoms * presetinstead ofnatoms * (preset - pretrained_bias), and every further call accumulated the preset again. The four copies of the mode branch (the pt, pd and dpmodel atomic models and the pt model wrapper) shared the defect.This PR makes the preset the bias of an assigned output in every mode, adds bundled tables of isolated-atom energies so that a table is named instead of typed, and adds the fitting option
vacuum_ref, which references the network output of every atom to the output the same network gives an isolated atom of its type. With both options the energy of an atom without neighbors is exactly its preset bias, whatever the network parameters are, so the dissociation limit of an energy model is pinned to the isolated-atom energies of the reference calculation.Changes
preset_out_bias
- An output with at least one assigned type is fixed by the preset alone. Every element that occurs in the training data must be assigned (a missing element is an error), the assigned types take the preset value in both
set-by-statisticandchange-by-statistic, a type absent from the data gets a zero bias at initialization and keeps its stored bias at fine-tuning, and no statistics are computed for, read from or written to the cache for such an output; its output std keeps its stored value. The types excluded byatom_exclude_types(the virtual types of a spin model, for example) need no preset, and elements outside thetype_mapare ignored. Outputs without a preset are fitted as before.- Four forms are accepted: a dict keyed by element symbol, the name of a bundled table, the path of a JSON file holding such a dict, and a list with one entry per type of the
type_map(nullleaves a type unassigned; the form for tensor outputs). A table is resolved once when the input is processed, in single-task configurations, in every branch of a multi-task configuration and for a preset written next tomodel_dict, and its values are stored in the model, so a trained model depends neither on the file nor on the bundled data.- Bundled tables live in
deepmd/utils/preset_out_bias_tables.json, one entry per name with itssourceand itsvalueskeyed by element symbol, so further tables can be added without code changes. The entries are the isolated-atom reference energies of the UMA training tasks published with fairchem (configs/uma/training_release/element_refs/iso_atom_elem_refs.yaml, MIT license), in eV:omat24(89 elements),omol25(83, neutral atoms),omc25(94),odac25(94) andoc20(97). A bundled name takes precedence over a file of the same name.- All preset handling lives in
deepmd.utils.preset_out_bias(normalization, table resolution, remapping, validation, per-type rows), shared by the pt, pd and dpmodel atomic models; the per-backendchange_out_biasbodies reduce to the shared helper plus the fit of the remaining outputs, and_store_out_statwrites bias rows without touching the std.change_type_mapremaps the preset together with the stored bias; an output the model does not produce, a preset on a fitting whose statistics do not distinguish atom types, and an assigned preset on a dipole model are rejected.- The dpmodel factory (pt_expt, jax) and the pt linear and ZBL builders forward the option; the pt_expt DPA4/SeZM builder accepts it.
vacuum_ref(fitting option, default off)
- The atomic energy becomes
E_i = bias(t_i) + f(x_i; c_i) - f(x_vac(t_i); c_i), wherex_vac(t)is the descriptor of an isolated atom of typetcomputed by the same descriptor with the current parameters andc_iis the atom’s own conditioning (frame parameters, atomic parameters, case embedding). Without frame or atomic parameters the reference is one row per type; otherwise the reference rows follow the atoms. The reference is evaluated at every training step, so it follows the parameters; forces and virials are unchanged.- The reference atom is the neutral atom in its ground state: with charge/spin conditioning it carries zero charge and the ground-state multiplicity of the element, and with native spin a spin vector of one Bohr magneton per unpaired electron (
deepmd.utils.vacuum_reference, from the electron-configuration table); charged, excited or differently magnetized isolated atoms keep the deviation the network learns. The condition tables are built once per type map at the atomic model (pt: buffers ofSeZMAtomicModel; dpmodel: numpy attributes ofDPAtomicModel, non-persistent buffers on pt_expt).- Routes: on pt_expt every graph-native model (DPA1, DPA2, DPA4, DPA4C) carries one isolated node per type through the same forward as single-node frames appended to the flat node axis (
append_isolated_frames); on the PyTorch backend the SeZM edge route appends the reference nodes inforward_with_edges. The dense route evaluates single-atom frames.- Freezing removes the reference atoms from every exported model: the vacuum descriptor of every type is evaluated once on the export object and folded into the fitting bias, or, for a fitting with frame or atomic parameters whose reference varies between atoms, stored in the fitting as a deployment constant (
vacuum_table, kept out of checkpoints and serialization) from which the fitting evaluates its references. The pt_expt export folds inside_trace_and_export_impl, sodp freeze,.pte/.pt2conversion andchange-biason frozen artifacts all resolve the reference on the object they export, and the archive keeps the live model. A SeZM checkpoint indensmode is rejected by the freeze: the DeNS head serves training alone and is not exported.- The fused pt_expt fitting operator and the fused energy/force route take the reference through the per-type bias (
graph_fitting(fit, descriptor, atype, atom_bias)); a fitting whose reference varies between atoms is served by the autograd route.- Scope:
vacuum_refis available for DPA4/SeZM on the PyTorch backend and for the graph-native models on pt_expt. The TensorFlow and Paddle fittings reject a serializedvacuum_ref: truemodel withNotImplementedErrorinstead of ignoring the option.atom_eneris unchanged on every backend; a fitting rejects the two options together.- Documentation: the section “Isolated-atom energy reference” of
doc/model/train-energy.md, the argcheck entriespreset_out_biasandvacuum_ref, and the examplesexamples/water/dpa4/input_e0.json(single-task) andexamples/water/dpa4/input_multitask_e0.json(per-branch presets).Breaking changes
- Reusing output-statistics caches requires a per-output preset record matching the current constraints. Existing caches without that record are recomputed in update mode; read-only users must regenerate the output statistics once with
stat_file_mode: update. This cache validation change does not alter model or checkpoint serialization.- A partial preset is no longer fitted around: if an output assigns any type, every element observed in the data must be assigned, otherwise the statistics raise. Previously the unassigned observed types were fitted with least squares around the preset.
- With
set-by-statistic, the types of an assigned output that do not occur in the data get a zero bias instead of a fitted one, and the output std of such an output keeps its initial value; preset outputs never read or write the output-statistics cache.DescrptSeZM.forward_with_edgestakesvacuum_conditions: dict | None(the reference-atom inputs) and returns(descriptor, latent, vacuum);deepmd.pt_expt.kernels.graph_fitting.graph_fittingtakes the per-type bias explicitly.- The fitting serialization of every backend includes
vacuum_ref, and its@versionis bumped (general fitting 4 to 5, polarizability 5 to 6, property 6 to 7, population 4 to 5); older dictionaries without the key load withvacuum_ref: false, and the TensorFlow and Paddle fittings emitfalseand rejecttruebehind the version check.compute_stats_do_not_distinguish_typesloses its unusedassigned_biasparameter.Validation
- Preset semantics:
source/tests/common/test_preset_out_bias.py(forms, bundled tables, resolution in single-task and multi-task configurations, rows, excluded and unknown types), the pt, dpmodel and pdtest_atomic_model_global_stat.py(set→change→changewith an assigned output, the rejection of an unassigned observed element, the output std under a full preset, a spin model with a dict preset, presets that need no data,change_type_map), the jax end-to-end test and the argcheck example inputs.- Reference identity
E_i = bias + f(x_i) - f(x_vac)and “an isolated atom gives exactly its bias”, in float64 to 1e-10:source/tests/pt/model/test_fitting_vacuum_ref.py(the full(fparam, aparam, case_embd, aparam_as_mask) × mixed_typesproduct,torch.jit.script,default_fparam, fold and stored table, state-dict round trip,change_type_map),source/tests/common/dpmodel/test_fitting_invar_fitting.py,test_fitting_call_graph.py,test_vacuum_ref_model.py(se_e2_a dense and DPA1 graph routes),source/tests/pt_expt/fitting/test_dpa4_ener.py.source/tests/tf/test_fitting_vacuum_ref.pychecks that the TensorFlow fittings reject a serializedvacuum_refand load a dictionary of the previous version; the Paddle, dpmodel and PyTorch serialization tests do the same.- Reference rows through the descriptors:
source/tests/pt/model/test_sezm_vacuum_ref.py(plain, charge/spin conditioning with native spin, DeNS, forces unchanged, fold, fused training kernels under AMP),source/tests/pt/model/test_sezm_parallel.py(reference rows under the LAMMPS-style communication path),source/tests/pt_expt/model/test_dpa4_vacuum_ref.py(graph route with charge/spin and native spin, a padded node axis, dense and graph routes agree to 1e-12,.pt2and.ptefreezes with and without frame parameters, the archive keeps the live model),source/tests/pt_expt/model/test_fused_vacuum_ref.py(fused energy/force route of DPA1 and compressed DPA4C equals autograd exactly, autograd fallback with frame parameters),source/tests/pt/model/test_sezm_vacuum_freeze.py(.pt2freezes on CPU and CUDA targets, with and without frame parameters, adenscheckpoint is rejected).- End to end: the two example inputs train (single-task, multi-task, two-process DDP); a model frozen with
dp --pt freezegives an isolated O and H exactly their preset energies. Paddle is not installed here and the TensorFlow operators are not built; the pd and tf tests mirror pt and are verified by CI.Summary by CodeRabbit
New Features
Added flexible per-element output-bias presets, including bundled tables, JSON files, and element-mapped values.
Added isolated-atom (
vacuum_ref) energy references for supported energy models, including folding references during export.Added vacuum-reference support for DPA4/SeZM and native-spin workflows.
Added support for varying graph frame sizes and isolated reference frames.
Bug Fixes
Preset biases now validate observed types and remain fixed during statistical adjustments.
State-dependent statistics no longer incorrectly reuse cached results.
Improved model serialization and export consistency for bias and vacuum-reference settings.
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
DeePMD-kit
Start from a pretrained Deep Potential model, fine-tune it for your system, and deploy it at simulation scale.
Pretrained models · Fine-tuning · Documentation · Quick start · Model guide · Tutorials · Examples · Releases
DeePMD-kit turns quantum-mechanical reference data into fast, scalable interatomic potentials. Use it across molecular and materials science—from finite molecules and covalent systems to periodic solids and metals—and scale from laptop fine-tuning to distributed training and MPI-parallel molecular dynamics.
The DPA4 model family traces a Pareto frontier across Matbench Discovery CPS and saturated inference throughput.
⚡ Why DeePMD-kit
.pt2export, and MPI-enabled simulation.Backend and interface support varies by model and feature. The web documentation marks compatibility and limitations on each feature page.
🧭 Two starting points, one path to dynamics
flowchart LR A["Pretrained DPA4 model"] --> C["Fine-tune on target data"] B["Model configuration"] --> D["Train from scratch"] E["Target reference data"] --> C E --> D C --> F["Test, compress, export"] D --> F F --> G["Python and native APIs"] F --> H["Molecular dynamics"]dp test,dp freeze, backend conversion, embedding extraction, and supported compression paths.🚀 Start in minutes
DeePMD-kit requires Python 3.10 or later. The fastest installation path is:
The installation guide covers pip, conda-forge, containers, offline packages, GPU builds, LAMMPS, i-PI, and source installation.
Fine-tune a pretrained DPA4 model
Download a built-in checkpoint, start from its matching released training configuration, and fine-tune it on your target data. This example uses DPA4-Neo, one of the recommended general-purpose sizes:
The DPA4 OMat24 release provides Nano, Mini, Neo, Air, and Plus checkpoints together with their matching training configurations. The downloaded
input_finetune.jsonmatches the Neo checkpoint above; for another size or version, use the correspondingly named JSON file. Keep its completemodelsection unchanged, including the full-periodic-tabletype_map; replace the training and validation data, and use a smaller learning rate for fine-tuning. Then run:These are PyTorch single-task checkpoints, so no model branch selection is needed. They target inorganic materials in the OMat24 chemical space; validate accuracy before using them outside that domain.
The fine-tuning guide covers full-model adaptation. DPA-ADAPT reuses supported pretrained DPA representations for downstream property-prediction tasks.
Pretrained model names can also be resolved and cached automatically by Python:
Train a model from scratch
Training from scratch remains a first-class workflow for new architectures, fully custom systems, and physical targets without a suitable pretrained checkpoint. Clone the examples and start with the compact water system:
Ready-to-run inputs include:
For a guided end-to-end example, open the web quick-start notebook.
🧠 Choose a model family
For conservative energy/force interatomic potentials, start with the DPA4 family. The choice between its two primary models follows the constraint that matters most for your workload:
DPA4 uses the PyTorch backend (
dp --pt). DPA4C currently uses the PyTorch Exportable backend (dp --pt-expt); its compressed CUDA path requiresfloat32.For other physical targets, use the model guide to select a compatible model and backend. The guide also compares data formats, precision, compression, and deployment constraints.
For energy/force potentials, DPA4 and DPA4C span accuracy–throughput trade-offs for different deployment budgets.
🔬 Go beyond conventional force fields
Explore the complete set of models and physical targets in the web documentation.
🔌 Deploy into the scientific ecosystem
Inference interfaces
Simulation and workflow integrations
See the integration hub for maintained interfaces, third-party projects, supported scope, and installation guidance.
The native C and C++ interfaces load machine-learning backends as runtime plugins. Applications can therefore open the backend required by a model without directly linking every framework.
📚 Documentation and community
Citation
If DeePMD-kit contributes to published work, cite the general software paper that matches the version used and the method-specific papers listed in CITATIONS.bib:
License
DeePMD-kit is licensed under the GNU Lesser General Public License v3.0 or later.