Skip to content

docs: document the floating-point precision of the model #4240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/development/create-a-model-pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ class SomeAtomicModel(BaseAtomicModel, torch.nn.Module):
pass
```

### Floating-point precision

When creating a new component, the floating-point precision should obey the [Floating-point precision of the model](../model/precision.md) section.
In implementation, the component should

- store parameters in the component precision, except those for output normalization;
- store output normalization parameters in {py:data}`deepmd.pt.utils.env.GLOBAL_PT_FLOAT_PRECISION`;
- before input normalization, cast the input tensor to the component precision; before output normalization, cast the output tensor to the {py:data}`deepmd.pt.utils.env.GLOBAL_PT_FLOAT_PRECISION`.

## Register new arguments

To let someone uses your new component in their input file, you need to create a new method that returns some `Argument` of your new component, and then register new arguments. For example, the code below
Expand Down
1 change: 1 addition & 0 deletions doc/model/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Model
linear
pairtab
change-bias
precision
15 changes: 15 additions & 0 deletions doc/model/precision.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Floating-point precision of the model

The following options control the precision of the model:

- The environment variable {envvar}`DP_INTERFACE_PREC` controls the interface precision of the model, the descriptor, and the fitting, the precision of the environmental matrix, and the precision of the normalized parameters for the environmental matrix and the fitting output.
- The training parameters {ref}`precision <model[standard]/fitting_net[ener]/precision>` in the descriptor, the fitting, and the type embedding control the precision of neural networks in those components, and the subsequent operations after the output of neural networks.
- The reduced output (e.g. total energy) is always `float64`.

Usually, the following two combinations of options are recommended:

- Setting {envvar}`DP_INTERFACE_PREC` to `high` (default) and all {ref}`precision <model[standard]/fitting_net[ener]/precision>` options to `float64` (default).
- Setting {envvar}`DP_INTERFACE_PREC` to `high` (default) and all {ref}`precision <model[standard]/fitting_net[ener]/precision>` options to `float32`.

The Python and C++ inference interfaces accept both `float64` and `float32` as the input and output arguments, whatever the floating-point precision of the model interface is.
Usually, the MD programs (such as LAMMPS) only use `float64` in their interfaces.
1 change: 1 addition & 0 deletions doc/troubleshooting/precision.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ See [FAQ: How to tune Fitting/embedding-net size](./howtoset_netsize.md) for det

In some cases, one may want to use the FP32 precision to make the model faster.
For some applications, FP32 is enough and thus is recommended, but one should still be aware that the precision of FP32 is not as high as that of FP64.
See [Floating-point precision of the model](../model/precision.md) section for how to set the precision.

## Training

Expand Down