-
Notifications
You must be signed in to change notification settings - Fork 580
feat(pt): add atomic_weight to dipole model inference #4628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ChiahsinChu
wants to merge
13
commits into
deepmodeling:devel
from
ChiahsinChu:devel-dipole_with_atomic_weight
Closed
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
275fb52
add atomic_weight for model inference
ChiahsinChu b5356d9
remove test tensor
ChiahsinChu 205e506
fix bug in model frozen
ChiahsinChu 50a8a21
deal with case without fitting net
ChiahsinChu a47b1e0
Merge branch 'devel' into devel-dipole_with_atomic_weight
ChiahsinChu 3aaccc7
Merge branch 'devel' into devel-dipole_with_atomic_weight
ChiahsinChu 3cbaa61
Merge branch 'devel' into devel-dipole_with_atomic_weight
ChiahsinChu 3763d8e
Merge branch 'devel' into devel-dipole_with_atomic_weight
ChiahsinChu 32a64e1
move `atomic_weight` to atomic model level
ChiahsinChu ad063bd
(np) add atomic_weight to atomic model and dipole model; add UT for p…
ChiahsinChu 778af5b
add doc for atomic_weight
ChiahsinChu 088b252
fix bug in jax2tf model convert
ChiahsinChu 66d3e0f
Merge branch 'devel' into devel-dipole_with_atomic_weight
ChiahsinChu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
||
|
|
@@ -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, | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
||
| 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] | ||
| ) | ||
ChiahsinChu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| model_predict = fit_output_to_model_output( | ||
| atomic_ret, | ||
| self.atomic_output_def(), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.