Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ repos:
- id: clang-format
exclude: ^(source/3rdparty|source/lib/src/gpu/cudart/.+\.inc|.+\.ipynb$|.+\.json$)
# markdown, yaml, CSS, javascript
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
types_or: [markdown, yaml, css]
# workflow files cannot be modified by pre-commit.ci
exclude: ^(source/3rdparty|\.github/workflows|\.clang-format)
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v4.0.0-alpha.8
# hooks:
# - id: prettier
# types_or: [markdown, yaml, css]
# # workflow files cannot be modified by pre-commit.ci
# exclude: ^(source/3rdparty|\.github/workflows|\.clang-format)
# Shell
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.11.0-1
Expand All @@ -83,25 +83,25 @@ repos:
hooks:
- id: cmake-format
#- id: cmake-lint
- repo: https://github.com/njzjz/mirrors-bibtex-tidy
rev: v1.13.0
hooks:
- id: bibtex-tidy
args:
- --curly
- --numeric
- --align=13
- --blank-lines
# disable sort: the order of keys and fields has explict meanings
#- --sort=key
- --duplicates=key,doi,citation,abstract
- --merge=combine
#- --sort-fields
#- --strip-comments
- --trailing-commas
- --encode-urls
- --remove-empty-fields
- --wrap=80
# - repo: https://github.com/njzjz/mirrors-bibtex-tidy
# rev: v1.13.0
# hooks:
# - id: bibtex-tidy
# args:
# - --curly
# - --numeric
# - --align=13
# - --blank-lines
# # disable sort: the order of keys and fields has explict meanings
# #- --sort=key
# - --duplicates=key,doi,citation,abstract
# - --merge=combine
# #- --sort-fields
# #- --strip-comments
# - --trailing-commas
# - --encode-urls
# - --remove-empty-fields
# - --wrap=80
# license header
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
Expand Down
7 changes: 7 additions & 0 deletions deepmd/pd/entrypoints/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
import json
import logging
import paddle.distributed as dist
from pathlib import (
Path,
)
Expand Down Expand Up @@ -41,6 +42,9 @@
from deepmd.pd.train.wrapper import (
ModelWrapper,
)
from deepmd.pd.utils import (
env,
)
from deepmd.pd.utils.dataloader import (
DpLoaderSet,
)
Expand Down Expand Up @@ -233,6 +237,7 @@ def train(
output: str = "out.json",
) -> None:
log.info("Configuration path: %s", input_file)
env.CUSTOM_OP_USE_JIT = False
if LOCAL_RANK == 0:
SummaryPrinter()()
with open(input_file) as fin:
Expand Down Expand Up @@ -539,6 +544,8 @@ def main(args: Optional[Union[list[str], argparse.Namespace]] = None):
log.debug("Log handles were successfully set")
log.info("DeePMD version: %s", __version__)

dist.enable_auto_dp()

if FLAGS.command == "train":
train(
input_file=FLAGS.INPUT,
Expand Down
14 changes: 10 additions & 4 deletions deepmd/pd/model/descriptor/dpa3.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DescrptDPA3(BaseDescriptor, paddle.nn.Layer):
Whether to use bias in the type embedding layer.
use_loc_mapping : bool, Optional
Whether to use local atom index mapping in training or non-parallel inference.
Not supported yet in Paddle.
When True, local indexing and mapping are applied to neighbor lists and embeddings during descriptor computation.
type_map : list[str], Optional
A list of strings. Give the name to each type of atoms.

Expand All @@ -117,7 +117,7 @@ def __init__(
seed: Optional[Union[int, list[int]]] = None,
use_econf_tebd: bool = False,
use_tebd_bias: bool = False,
use_loc_mapping: bool = False,
use_loc_mapping: bool = True,
type_map: Optional[list[str]] = None,
) -> None:
super().__init__()
Expand Down Expand Up @@ -160,6 +160,8 @@ def init_subclass_params(sub_data, sub_class):
fix_stat_std=self.repflow_args.fix_stat_std,
optim_update=self.repflow_args.optim_update,
smooth_edge_update=self.repflow_args.smooth_edge_update,
edge_init_use_dist=self.repflow_args.edge_init_use_dist,
use_exp_switch=self.repflow_args.use_exp_switch,
use_dynamic_sel=self.repflow_args.use_dynamic_sel,
sel_reduce_factor=self.repflow_args.sel_reduce_factor,
use_loc_mapping=use_loc_mapping,
Expand All @@ -170,8 +172,8 @@ def init_subclass_params(sub_data, sub_class):
)

self.use_econf_tebd = use_econf_tebd
self.use_tebd_bias = use_tebd_bias
self.use_loc_mapping = use_loc_mapping
self.use_tebd_bias = use_tebd_bias
self.type_map = type_map
self.tebd_dim = self.repflow_args.n_dim
self.type_embedding = TypeEmbedNet(
Expand Down Expand Up @@ -487,12 +489,16 @@ def forward(
The smooth switch function. shape: nf x nloc x nnei

"""
parallel_mode = comm_dict is not None
# cast the input to internal precsion
extended_coord = extended_coord.to(dtype=self.prec)
nframes, nloc, nnei = nlist.shape
nall = extended_coord.reshape([nframes, -1]).shape[1] // 3

node_ebd_ext = self.type_embedding(extended_atype)
if not parallel_mode and self.use_loc_mapping:
node_ebd_ext = self.type_embedding(extended_atype[:, :nloc])
else:
node_ebd_ext = self.type_embedding(extended_atype)
node_ebd_inp = node_ebd_ext[:, :nloc, :]
# repflows
node_ebd, edge_ebd, h2, rot_mat, sw = self.repflows(
Expand Down
18 changes: 16 additions & 2 deletions deepmd/pd/model/descriptor/env_mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import paddle

from deepmd.pd.utils.preprocess import (
compute_exp_sw,
compute_smooth_weight,
)

Expand All @@ -14,6 +15,7 @@ def _make_env_mat(
ruct_smth: float,
radial_only: bool = False,
protection: float = 0.0,
use_exp_switch: bool = False,
):
"""Make smooth environment matrix."""
bsz, natoms, nnei = nlist.shape
Expand All @@ -22,17 +24,26 @@ def _make_env_mat(
mask = nlist >= 0
# nlist = nlist * mask ## this impl will contribute nans in Hessian calculation.
nlist = paddle.where(mask, nlist, nall - 1)

# tmp = coord[:, :natoms].clone()
# coord_l = tmp.reshape([bsz, -1, 1, 3])
coord_l = coord[:, :natoms].reshape([bsz, -1, 1, 3])

index = nlist.reshape([bsz, -1]).unsqueeze(-1).expand([-1, -1, 3])
coord_r = paddle.take_along_axis(coord, axis=1, indices=index)
coord_pad = paddle.concat([coord, coord[:, -1:, :] + rcut], axis=1)
coord_r = paddle.take_along_axis(coord_pad, axis=1, indices=index)
coord_r = coord_r.reshape([bsz, natoms, nnei, 3])
diff = coord_r - coord_l
length = paddle.linalg.norm(diff, axis=-1, keepdim=True)
# for index 0 nloc atom
length = length + (~mask.unsqueeze(-1)).astype(length.dtype)
t0 = 1 / (length + protection)
t1 = diff / (length + protection) ** 2
weight = compute_smooth_weight(length, ruct_smth, rcut)
weight = (
compute_smooth_weight(length, ruct_smth, rcut)
if not use_exp_switch
else compute_exp_sw(length, ruct_smth, rcut)
)
weight = weight * mask.unsqueeze(-1).astype(weight.dtype)
if radial_only:
env_mat = t0 * weight
Expand All @@ -51,6 +62,7 @@ def prod_env_mat(
rcut_smth: float,
radial_only: bool = False,
protection: float = 0.0,
use_exp_switch: bool = False,
):
"""Generate smooth environment matrix from atom coordinates and other context.

Expand All @@ -63,6 +75,7 @@ def prod_env_mat(
- rcut_smth: Smooth hyper-parameter for pair force & energy.
- radial_only: Whether to return a full description or a radial-only descriptor.
- protection: Protection parameter to prevent division by zero errors during calculations.
- use_exp_switch: Whether to use the exponential switch function.

Returns
-------
Expand All @@ -75,6 +88,7 @@ def prod_env_mat(
rcut_smth,
radial_only,
protection=protection,
use_exp_switch=use_exp_switch,
) # shape [n_atom, dim, 4 or 1]
t_avg = mean[atype] # [n_atom, dim, 4 or 1]
t_std = stddev[atype] # [n_atom, dim, 4 or 1]
Expand Down
Loading