From f04563f4b265fcde3e3461aa929b93ed906be864 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:58:45 +0800 Subject: [PATCH 1/8] test cuda --- deepmd/pt/model/model/pairtab_atomic_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deepmd/pt/model/model/pairtab_atomic_model.py b/deepmd/pt/model/model/pairtab_atomic_model.py index 98215191c1..6ba9ad51dd 100644 --- a/deepmd/pt/model/model/pairtab_atomic_model.py +++ b/deepmd/pt/model/model/pairtab_atomic_model.py @@ -7,8 +7,8 @@ ) import torch -from torch import ( - nn, +from .model import ( + BaseModel, ) from deepmd.dpmodel import ( @@ -24,7 +24,7 @@ ) -class PairTabModel(nn.Module, BaseAtomicModel): +class PairTabModel(BaseModel, BaseAtomicModel): """Pairwise tabulation energy model. This model can be used to tabulate the pairwise energy between atoms for either From 81691fd3c3797a75f9cff84d5b7fc12f27f84444 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:00:13 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/pt/model/model/pairtab_atomic_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deepmd/pt/model/model/pairtab_atomic_model.py b/deepmd/pt/model/model/pairtab_atomic_model.py index 6ba9ad51dd..f82b5355ad 100644 --- a/deepmd/pt/model/model/pairtab_atomic_model.py +++ b/deepmd/pt/model/model/pairtab_atomic_model.py @@ -7,9 +7,6 @@ ) import torch -from .model import ( - BaseModel, -) from deepmd.dpmodel import ( FittingOutputDef, @@ -22,6 +19,9 @@ from .base_atomic_model import ( BaseAtomicModel, ) +from .model import ( + BaseModel, +) class PairTabModel(BaseModel, BaseAtomicModel): From 3a4dd12ac55f3aa0e2ca4e9160b906d36e92ba08 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:21:51 +0800 Subject: [PATCH 3/8] fix: add tab_data to graph --- deepmd/pt/model/model/pairtab_atomic_model.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/deepmd/pt/model/model/pairtab_atomic_model.py b/deepmd/pt/model/model/pairtab_atomic_model.py index f82b5355ad..2837aaffe7 100644 --- a/deepmd/pt/model/model/pairtab_atomic_model.py +++ b/deepmd/pt/model/model/pairtab_atomic_model.py @@ -62,11 +62,11 @@ def __init__( tab_info, tab_data, ) = self.tab.get() # this returns -> Tuple[np.array, np.array] - self.tab_info = torch.from_numpy(tab_info) - self.tab_data = torch.from_numpy(tab_data) + self.register_buffer("tab_info", torch.from_numpy(tab_info)) + self.register_buffer("tab_data", torch.from_numpy(tab_data)) else: - self.tab_info = None - self.tab_data = None + self.register_buffer("tab_info", None) + self.register_buffer("tab_data", None) # self.model_type = "ener" # self.model_version = MODEL_VERSION ## this shoud be in the parent class @@ -118,8 +118,8 @@ def deserialize(cls, data) -> "PairTabModel": tab = PairTab.deserialize(data["tab"]) tab_model = cls(None, rcut, sel) tab_model.tab = tab - tab_model.tab_info = torch.from_numpy(tab_model.tab.tab_info) - tab_model.tab_data = torch.from_numpy(tab_model.tab.tab_data) + tab_model.register_buffer("tab_info", torch.from_numpy(tab_model.tab.tab_info)) + tab_model.register_buffer("tab_data", torch.from_numpy(tab_model.tab.tab_data)) return tab_model def forward_atomic( From 63994ac5d5b79decd9128401aad85b2c1ec2a9ab Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Thu, 8 Feb 2024 20:27:11 +0800 Subject: [PATCH 4/8] fix: cuda --- source/tests/pt/model/test_linear_atomic_model.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/tests/pt/model/test_linear_atomic_model.py b/source/tests/pt/model/test_linear_atomic_model.py index 211b1f8215..d6bcbe53da 100644 --- a/source/tests/pt/model/test_linear_atomic_model.py +++ b/source/tests/pt/model/test_linear_atomic_model.py @@ -73,7 +73,9 @@ def test_pairwise(self, mock_loadtxt): ).to(env.DEVICE) type_map = ["foo", "bar"] - zbl_model = PairTabModel(tab_file=file_path, rcut=0.3, sel=2) + zbl_model = PairTabModel(tab_file=file_path, rcut=0.3, sel=2).to( + env.DEVICE + ) dp_model = DPAtomicModel(ds, ft, type_map=type_map, resuming=True).to( env.DEVICE ) @@ -82,7 +84,7 @@ def test_pairwise(self, mock_loadtxt): zbl_model, sw_rmin=0.1, sw_rmax=0.25, - ) + ).to(env.DEVICE) wgt_res = [] for dist in np.linspace(0.05, 0.3, 10): extended_coord = torch.tensor( From 0e99b8022a618db0009184479d92a480604a8d9a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:30:16 +0000 Subject: [PATCH 5/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/tests/pt/model/test_linear_atomic_model.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/tests/pt/model/test_linear_atomic_model.py b/source/tests/pt/model/test_linear_atomic_model.py index d6bcbe53da..d362e85617 100644 --- a/source/tests/pt/model/test_linear_atomic_model.py +++ b/source/tests/pt/model/test_linear_atomic_model.py @@ -73,9 +73,7 @@ def test_pairwise(self, mock_loadtxt): ).to(env.DEVICE) type_map = ["foo", "bar"] - zbl_model = PairTabModel(tab_file=file_path, rcut=0.3, sel=2).to( - env.DEVICE - ) + zbl_model = PairTabModel(tab_file=file_path, rcut=0.3, sel=2).to(env.DEVICE) dp_model = DPAtomicModel(ds, ft, type_map=type_map, resuming=True).to( env.DEVICE ) From 3f979732b7d3b653904370e363fd1c9ce8e131c1 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Thu, 8 Feb 2024 22:47:07 +0800 Subject: [PATCH 6/8] fix: cuda --- source/tests/pt/model/test_linear_atomic_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tests/pt/model/test_linear_atomic_model.py b/source/tests/pt/model/test_linear_atomic_model.py index d362e85617..caa386e9c3 100644 --- a/source/tests/pt/model/test_linear_atomic_model.py +++ b/source/tests/pt/model/test_linear_atomic_model.py @@ -73,7 +73,7 @@ def test_pairwise(self, mock_loadtxt): ).to(env.DEVICE) type_map = ["foo", "bar"] - zbl_model = PairTabModel(tab_file=file_path, rcut=0.3, sel=2).to(env.DEVICE) + zbl_model = PairTabModel(tab_file=file_path, rcut=0.3, sel=2) dp_model = DPAtomicModel(ds, ft, type_map=type_map, resuming=True).to( env.DEVICE ) From 0702221d3d045181ff8176a66580aebed94975f0 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Fri, 9 Feb 2024 07:53:50 +0800 Subject: [PATCH 7/8] fix: move input to gpu --- source/tests/pt/model/test_linear_atomic_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/tests/pt/model/test_linear_atomic_model.py b/source/tests/pt/model/test_linear_atomic_model.py index caa386e9c3..cd44a56053 100644 --- a/source/tests/pt/model/test_linear_atomic_model.py +++ b/source/tests/pt/model/test_linear_atomic_model.py @@ -56,8 +56,8 @@ def test_pairwise(self, mock_loadtxt): [0.25, 0.0, 0.0, 0.0], ] ) - extended_atype = torch.tensor([[0, 0]]) - nlist = torch.tensor([[[1], [-1]]]) + extended_atype = torch.tensor([[0, 0]]).to(env.DEVICE) + nlist = torch.tensor([[[1], [-1]]]).to(env.DEVICE) ds = DescrptSeA( rcut=0.3, @@ -92,7 +92,7 @@ def test_pairwise(self, mock_loadtxt): [0.0, dist, 0.0], ], ] - ) + ).to(env.DEVICE) wgt_model.forward_atomic(extended_coord, extended_atype, nlist) From 7a80229db18a43756b22d5b876890a0c27976af5 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Fri, 9 Feb 2024 08:31:33 +0800 Subject: [PATCH 8/8] fix: move res to gpu --- source/tests/pt/model/test_linear_atomic_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tests/pt/model/test_linear_atomic_model.py b/source/tests/pt/model/test_linear_atomic_model.py index cd44a56053..e9090de86a 100644 --- a/source/tests/pt/model/test_linear_atomic_model.py +++ b/source/tests/pt/model/test_linear_atomic_model.py @@ -112,7 +112,7 @@ def test_pairwise(self, mock_loadtxt): [0.0, 0.0], ], dtype=torch.float64, - ) + ).to(env.DEVICE) torch.testing.assert_close(results, excepted_res, rtol=0.0001, atol=0.0001)