Skip to content

Commit 76f28e9

Browse files
authored
Merge branch 'dpa3-alpha' into 1218_dpa3_alpha_nostat
2 parents 57acd99 + 4e65d8b commit 76f28e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4743
-445
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
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.8.2
32+
rev: v0.8.3
3333
hooks:
3434
- id: ruff
3535
args: ["--fix"]
@@ -60,7 +60,7 @@ repos:
6060
- id: blacken-docs
6161
# C++
6262
- repo: https://github.com/pre-commit/mirrors-clang-format
63-
rev: v19.1.4
63+
rev: v19.1.5
6464
hooks:
6565
- id: clang-format
6666
exclude: ^(source/3rdparty|source/lib/src/gpu/cudart/.+\.inc|.+\.ipynb$)

deepmd/pd/entrypoints/main.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def train(
230230
use_pretrain_script: bool = False,
231231
force_load: bool = False,
232232
output: str = "out.json",
233-
):
233+
) -> None:
234234
log.info("Configuration path: %s", input_file)
235235
SummaryPrinter()()
236236
with open(input_file) as fin:
@@ -321,18 +321,26 @@ def train(
321321
# save min_nbor_dist
322322
if min_nbor_dist is not None:
323323
if not multi_task:
324-
trainer.model.min_nbor_dist = min_nbor_dist
324+
trainer.model.min_nbor_dist = paddle.to_tensor(
325+
min_nbor_dist,
326+
dtype=paddle.float64,
327+
place=DEVICE,
328+
)
325329
else:
326330
for model_item in min_nbor_dist:
327-
trainer.model[model_item].min_nbor_dist = min_nbor_dist[model_item]
331+
trainer.model[model_item].min_nbor_dist = paddle.to_tensor(
332+
min_nbor_dist[model_item],
333+
dtype=paddle.float64,
334+
place=DEVICE,
335+
)
328336
trainer.run()
329337

330338

331339
def freeze(
332340
model: str,
333341
output: str = "frozen_model.json",
334342
head: Optional[str] = None,
335-
):
343+
) -> None:
336344
paddle.set_flags(
337345
{
338346
"FLAGS_save_cf_stack_op": 1,
@@ -383,7 +391,7 @@ def change_bias(
383391
numb_batch: int = 0,
384392
model_branch: Optional[str] = None,
385393
output: Optional[str] = None,
386-
):
394+
) -> None:
387395
if input_file.endswith(".pd"):
388396
old_state_dict = paddle.load(input_file)
389397
model_state_dict = copy.deepcopy(old_state_dict.get("model", old_state_dict))

deepmd/pd/loss/ener.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
TaskLoss,
1111
)
1212
from deepmd.pd.utils import (
13-
decomp,
1413
env,
1514
)
1615
from deepmd.pd.utils.env import (
@@ -224,10 +223,7 @@ def forward(self, input_dict, model, label, natoms, learning_rate, mae=False):
224223

225224
if self.relative_f is not None:
226225
force_label_3 = force_label.reshape([-1, 3])
227-
# norm_f = force_label_3.norm(axis=1, keepdim=True) + self.relative_f
228-
norm_f = (
229-
decomp.norm(force_label_3, axis=1, keepdim=True) + self.relative_f
230-
)
226+
norm_f = force_label_3.norm(axis=1, keepdim=True) + self.relative_f
231227
diff_f_3 = diff_f.reshape([-1, 3])
232228
diff_f_3 = diff_f_3 / norm_f
233229
diff_f = diff_f_3.reshape([-1])

deepmd/pd/model/atomic_model/dp_atomic_model.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
2-
import copy
32
import functools
43
import logging
54
from typing import (
@@ -52,7 +51,7 @@ def __init__(
5251
fitting,
5352
type_map: list[str],
5453
**kwargs,
55-
):
54+
) -> None:
5655
super().__init__(type_map, **kwargs)
5756
ntypes = len(type_map)
5857
self.type_map = type_map
@@ -201,7 +200,7 @@ def serialize(self) -> dict:
201200

202201
@classmethod
203202
def deserialize(cls, data) -> "DPAtomicModel":
204-
data = copy.deepcopy(data)
203+
data = data.copy()
205204
check_version_compatibility(data.pop("@version", 1), 2, 1)
206205
data.pop("@class", None)
207206
data.pop("type", None)
@@ -212,6 +211,37 @@ def deserialize(cls, data) -> "DPAtomicModel":
212211
obj = super().deserialize(data)
213212
return obj
214213

214+
def enable_compression(
215+
self,
216+
min_nbor_dist: float,
217+
table_extrapolate: float = 5,
218+
table_stride_1: float = 0.01,
219+
table_stride_2: float = 0.1,
220+
check_frequency: int = -1,
221+
) -> None:
222+
"""Call descriptor enable_compression().
223+
224+
Parameters
225+
----------
226+
min_nbor_dist
227+
The nearest distance between atoms
228+
table_extrapolate
229+
The scale of model extrapolation
230+
table_stride_1
231+
The uniform stride of the first table
232+
table_stride_2
233+
The uniform stride of the second table
234+
check_frequency
235+
The overflow check frequency
236+
"""
237+
self.descriptor.enable_compression(
238+
min_nbor_dist,
239+
table_extrapolate,
240+
table_stride_1,
241+
table_stride_2,
242+
check_frequency,
243+
)
244+
215245
def forward_atomic(
216246
self,
217247
extended_coord,
@@ -278,7 +308,7 @@ def compute_or_load_stat(
278308
self,
279309
sampled_func,
280310
stat_file_path: Optional[DPPath] = None,
281-
):
311+
) -> None:
282312
"""
283313
Compute or load the statistics parameters of the model,
284314
such as mean and standard deviation of descriptors or the energy bias of the fitting net.

deepmd/pd/model/descriptor/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from .descriptor import (
66
DescriptorBlock,
77
)
8+
from .dpa1 import (
9+
DescrptBlockSeAtten,
10+
DescrptDPA1,
11+
)
812
from .env_mat import (
913
prod_env_mat,
1014
)
@@ -17,6 +21,8 @@
1721
"BaseDescriptor",
1822
"DescriptorBlock",
1923
"DescrptBlockSeA",
24+
"DescrptBlockSeAtten",
25+
"DescrptDPA1",
2026
"DescrptSeA",
2127
"prod_env_mat",
2228
]

0 commit comments

Comments
 (0)