Skip to content

Commit

Permalink
Merge branch 'refactor_property' of github.com:Chengqian-Zhang/deepmd…
Browse files Browse the repository at this point in the history
…-kit into refactor_property
  • Loading branch information
Chengqian-Zhang committed Dec 20, 2024
2 parents f07f1b2 + 4613425 commit 120d9d8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 1 addition & 3 deletions deepmd/pt/model/atomic_model/base_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,7 @@ def change_out_bias(
self._store_out_stat(delta_bias, out_std, add=True)
elif bias_adjust_mode == "set-by-statistic":
property_name = (
self.fitting_net.property_name
if "property" in self.bias_keys
else None
self.fitting_net.property_name if "property" in self.bias_keys else None
)
bias_out, std_out = compute_output_stats(
sample_merged,
Expand Down
11 changes: 7 additions & 4 deletions doc/model/train-fitting-property.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The JSON of `property` type should be provided like

## Loss

DeepProperty supports trainings of the global system (one or more global labels are provided in a frame). For example, when fitting `property`, each frame will provide a `1 x task_dim` vector which gives the fitting properties.
DeepProperty supports trainings of the global system (one or more global labels are provided in a frame). For example, when fitting `property`, each frame will provide a `1 x task_dim` vector which gives the fitting properties.

The loss section should be provided like

Expand All @@ -64,6 +64,7 @@ The loss section should be provided like
The label should be named `{property_name}.npy/raw`, `property_name` is defined by `fitting_net/property_name` in `input.json`.

To prepare the data, you can use `dpdata` tools, for example:

```
import dpdata
import numpy as np
Expand Down Expand Up @@ -133,7 +134,7 @@ dp --pt train input.json
The detailed loss can be found in `lcurve.out`:

```
# step mae_val mae_trn lr
# step mae_val mae_trn lr
# If there is no available reference data, rmse_*_{val,trn} will print nan
1 2.72e-02 2.40e-02 2.0e-04
100 1.79e-02 1.34e-02 2.0e-04
Expand Down Expand Up @@ -183,10 +184,12 @@ for `*.property.out.*`, it contains matrix with shape of `(2, task_dim)`,
```

## Data Normalization
When `fitting_net/type` is `ener`, the energy bias layer “$e_{bias}$” adds a constant bias to the atomic energy contribution according to the atomic number.i.e.,

When `fitting_net/type` is `ener`, the energy bias layer “$e_{bias}$” adds a constant bias to the atomic energy contribution according to the atomic number.i.e.,
$$e_{bias} (Z_i) (MLP(D_i))= MLP(D_i) + e_{bias} (Z_i)$$

But when `fitting_net/type` is `property`. The property bias layer is used to normalize the property output of the model.i.e.,
$$p_{bias} (MLP(D_i))= MLP(D_i) * std+ mean$$

1. `std`: The standard deviation of the property label
2. `mean`: The average value of the property label
2. `mean`: The average value of the property label
3 changes: 2 additions & 1 deletion examples/property/train/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Some explanations of the parameters in `input.json`:

1. `fitting_net/property_name` is the name of the property to be predicted. It should be consistent with the property name in the dataset. In each system, code will read `set.*/{property_name}.npy` file as prediction label if you use NumPy format data.
2. `fitting_net/task_dim` is the dimension of model output. It should be consistent with the property dimension in the dataset, which means if the shape of data stored in `set.*/{property_name}.npy` is `batch size * 3`, `fitting_net/task_dim` should be set to 3.
3. `fitting/intensive` indicates whether the fitting property is intensive. If `intensive` is `true`, the model output is the average of the property contribution of each atom. If `intensive` is `false`, the model output is the sum of the property contribution of each atom.
3. `fitting/intensive` indicates whether the fitting property is intensive. If `intensive` is `true`, the model output is the average of the property contribution of each atom. If `intensive` is `false`, the model output is the sum of the property contribution of each atom.
4 changes: 3 additions & 1 deletion examples/property/train/input_torch.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
},
"loss": {
"type": "property",
"metric": ["mae"],
"metric": [
"mae"
],
"loss_func": "smooth_mae",
"beta": 1.0,
"_comment": " that's all"
Expand Down

0 comments on commit 120d9d8

Please sign in to comment.