Skip to content

Commit 7dd7f6a

Browse files
authored
Merge branch 'devel' into devel
2 parents 9920e57 + e2b659a commit 7dd7f6a

17 files changed

Lines changed: 154 additions & 49 deletions

File tree

.github/workflows/build_wheel.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
# https://github.com/pypa/setuptools_scm/issues/480
7676
fetch-depth: 0
7777
- name: Install uv
78-
run: curl -LsSf https://astral.sh/uv/0.2.10/install.sh | sh
78+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
7979
if: runner.os != 'Linux'
8080
- uses: docker/setup-qemu-action@v3
8181
name: Setup QEMU
@@ -161,7 +161,7 @@ jobs:
161161
images: ghcr.io/deepmodeling/deepmd-kit
162162

163163
- name: Build and push Docker image
164-
uses: docker/build-push-action@v5
164+
uses: docker/build-push-action@v6
165165
with:
166166
context: source/install/docker
167167
push: ${{ github.repository_owner == 'deepmodeling' && github.event_name == 'push' && github.actor != 'dependabot[bot]' }}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
exclude: ^source/3rdparty
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
3131
# Ruff version.
32-
rev: v0.4.8
32+
rev: v0.4.9
3333
hooks:
3434
- id: ruff
3535
args: ["--fix"]

deepmd/pt/train/training.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
TensorLoss,
3232
)
3333
from deepmd.pt.model.model import (
34-
DOSModel,
3534
get_model,
3635
get_zbl_model,
3736
)
@@ -601,15 +600,13 @@ def single_model_finetune(
601600
_finetune_rule_single,
602601
_sample_func,
603602
):
604-
# need fix for DOSModel
605-
if not isinstance(_model, DOSModel):
606-
_model = _model_change_out_bias(
607-
_model,
608-
_sample_func,
609-
_bias_adjust_mode="change-by-statistic"
610-
if not _finetune_rule_single.get_random_fitting()
611-
else "set-by-statistic",
612-
)
603+
_model = _model_change_out_bias(
604+
_model,
605+
_sample_func,
606+
_bias_adjust_mode="change-by-statistic"
607+
if not _finetune_rule_single.get_random_fitting()
608+
else "set-by-statistic",
609+
)
613610
return _model
614611

615612
if not self.multi_task:

