Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions deepmd/pt/model/model/dipole_model.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing since it breaks the consistency of APIs between different models and backends.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to add this keyword for all models and backends?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what is the best way

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest incorporating the atomic weight into the base atomic model, following a similar approach to how atom masks are managed. This would ensure that atomic weight is consistently supported across all atomic modes.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def forward(
fparam: Optional[torch.Tensor] = None,
aparam: Optional[torch.Tensor] = None,
do_atomic_virial: bool = False,
atomic_weight: Optional[torch.Tensor] = None,
) -> dict[str, torch.Tensor]:
model_ret = self.forward_common(
coord,
Expand All @@ -68,6 +69,7 @@ def forward(
fparam=fparam,
aparam=aparam,
do_atomic_virial=do_atomic_virial,
atomic_weight=atomic_weight,
)
if self.get_fitting_net() is not None:
model_predict = {}
Expand Down Expand Up @@ -98,6 +100,7 @@ def forward_lower(
fparam: Optional[torch.Tensor] = None,
aparam: Optional[torch.Tensor] = None,
do_atomic_virial: bool = False,
atomic_weight: Optional[torch.Tensor] = None,
):
model_ret = self.forward_common_lower(
extended_coord,
Expand All @@ -108,6 +111,7 @@ def forward_lower(
aparam=aparam,
do_atomic_virial=do_atomic_virial,
extra_nlist_sort=self.need_sorted_nlist_for_lower(),
atomic_weight=atomic_weight,
)
if self.get_fitting_net() is not None:
model_predict = {}
Expand Down
12 changes: 12 additions & 0 deletions deepmd/pt/model/model/make_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def forward_common(
fparam: Optional[torch.Tensor] = None,
aparam: Optional[torch.Tensor] = None,
do_atomic_virial: bool = False,
atomic_weight: Optional[torch.Tensor] = None,
) -> dict[str, torch.Tensor]:
"""Return model prediction.

Expand Down Expand Up @@ -188,6 +189,7 @@ def forward_common(
do_atomic_virial=do_atomic_virial,
fparam=fp,
aparam=ap,
atomic_weight=atomic_weight,
)
model_predict = communicate_extended_output(
model_predict_lower,
Expand Down Expand Up @@ -242,6 +244,7 @@ def forward_common_lower(
do_atomic_virial: bool = False,
comm_dict: Optional[dict[str, torch.Tensor]] = None,
extra_nlist_sort: bool = False,
atomic_weight: Optional[torch.Tensor] = None,
):
"""Return model prediction. Lower interface that takes
extended atomic coordinates and types, nlist, and mapping
Expand Down Expand Up @@ -293,6 +296,15 @@ def forward_common_lower(
aparam=ap,
comm_dict=comm_dict,
)
# add weight to atomic_output
if hasattr(self.atomic_model, "fitting_net"):
if hasattr(self.atomic_model.fitting_net, "var_name"):
kw = self.atomic_model.fitting_net.var_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that self.atomic_model.fitting_output_def could be used here

if atomic_weight is not None:
# atomic_weight: nf x nloc x dim
atomic_ret[kw] = atomic_ret[kw] * atomic_weight.view(
[atomic_ret[kw].shape[0], atomic_ret[kw].shape[1], -1]
)
model_predict = fit_output_to_model_output(
atomic_ret,
self.atomic_output_def(),
Expand Down