Skip to content
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

store energy bias with interface precision #2174

Merged
merged 3 commits into from
Dec 13, 2022

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Dec 9, 2022

This PR moves energy biases out of NN for all situations and stores them with interface precision.

When using the FP64 precision interface and FP32 precision NN, this patch can improve the accuracy of the atomic energy when it has a large absolute value. For example, when the atomic energy is 11451.41234567 eV, the FP32 value is 11451.412 eV (places=3); but if we have an FP64 bias of 11450.000000 eV, the NN only needs to fit 1.41234567 eV, and the FP32 value is 1.4123456 eV (places=7).

njzjz added 2 commits December 9, 2022 15:04
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
@njzjz
Copy link
Member Author

njzjz commented Dec 9, 2022

@wanghan-iapcm @denghuilu @iProzd Discussion is welcome.

Copy link
Collaborator

@wanghan-iapcm wanghan-iapcm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see, apart from the precision of the bias_atom_e, the implement by this PR should be equivalent to the old one. Am I correct?

@njzjz
Copy link
Member Author

njzjz commented Dec 12, 2022

As far as I see, apart from the precision of the bias_atom_e, the implement by this PR should be equivalent to the old one. Am I correct?

This PR brings the implementation for the type embedding in #1592 and #1866 to other cases.

Before, the bias is stored in the bias of the last layer in the fitting network. This PR creates a new constant variable (not trainable) for it, as we did for the type embedding in #1592 and #1866.

deepmd/model/multi.py Show resolved Hide resolved
deepmd/fit/ener.py Show resolved Hide resolved
@wanghan-iapcm
Copy link
Collaborator

As far as I see, apart from the precision of the bias_atom_e, the implement by this PR should be equivalent to the old one. Am I correct?

This PR brings the implementation for the type embedding in #1592 and #1866 to other cases.

Before, the bias is stored in the bias of the last layer in the fitting network. This PR creates a new constant variable (not trainable) for it, as we did for the type embedding in #1592 and #1866.

I want to confirm for the standard cases (like se_a) the PR gives equivalent result as the old implementation.

@njzjz
Copy link
Member Author

njzjz commented Dec 12, 2022

I want to confirm for the standard cases (like se_a) the PR gives equivalent result as the old implementation.

cd examples/water/se_e2_a
dp train input.json

devel:

#  step      rmse_val    rmse_trn    rmse_e_val  rmse_e_trn    rmse_f_val  rmse_f_trn         lr
      0      2.65e+01    2.76e+01      6.77e-01    6.79e-01      8.38e-01    8.71e-01    1.0e-03
    100      1.00e+01    9.86e+00      2.62e-01    2.53e-01      3.17e-01    3.11e-01    1.0e-03
    200      6.61e+00    6.83e+00      9.79e-02    9.06e-02      2.09e-01    2.16e-01    1.0e-03
    300      5.93e+00    5.74e+00      2.10e-02    1.91e-02      1.88e-01    1.81e-01    1.0e-03
    400      6.82e+00    6.73e+00      1.78e-01    1.80e-01      2.15e-01    2.13e-01    1.0e-03
    500      5.44e+00    5.26e+00      4.11e-02    4.33e-02      1.72e-01    1.66e-01    1.0e-03
    600      5.06e+00    5.58e+00      5.22e-02    5.26e-02      1.60e-01    1.76e-01    1.0e-03
    700      5.33e+00    5.23e+00      1.96e-02    1.76e-02      1.69e-01    1.65e-01    1.0e-03
    800      4.64e+00    4.29e+00      5.06e-02    5.19e-02      1.47e-01    1.36e-01    1.0e-03
    900      4.85e+00    4.44e+00      1.38e-02    1.12e-02      1.53e-01    1.41e-01    1.0e-03
   1000      4.66e+00    4.02e+00      1.19e-03    1.78e-03      1.48e-01    1.27e-01    1.0e-03

This PR:

#  step      rmse_val    rmse_trn    rmse_e_val  rmse_e_trn    rmse_f_val  rmse_f_trn         lr
      0      2.65e+01    2.76e+01      6.77e-01    6.79e-01      8.38e-01    8.71e-01    1.0e-03
    100      1.00e+01    9.86e+00      2.62e-01    2.53e-01      3.17e-01    3.11e-01    1.0e-03
    200      6.61e+00    6.83e+00      9.79e-02    9.06e-02      2.09e-01    2.16e-01    1.0e-03
    300      5.93e+00    5.74e+00      2.10e-02    1.91e-02      1.88e-01    1.81e-01    1.0e-03
    400      6.82e+00    6.73e+00      1.78e-01    1.80e-01      2.15e-01    2.13e-01    1.0e-03
    500      5.44e+00    5.26e+00      4.11e-02    4.33e-02      1.72e-01    1.66e-01    1.0e-03
    600      5.06e+00    5.58e+00      5.22e-02    5.26e-02      1.60e-01    1.76e-01    1.0e-03
    700      5.33e+00    5.23e+00      1.96e-02    1.76e-02      1.69e-01    1.65e-01    1.0e-03
    800      4.64e+00    4.29e+00      5.06e-02    5.19e-02      1.47e-01    1.36e-01    1.0e-03
    900      4.85e+00    4.44e+00      1.38e-02    1.12e-02      1.53e-01    1.41e-01    1.0e-03
   1000      4.66e+00    4.02e+00      1.19e-03    1.78e-03      1.48e-01    1.27e-01    1.0e-03

The outputs are the same.

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
@wanghan-iapcm wanghan-iapcm merged commit 3c77e1b into deepmodeling:devel Dec 13, 2022
mingzhong15 pushed a commit to mingzhong15/deepmd-kit that referenced this pull request Jan 15, 2023
This PR moves energy biases out of NN for all situations and stores them
with interface precision.

When using the FP64 precision interface and FP32 precision NN, this
patch can improve the accuracy of the atomic energy when it has a large
absolute value. For example, when the atomic energy is 11451.41234567
eV, the FP32 value is 11451.412 eV (places=3); but if we have an FP64
bias of 11450.000000 eV, the NN only needs to fit 1.41234567 eV, and the
FP32 value is 1.4123456 eV (places=7).

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants