Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrogenSulfate committed Oct 9, 2024
1 parent a83fb63 commit f7f64b1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions deepmd/pd/loss/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def forward(self, input_dict, model, label, natoms, learning_rate=0.0, mae=False
[-1, self.numb_dos]
)
if "mask" in model_pred:
diff = diff[model_pred["mask"].reshape([-1]).bool()]
diff = diff[model_pred["mask"].reshape([-1]).astype("bool")]
l2_local_loss_dos = paddle.mean(paddle.square(diff))
if not self.inference:
more_loss["l2_local_dos_loss"] = self.display_if_exist(
Expand All @@ -164,7 +164,7 @@ def forward(self, input_dict, model, label, natoms, learning_rate=0.0, mae=False
[-1, self.numb_dos]
)
if "mask" in model_pred:
diff = diff[model_pred["mask"].reshape([-1]).bool()]
diff = diff[model_pred["mask"].reshape([-1]).astype("bool")]
l2_local_loss_cdf = paddle.mean(paddle.square(diff))
if not self.inference:
more_loss["l2_local_cdf_loss"] = self.display_if_exist(
Expand Down
9 changes: 6 additions & 3 deletions deepmd/pd/loss/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def forward(self, input_dict, model, label, natoms, learning_rate=0.0, mae=False
[-1, self.tensor_size]
)
if "mask" in model_pred:
diff = diff[model_pred["mask"].reshape([-1]).bool()]
diff = diff[model_pred["mask"].reshape([-1]).astype("bool")]
l2_local_loss = paddle.mean(paddle.square(diff))
if not self.inference:
more_loss[f"l2_local_{self.tensor_name}_loss"] = self.display_if_exist(
Expand All @@ -133,9 +133,12 @@ def forward(self, input_dict, model, label, natoms, learning_rate=0.0, mae=False
if "mask" in model_pred:
atom_num = model_pred["mask"].sum(-1, keepdim=True)
l2_global_loss = paddle.mean(
paddle.sum(paddle.square(diff) * atom_num, axis=0) / atom_num.sum()
paddle.sum(
paddle.square(diff) * atom_num.astype(diff.dtype), axis=0
)
/ atom_num.sum()
)
atom_num = paddle.mean(atom_num.float())
atom_num = paddle.mean(atom_num.astype(diff.dtype))
else:
atom_num = natoms
l2_global_loss = paddle.mean(paddle.square(diff))
Expand Down
3 changes: 1 addition & 2 deletions deepmd/pd/utils/nlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ def build_neighbor_list(
nall = coord.shape[1] // 3
# fill virtual atoms with large coords so they are not neighbors of any
# real atom.
# if coord.numel().item() > 0:
if True > 0:
if coord.numel() > 0:
xmax = paddle.max(coord) + 2.0 * rcut
else:
xmax = paddle.zeros([], dtype=coord.dtype).to(device=coord.place) + 2.0 * rcut
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pd/utils/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def build_neighbor_list(
- atype: shape is [nall]
"""
nall = coord.numel() // 3
coord = coord.float()
coord = coord.astype(paddle.get_default_dtype())
nlist = [[] for _ in range(nloc)]
coord_l = coord.reshape([-1, 1, 3])[:nloc]
coord_r = coord.reshape([1, -1, 3])
Expand Down

0 comments on commit f7f64b1

Please sign in to comment.