From abf3477472a0aed66ba70313c8069fde90099ba6 Mon Sep 17 00:00:00 2001 From: Chenxing Luo Date: Sun, 17 Mar 2024 16:58:44 -0400 Subject: [PATCH 1/3] Fix LAMMPS plugin symlink path on macOS platform (#3473) This pull request fixes the broken symlink for `dpplugin.so` on macOS. It should point to `libdeepmd_lmp.so` but point to `libdeepmd_lmp.dylib` instead. ### Details The `libdeepmd_lmp` is a shared module. https://github.com/deepmodeling/deepmd-kit/blob/b875ea8f6661b6e1567537ead7e2b4a8b14ea113/source/lmp/plugin/CMakeLists.txt#L72 The build target name on macOS is `libdeepmd_lmp.so`. Because on macOS, the `CMAKE_SHARED_MODULE_SUFFIX` (`.so`) is different from `CMAKE_SHARED_LIBRARY_SUFFIX` (`.dynlib`). As a result, in previous versions, on macOS the symbolic link `dpplugin.so` was pointed to `libdeepmd_lmp.dylib`, which does not exist. One can check the conda-forge builds to confirm (e.g., [osx-arm64/deepmd-kit-2.2.9-cpu_py311hf5376d5_mpi_openmpi_0.conda](https://anaconda.org/conda-forge/deepmd-kit/2.2.9/download/osx-arm64/deepmd-kit-2.2.9-cpu_py311hf5376d5_mpi_openmpi_0.conda)). --- source/lmp/plugin/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index bfc2253412..4fdae7ac5b 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -126,7 +126,7 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) install( CODE "execute_process( \ COMMAND ${CMAKE_COMMAND} -E create_symlink \ - ../${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_SHARED_LIBRARY_SUFFIX} \ + ../${CMAKE_SHARED_MODULE_PREFIX}${libname}${CMAKE_SHARED_MODULE_SUFFIX} \ ${CMAKE_INSTALL_PREFIX}/lib/${libname}/${PLUGINNAME} \ )") endif() From eca5b309a9602df6b3fdaad00c4f697d11989a30 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 17 Mar 2024 21:58:29 -0400 Subject: [PATCH 2/3] fix(pt): Fix PairTabAtomicModel OOM error (#3484) Reduce memory usage of `_extract_spline_coefficient`. Signed-off-by: Jinzhe Zeng --- .../atomic_model/pairtab_atomic_model.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py index a4aa43ede1..7c7c8a2969 100644 --- a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py +++ b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py @@ -415,20 +415,28 @@ def _extract_spline_coefficient( # (nframes, nloc, nnei) expanded_i_type = i_type.unsqueeze(-1).expand(-1, -1, j_type.shape[-1]) - # (nframes, nloc, nnei, nspline, 4) - expanded_tab_data = tab_data[expanded_i_type, j_type] - - # (nframes, nloc, nnei, 1, 4) - expanded_idx = idx.unsqueeze(-1).unsqueeze(-1).expand(-1, -1, -1, -1, 4) - # handle the case where idx is beyond the number of splines - clipped_indices = torch.clamp(expanded_idx, 0, nspline - 1).to(torch.int64) - + clipped_indices = torch.clamp(idx, 0, nspline - 1).to(torch.int64) + + nframes = i_type.shape[0] + nloc = i_type.shape[1] + nnei = j_type.shape[2] + ntypes = tab_data.shape[0] + # tab_data_idx: (nframes, nloc, nnei) + tab_data_idx = ( + expanded_i_type * ntypes * nspline + j_type * nspline + clipped_indices + ) + # tab_data: (ntype, ntype, nspline, 4) + tab_data = tab_data.view(ntypes * ntypes * nspline, 4) + # tab_data_idx: (nframes * nloc * nnei, 4) + tab_data_idx = tab_data_idx.view(nframes * nloc * nnei, 1).expand(-1, 4) # (nframes, nloc, nnei, 4) - final_coef = torch.gather(expanded_tab_data, 3, clipped_indices).squeeze() + final_coef = torch.gather(tab_data, 0, tab_data_idx).view( + nframes, nloc, nnei, 4 + ) # when the spline idx is beyond the table, all spline coefficients are set to `0`, and the resulting ener corresponding to the idx is also `0`. - final_coef[expanded_idx.squeeze() > nspline] = 0 + final_coef[idx > nspline] = 0 return final_coef @staticmethod From 9b6042b2fba7ba5f9c310c49db5bdb4308499d6e Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:09:43 +0800 Subject: [PATCH 3/3] Fix: Invar_fitting warning msg (#3485) This should fix #3476 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- deepmd/pt/model/task/invar_fitting.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/deepmd/pt/model/task/invar_fitting.py b/deepmd/pt/model/task/invar_fitting.py index 1699b440ac..afb1d73658 100644 --- a/deepmd/pt/model/task/invar_fitting.py +++ b/deepmd/pt/model/task/invar_fitting.py @@ -167,11 +167,7 @@ def compute_output_stats( bias_atom_e = compute_output_stats( merged, self.ntypes, stat_file_path, self.rcond, self.atom_ener ) - self.bias_atom_e.copy_( - torch.tensor(bias_atom_e, device=env.DEVICE).view( - [self.ntypes, self.dim_out] - ) - ) + self.bias_atom_e.copy_(bias_atom_e.view([self.ntypes, self.dim_out])) def output_def(self) -> FittingOutputDef: return FittingOutputDef(