Dosu LogoDosu Logo
Ask
Join our Discord
DeePMD-kitPublic
DeepModeling
Documents
CUDA Kernel Compatibility
DeePMD-kit Configuration
DeePMD-kit Long-Range and Surface Modeling
DeePMD-kit Model Formats
DeePMD-kit Precision Control
DPA1 Inference
DPDispatcher Task Grouping
dpgen Surface Workflows
Force Loss Computation
LAMMPS DeepMD Integration
Model Reuse in dpgen
Multi-Component System Workflows
Neighbor List Backend Integration
DocumentsDeePMD-kit
DeePMD-kit Precision Control
DeePMD-kit Precision Control
Type
Topic
Status
Published
Created
Aug 1, 2026
Updated
Aug 1, 2026

DeePMD-kit Precision Control#

Overview#

DeePMD-kit exposes two independent layers of floating-point precision control:

  1. DP_INTERFACE_PREC (environment variable) — governs the interface precision: the environmental matrix, descriptor statistics, fitting normalisation parameters, and the data boundary between components.
  2. precision (per-network training parameter) — governs the dtype used inside each neural network (descriptor, fitting net, type embedding) and subsequent operations on its output.

The reduced scalar output (e.g., total energy) is always float64, regardless of either setting .


DP_INTERFACE_PREC Environment Variable#

Set at Python import time in deepmd/env.py.

ValueGLOBAL_NP_FLOAT_PRECISIONGLOBAL_ENER_FLOAT_PRECISIONglobal_float_prec
high (default)np.float64np.float64"double"
lownp.float32np.float64"float"

Any other value raises a RuntimeError .

GLOBAL_NP_FLOAT_PRECISION is the dtype used for the environmental matrix, descriptor mean/std statistics (davg/dstd), and atom-energy biases. GLOBAL_ENER_FLOAT_PRECISION remains float64 even in low mode, keeping reduced-energy outputs in double precision.

The "default" precision string in PRECISION_DICT resolves to GLOBAL_NP_FLOAT_PRECISION at import time , so changing DP_INTERFACE_PREC after import has no effect.


PRECISION_DICT — the Central Dtype Registry#

Defined in deepmd/dpmodel/common.py, this dict maps human-readable precision strings to NumPy (or ml_dtypes) dtype objects:

Stringdtype
"float16" / "half"np.float16
"float32" / "single"np.float32
"float64" / "double"np.float64
"bfloat16"ml_dtypes.bfloat16
"default"← GLOBAL_NP_FLOAT_PRECISION
"int32" / "int64" / "bool"integer/bool types

DEFAULT_PRECISION is hard-coded to "float64" and is used as the default value for all per-network precision constructor arguments.


Per-Network precision Parameter#

Each major model component accepts a precision string in its constructor. The string is validated against PRECISION_DICT and resolved to a dtype:

  • Descriptor (e.g., DescrptSeA, DPA-1, DPA-2, DPA-3): controls dtype for davg/dstd statistics arrays and post-network operations.
  • Fitting net (GeneralFitting): controls dtype for frame/atomic parameter statistics (fparam_avg, aparam_inv_std, etc.) and layer weight initialisation. Stored as both self.precision (string, for serialization) and self.prec = PRECISION_DICT[self.precision.lower()] (dtype, for array ops).
  • Type embedding (TypeEmbedNet): controls dtype for the embedding table and eye-matrix construction during type-map changes.

The precision string propagates from these top-level components down through FittingNet/EmbeddingNet/NativeLayer constructors unchanged, so all weight tensors in a network share the same dtype.

cast_precision decorator#

cast_precision in common.py is a method decorator used to bridge the interface (global) precision and per-network precision:

  • Casts inputs from "global" → self.precision before the forward pass.
  • Casts outputs from self.precision → "global" after the forward pass.
  • Only affects tensors whose current dtype matches the source precision; integer/bool arrays are left untouched.

The get_xp_precision helper translates precision strings to array-API–compatible dtype objects (supporting NumPy, JAX, and other backends).


Recommended Configurations#

From the official precision docs :

Use caseDP_INTERFACE_PRECper-network precision
Default / highest accuracyhighfloat64
Faster training / lower memoryhighfloat32

Note: The Python and C++ inference interfaces accept both float64 and float32 inputs regardless of the model's internal precision. MD programs such as LAMMPS operate in float64 .


Key Source Files#

FileRole
deepmd/env.pyReads DP_INTERFACE_PREC; sets GLOBAL_NP_FLOAT_PRECISION, GLOBAL_ENER_FLOAT_PRECISION, global_float_prec
deepmd/dpmodel/common.pyPRECISION_DICT, DEFAULT_PRECISION, cast_precision, get_xp_precision
deepmd/dpmodel/fitting/general_fitting.pyConsumes precision in fitting net construction and array initialization
doc/model/precision.mdOfficial documentation explaining the two-layer precision model
deepmd/dpmodel/utils/network.pyNativeLayer, EmbeddingNet, FittingNet — propagate precision to weight tensors