deepmd/pt/utils/stat.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ def compute_output_stats_global(
399399
model_pred: Optional[Dict[str, np.ndarray]] = None,
400400
):
401401
"""This function only handle stat computation from reduced global labels."""
402+
# return directly if model predict is empty for global
403+
if model_pred == {}:
404+
return {}, {}
405+
402406
# get label dict from sample; for each key, only picking the system with global labels.
403407
outputs = {
404408
kk: [

deepmd/utils/econf_embd.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import numpy as np
3-
4-
try:
5-
import dpdata
6-
from mendeleev import (
7-
element,
8-
)
9-
except ImportError:
10-
pass
3+
from mendeleev import (
4+
element,
5+
)
116

127
###
138
# made by command
@@ -173,7 +168,7 @@
173168
maxl = maxn
174169
maxm = 2 * maxl + 1
175170

176-
type_map = dpdata.periodic_table.ELEMENTS
171+
type_map = list(electronic_configuration_embedding.keys())
177172
ECONF_DIM = electronic_configuration_embedding[type_map[0]].shape[0]
178173

179174

doc/freeze/freeze.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Freeze a model
22

3-
The trained neural network is extracted from a checkpoint and dumped into a protobuf(.pb) file. This process is called "freezing" a model. The idea and part of our code are from [Morgan](https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc). To freeze a model, typically one does
3+
The trained neural network is extracted from a checkpoint and dumped into a model file. This process is called "freezing" a model.
4+
To freeze a model, typically one does
45

56
::::{tab-set}
67

@@ -11,6 +12,7 @@ $ dp freeze -o model.pb
1112
```
1213

1314
in the folder where the model is trained. The output model is called `model.pb`.
15+
The idea and part of our code are from [Morgan](https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc).
1416

1517
:::
1618

doc/model/sel.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,26 @@ All descriptors require to set `sel`, which means the expected maximum number of
66

77
To determine a proper `sel`, one can calculate the neighbor stat of the training data before training:
88

9+
::::{tab-set}
10+
11+
:::{tab-item} TensorFlow {{ tensorflow_icon }}
12+
913
```sh
10-
dp neighbor-stat -s data -r 6.0 -t O H
14+
dp --tf neighbor-stat -s data -r 6.0 -t O H
1115
```
1216

17+
:::
18+
19+
:::{tab-item} PyTorch {{ pytorch_icon }}
20+
21+
```sh
22+
dp --pt neighbor-stat -s data -r 6.0 -t O H
23+
```
24+
25+
:::
26+
27+
::::
28+
1329
where `data` is the directory of data, `6.0` is the cutoff radius, and `O` and `H` is the type map. The program will give the `max_nbor_size`. For example, `max_nbor_size` of the water example is `[38, 72]`, meaning an atom may have 38 O neighbors and 72 H neighbors in the training data.
1430

1531
The `sel` should be set to a higher value than that of the training data, considering there may be some extreme geometries during MD simulations. As a result, we set `sel` to `[46, 92]` in the water example.

doc/model/train-fitting-dos.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Fit electronic density of states (DOS) {{ tensorflow_icon }}
1+
# Fit electronic density of states (DOS) {{ tensorflow_icon }} {{ pytorch_icon }} {{ dpmodel_icon }}
22

33
:::{note}
4-
**Supported backends**: TensorFlow {{ tensorflow_icon }}
4+
**Supported backends**: TensorFlow {{ tensorflow_icon }}, PyTorch {{ pytorch_icon }}, DP {{ dpmodel_icon }}
55
:::
66

77
Here we present an API to DeepDOS model, which can be used to fit electronic density of state (DOS) (which is a vector).
@@ -82,10 +82,26 @@ To prepare the data, we recommend shifting the DOS data by the Fermi level.
8282

8383
The training command is the same as `ener` mode, i.e.
8484

85+
::::{tab-set}
86+
87+
:::{tab-item} TensorFlow {{ tensorflow_icon }}
88+
89+
```bash
90+
dp --tf train input.json
91+
```
92+
93+
:::
94+
95+
:::{tab-item} PyTorch {{ pytorch_icon }}
96+
8597
```bash
86-
dp train input.json
98+
dp --pt train input.json
8799
```
88100

101+
:::
102+
103+
::::
104+
89105
The detailed loss can be found in `lcurve.out`:
90106

91107
```
@@ -117,14 +133,33 @@ The detailed loss can be found in `lcurve.out`:
117133

118134
In this earlier version, we can use `dp test` to infer the electronic density of state for given frames.
119135

136+
::::{tab-set}
137+
138+
:::{tab-item} TensorFlow {{ tensorflow_icon }}
139+
140+
```bash
141+
142+
dp --tf freeze -o frozen_model.pb
143+
144+
dp --tf test -m frozen_model.pb -s ../data/111/$k -d ${output_prefix} -a -n 100
145+
```
146+
147+
:::
148+
149+
:::{tab-item} PyTorch {{ pytorch_icon }}
150+
120151
```bash
121152

122-
$DP freeze -o frozen_model.pb
153+
dp --pt freeze -o frozen_model.pth
123154

124-
$DP test -m frozen_model.pb -s ../data/111/$k -d ${output_prefix} -a -n 100
155+
dp --pt test -m frozen_model.pth -s ../data/111/$k -d ${output_prefix} -a -n 100
125156
```
126157

127-
if `dp test -d ${output_prefix} -a` is specified, the predicted DOS and atomic DOS for each frame is output in the working directory
158+
:::
159+
160+
::::
161+
162+
if `dp test -d ${output_prefix} -a` is specified, the predicted DOS and atomic DOS for each frame are output in the working directory
128163

129164
```
130165
${output_prefix}.ados.out.0 ${output_prefix}.ados.out.1 ${output_prefix}.ados.out.2 ${output_prefix}.ados.out.3

doc/test/model-deviation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ One can also use a subcommand to calculate the deviation of predicted forces or
5959
dp model-devi -m graph.000.pb graph.001.pb graph.002.pb graph.003.pb -s ./data -o model_devi.out
6060
```
6161

62-
where `-m` specifies graph files to be calculated, `-s` gives the data to be evaluated, `-o` the file to which model deviation results is dumped. Here is more information on this sub-command:
62+
where `-m` specifies model files to be calculated, `-s` gives the data to be evaluated, `-o` the file to which model deviation results are dumped. Here is more information on this sub-command:
6363

6464
```bash
6565
usage: dp model-devi [-h] [-v {DEBUG,3,INFO,2,WARNING,1,ERROR,0}]

doc/third-party/gromacs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Then, in your working directories, we have to write `input.json` file:
105105

106106
Here is an explanation for these settings:
107107

108-
- `graph_file` : The graph file (with suffix .pb) generated by `dp freeze` command
108+
- `graph_file` : The [model file](../backend.md) generated by `dp freeze` command
109109
- `type_file` : File to specify DP atom types (in space-separated format). Here, `type.raw` looks like
110110

111111
```

0 commit comments

Comments
 (0)