Skip to content

Commit 2d4c615

Browse files
authored
feat: enable PyTorch custom ops by default (deepmodeling#5578)
## Summary - change the `DP_ENABLE_PYTORCH` build-time default from `0` to `1` in the build backend - update the install-from-source docs to describe PyTorch customized C++ OPs as enabled by default - adjust related model/compression docs so they no longer tell users to set `DP_ENABLE_PYTORCH=1` explicitly ## Tests - `python3 -m py_compile backend/find_pytorch.py backend/read_env.py deepmd/pt/cxx_op.py` - `git diff --check` - `uv run --no-project --with dependency-groups --with packaging python` smoke checks for default `-DENABLE_PYTORCH=ON` and explicit `DP_ENABLE_PYTORCH=0` -> `-DENABLE_PYTORCH=OFF` Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * PyTorch backend customized C++ OPs now enabled by default when building from source. * **Bug Fixes** * Corrected error messages and installation guidance for PyTorch backend issues. * **Documentation** * Updated installation and model documentation to reflect PyTorch backend enabled by default. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 2b3bb05 commit 2d4c615

7 files changed

Lines changed: 10 additions & 10 deletions

File tree

backend/find_pytorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def find_pytorch() -> tuple[str | None, list[str]]:
4949
str, optional
5050
PyTorch library path if found.
5151
list of str
52-
TensorFlow requirement if not found. Empty if found.
52+
PyTorch requirement if not found. Empty if found.
5353
"""
54-
if os.environ.get("DP_ENABLE_PYTORCH", "0") == "0":
54+
if os.environ.get("DP_ENABLE_PYTORCH", "1") == "0":
5555
return None, []
5656
requires = []
5757
pt_spec = None

backend/read_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_argument_from_env() -> tuple[str, list, list, dict, str, str]:
104104
cmake_args.append("-DENABLE_TENSORFLOW=OFF")
105105
tf_version = None
106106

107-
if os.environ.get("DP_ENABLE_PYTORCH", "0") == "1":
107+
if os.environ.get("DP_ENABLE_PYTORCH", "1") == "1":
108108
pt_install_dir, _ = find_pytorch()
109109
pt_version = get_pt_version(pt_install_dir)
110110
cmake_args.extend(

deepmd/pt/cxx_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def load_library(module_name: str) -> bool:
8383
f"incompatible and thus an error is raised when loading {module_name}. "
8484
f"You need to install PyTorch {PT_VERSION}, or rebuild deepmd-kit "
8585
f"against PyTorch {pt_py_version}.\nIf you are using a wheel from "
86-
"PyPI, you may consider to install deepmd-kit execuating "
87-
"`DP_ENABLE_PYTORCH=1 pip install deepmd-kit --no-binary deepmd-kit` "
86+
"PyPI, you may consider rebuilding deepmd-kit with "
87+
"`pip install deepmd-kit --no-binary deepmd-kit` "
8888
"instead."
8989
) from e
9090
error_message = (

doc/freeze/compress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ See the documentation of a specific descriptor to see whether it supports model
125125

126126
When compressing models in the PyTorch backend, the customized OP library for the Python interface must be installed when [freezing the model](../freeze/freeze.md).
127127

128-
The customized OP library for the Python interface can be installed by setting environment variable {envvar}`DP_ENABLE_PYTORCH` to `1` during [installation](../install/install-from-source.md).
128+
The customized OP library for the Python interface is installed by default when building DeePMD-kit from source; see the [installation guide](../install/install-from-source.md) for details.
129129

130130
[^1]: This section is built upon Jinzhe Zeng, Duo Zhang, Denghui Lu, Pinghui Mo, Zeyu Li, Yixiao Chen, Marián Rynik, Li'ang Huang, Ziyao Li, Shaochen Shi, Yingze Wang, Haotian Ye, Ping Tuo, Jiabin Yang, Ye Ding, Yifan Li, Davide Tisi, Qiyu Zeng, Han Bao, Yu Xia, Jiameng Huang, Koki Muraoka, Yibo Wang, Junhan Chang, Fengbo Yuan, Sigbjørn Løland Bore, Chun Cai, Yinnian Lin, Bo Wang, Jiayan Xu, Jia-Xin Zhu, Chenxing Luo, Yuzhi Zhang, Rhys E. A. Goodall, Wenshuo Liang, Anurag Kumar Singh, Sikai Yao, Jingchao Zhang, Renata Wentzcovitch, Jiequn Han, Jie Liu, Weile Jia, Darrin M. York, Weinan E, Roberto Car, Linfeng Zhang, Han Wang, [J. Chem. Phys. 159, 054801 (2023)](https://doi.org/10.1063/5.0155600) licensed under a [Creative Commons Attribution (CC BY) license](http://creativecommons.org/licenses/by/4.0/).

doc/install/install-from-source.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Note that TensorFlow may have specific requirements for the compiler version to
151151

152152
:::{tab-item} PyTorch {{ pytorch_icon }}
153153

154-
You can set the environment variable `export DP_ENABLE_PYTORCH=1` to enable customized C++ OPs in the PyTorch backend.
154+
Customized C++ OPs in the PyTorch backend are enabled by default when building the Python interface.
155155
Note that PyTorch may have specific requirements for the compiler version to support the C++ standard version and [`_GLIBCXX_USE_CXX11_ABI`](https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html) used by PyTorch.
156156
:::
157157

@@ -196,7 +196,7 @@ The path to the ROCM toolkit directory. If `ROCM_ROOT` is not set, it will look
196196

197197
:::{envvar} DP_ENABLE_PYTORCH
198198

199-
**Choices**: `0`, `1`; **Default**: `0`
199+
**Choices**: `0`, `1`; **Default**: `1`
200200

201201
{{ pytorch_icon }} Enable customized C++ OPs for the PyTorch backend. PyTorch can still run without customized C++ OPs, but features will be limited.
202202
:::

doc/model/dpa2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ DPA-2 is designed for multi-task pre-training with a shared descriptor and task-
5858

5959
If one wants to run the DPA-2 model on LAMMPS, the customized OP library for the Python interface must be installed when [freezing the model](../freeze/freeze.md).
6060

61-
The customized OP library for the Python interface can be installed by setting environment variable {envvar}`DP_ENABLE_PYTORCH` to `1` during installation.
61+
The customized OP library for the Python interface is installed by default when building DeePMD-kit from source.
6262

6363
If one runs LAMMPS with MPI, the customized OP library for the C++ interface should be compiled against the same MPI library as the runtime MPI.
6464
If one runs LAMMPS with MPI and CUDA devices, it is recommended to compile the customized OP library for the C++ interface with a [CUDA-Aware MPI](https://developer.nvidia.com/mpi-solutions-gpus) library and CUDA,

doc/model/dpa3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ To run the DPA3 model on LAMMPS via source code installation
130130
the custom OP library for Python interface integration must be compiled and linked
131131
during the [model freezing process](../freeze/freeze.md).
132132

133-
The customized OP library for the Python interface can be installed by setting environment variable {envvar}`DP_ENABLE_PYTORCH` to `1` during installation.
133+
The customized OP library for the Python interface is installed by default when building DeePMD-kit from source.
134134

135135
If one runs LAMMPS with MPI, the customized OP library for the C++ interface should be compiled against the same MPI library as the runtime MPI.
136136
If one runs LAMMPS with MPI and CUDA devices, it is recommended to compile the customized OP library for the C++ interface with a [CUDA-Aware MPI](https://developer.nvidia.com/mpi-solutions-gpus) library and CUDA,

0 commit comments

Comments
 (0)