-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jax/array-api): se_e2_a (#4217)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new class `DescrptSeAArrayAPI` for enhanced array compatibility. - Added a new class `DescrptSeA` integrated with the Flax library for neural network modules. - Improved handling of atomic types and neighbor lists for better performance and clarity. - **Tests** - Enhanced test suite to support additional backends and configurations, including JAX and strict array API. - Added new evaluation methods for testing across different frameworks. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
16172e6
commit cfb4731
Showing
5 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from typing import ( | ||
Any, | ||
) | ||
|
||
from deepmd.dpmodel.descriptor.se_e2_a import DescrptSeAArrayAPI as DescrptSeADP | ||
from deepmd.jax.common import ( | ||
flax_module, | ||
to_jax_array, | ||
) | ||
from deepmd.jax.utils.exclude_mask import ( | ||
PairExcludeMask, | ||
) | ||
from deepmd.jax.utils.network import ( | ||
NetworkCollection, | ||
) | ||
|
||
|
||
@flax_module | ||
class DescrptSeA(DescrptSeADP): | ||
def __setattr__(self, name: str, value: Any) -> None: | ||
if name in {"dstd", "davg"}: | ||
value = to_jax_array(value) | ||
elif name in {"embeddings"}: | ||
if value is not None: | ||
value = NetworkCollection.deserialize(value.serialize()) | ||
elif name == "env_mat": | ||
# env_mat doesn't store any value | ||
pass | ||
elif name == "emask": | ||
value = PairExcludeMask(value.ntypes, value.exclude_types) | ||
|
||
return super().__setattr__(name, value) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from typing import ( | ||
Any, | ||
) | ||
|
||
from deepmd.dpmodel.descriptor.se_e2_a import DescrptSeAArrayAPI as DescrptSeADP | ||
|
||
from ..common import ( | ||
to_array_api_strict_array, | ||
) | ||
from ..utils.exclude_mask import ( | ||
PairExcludeMask, | ||
) | ||
from ..utils.network import ( | ||
NetworkCollection, | ||
) | ||
|
||
|
||
class DescrptSeA(DescrptSeADP): | ||
def __setattr__(self, name: str, value: Any) -> None: | ||
if name in {"dstd", "davg"}: | ||
value = to_array_api_strict_array(value) | ||
elif name in {"embeddings"}: | ||
if value is not None: | ||
value = NetworkCollection.deserialize(value.serialize()) | ||
elif name == "env_mat": | ||
# env_mat doesn't store any value | ||
pass | ||
elif name == "emask": | ||
value = PairExcludeMask(value.ntypes, value.exclude_types) | ||
|
||
return super().__setattr__(name, value) |
This file contains 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