Skip to content

Commit

Permalink
docs: document the floating-point precision of the model (#4240)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added a new section on `precision` in the documentation, enhancing
navigation.
- Introduced detailed guidelines on floating-point precision settings
for the model.
- Included structured instructions for creating models with the PyTorch
backend.

- **Documentation**
- Expanded troubleshooting documentation related to model precision
issues, including data accuracy and training recommendations.
- Enhanced guidelines for integrating new components into user
configurations and ensuring model integrity across different backends.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored Oct 28, 2024
1 parent 8f546cf commit 40b3ea1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
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

0 comments on commit 40b3ea1

Please sign in to comment.