Bug summary
I am trying to build DeepMD-kit from source with the PyTorch backend and CUDA enabled. The installation process is currently fragile and significantly under-documented.
The build fails at multiple stages unless several environment variables and Python build dependencies are manually set or installed. These requirements are not clearly documented in the source installation instructions, and some of them appear to be required before the custom PEP 517 build backend can even be imported.
This creates a poor installation experience for users who need to build DeepMD-kit from source for PyTorch/CUDA workflows.
DeePMD-kit Version
Unreleased main branch at 2026/7/4 in the morning
Backend and its version
pytorch 2.11.0 cuda 128 wheel
How did you download the software?
Built from source
Input Files, Running Commands, Error Log, etc.
-DeepMD-kit source tree: 3.2.0b1.dev94+gd279173a1
-Python: 3.12.3
- pip: 26.1.2
- PyTorch: 2.11.0+cu128
- PyTorch CUDA: 12.8
- CUDA Toolkit: 12.8.2, installed via run file.
- CUDA path: /opt/cuda_128
- NVIDIA driver: 580
- GPU: NVIDIA Tesla T4
- OS/container: Bohrium, Ubuntu 24.04 base image, root inside container
Problem 1: CUDA path detection is incomplete for PyTorch/Caffe2
With only CUDAToolkit_ROOT set, DeepMD-kit’s own CMake configuration appears to find CUDA:
-- Found CUDAToolkit: /opt/cuda_128/targets/x86_64-linux/include (found version "12.8.93")
-- Found CUDA in /opt/cuda_128/bin, build nv GPU support
However, PyTorch/Caffe2 then fails:
CUDA_TOOLKIT_ROOT_DIR not found or specified
-- Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY)
CMake Error at .../torch/share/cmake/Caffe2/Caffe2Config.cmake:90 (message):
Your installed Caffe2 version uses CUDA but I cannot find the CUDA
libraries. Please set the proper CUDA prefixes and / or install CUDA.
This means that setting only CUDAToolkit_ROOT is insufficient. Users also need to manually set the older CUDA variables expected indirectly by PyTorch/Caffe2:
export CUDA_HOME=/opt/cuda_128
export CUDA_ROOT=/opt/cuda_128
export CUDA_PATH=/opt/cuda_128
export CUDA_TOOLKIT_ROOT_DIR=/opt/cuda_128
export CUDA_NVCC_EXECUTABLE=/opt/cuda_128/bin/nvcc
export CUDA_INCLUDE_DIRS=/opt/cuda_128/include
export CUDA_CUDART_LIBRARY=/opt/cuda_128/lib64/libcudart.so
export PATH=/opt/cuda_128/bin:$PATH
export LD_LIBRARY_PATH=/opt/cuda_128/lib64:${LD_LIBRARY_PATH:-}
It would be useful if the documentation explicitly stated this, or if the build system propagated CUDAToolkit_ROOT to the legacy variables when building with PyTorch + CUDA.
Problem 2: Custom PEP 517 backend cannot be imported unless source root is added to PYTHONPATH
After trying to work around CUDA detection and using source installation, the build fails with:
BackendUnavailable: Cannot import 'backend.dp_backend'
This appears to require manually setting:
export PYTHONPATH="$(pwd):${PYTHONPATH:-}"
Otherwise, pip cannot import the custom build backend from the source tree.
If this is expected, it should be documented. If not, the pyproject.toml configuration may need to be adjusted, for example with the appropriate backend-path.
Problem 3: Build backend has undeclared Python dependencies
After setting PYTHONPATH, importing the backend fails again because required build-time Python packages are missing.
First failure:
File "/opt/deepmd-kit/backend/dp_backend.py", line 6, in <module>
from scikit_build_core import build as _orig
ModuleNotFoundError: No module named 'scikit_build_core'
After manually installing scikit-build-core, another failure occurs:
File "/opt/deepmd-kit/backend/utils.py", line 7, in <module>
from dependency_groups import (
ModuleNotFoundError: No module named 'dependency_groups'
This suggests that the custom build backend imports packages that are not guaranteed to exist before the backend itself is loaded.
The user currently has to manually install build dependencies such as:
python -m pip install -U \
pip setuptools wheel \
scikit-build-core cmake ninja build \
pyproject-metadata pathspec dependency-groups
These dependencies should either be declared in [build-system].requires or documented clearly before source installation instructions.
Current workaround
The following workaround gets further than the documented/simple installation path:
#!/usr/bin/env bash
set -euo pipefail
python -m pip install -U \
pip setuptools wheel \
scikit-build-core cmake ninja build \
pyproject-metadata pathspec dependency-groups
export DP_ENABLE_PYTORCH=1
export DP_ENABLE_TENSORFLOW=0
export DP_VARIANT=cuda
CUDA_DIR="/opt/cuda_128"
export CUDA_HOME="${CUDA_DIR}"
export CUDA_ROOT="${CUDA_DIR}"
export CUDA_PATH="${CUDA_DIR}"
export CUDAToolkit_ROOT="${CUDA_DIR}"
export CUDA_TOOLKIT_ROOT_DIR="${CUDA_DIR}"
export CUDA_NVCC_EXECUTABLE="${CUDA_DIR}/bin/nvcc"
export CUDA_INCLUDE_DIRS="${CUDA_DIR}/include"
export CUDA_CUDART_LIBRARY="${CUDA_DIR}/lib64/libcudart.so"
export PATH="${CUDA_DIR}/bin:${PATH}"
export LD_LIBRARY_PATH="${CUDA_DIR}/lib64:${LD_LIBRARY_PATH:-}"
export PYTHONPATH="$(pwd):${PYTHONPATH:-}"
export CMAKE_ARGS="-DDP_ENABLE_PYTORCH=ON -DDP_ENABLE_TENSORFLOW=OFF -DDP_VARIANT=cuda -DCUDAToolkit_ROOT=${CUDA_DIR} -DCUDA_TOOLKIT_ROOT_DIR=${CUDA_DIR} -DCUDA_NVCC_EXECUTABLE=${CUDA_DIR}/bin/nvcc -DCUDA_INCLUDE_DIRS=${CUDA_DIR}/include -DCUDA_CUDART_LIBRARY=${CUDA_DIR}/lib64/libcudart.so"
pip install . -v
This is a large amount of undocumented manual configuration for what appears to be a supported PyTorch + CUDA source build.
Expected behavior
For a source build with PyTorch + CUDA, the documentation should clearly specify:
Required Python build dependencies before invoking pip install ..
Required environment variables for CUDA Toolkit discovery.
Whether CUDAToolkit_ROOT alone is sufficient, or whether legacy variables such as CUDA_TOOLKIT_ROOT_DIR, CUDA_NVCC_EXECUTABLE, CUDA_INCLUDE_DIRS, and CUDA_CUDART_LIBRARY must also be set.
Whether PYTHONPATH=$(pwd) is required for the custom build backend, or whether pyproject.toml should handle this automatically.
Whether Python 3.12 is officially supported for source builds with PyTorch + CUDA.
Actual behavior
A straightforward source installation fails repeatedly at different stages:
PyTorch/Caffe2 cannot find CUDA unless several legacy CUDA variables are manually set.
pip cannot import backend.dp_backend unless the source root is added to PYTHONPATH.
The custom backend then fails due to missing build dependencies such as scikit_build_core and dependency_groups.
Request
Please consider improving the source installation documentation and/or build configuration for the PyTorch + CUDA backend.
In particular, it would be very helpful to:
Add a complete documented installation recipe for source builds with DP_ENABLE_PYTORCH=1, DP_ENABLE_TENSORFLOW=0, and DP_VARIANT=cuda.
Add all required build-backend dependencies to [build-system].requires, if missing.
Ensure the custom backend can be imported by pip without requiring users to manually set PYTHONPATH.
Clarify CUDA Toolkit detection behavior for PyTorch/Caffe2 and document the required variables.
Provide a minimal tested Dockerfile or shell script for PyTorch + CUDA source builds.
This is a serious usability issue for users who need to build DeepMD-kit from source in GPU-enabled PyTorch environments.
Steps to Reproduce
Intended configurations:
export DP_ENABLE_PYTORCH=1
export DP_ENABLE_TENSORFLOW=0
export DP_VARIANT=cuda
export CUDAToolkit_ROOT=/opt/cuda_128
pip install .
Further Information, Files, and Links
No response
Bug summary
I am trying to build DeepMD-kit from source with the PyTorch backend and CUDA enabled. The installation process is currently fragile and significantly under-documented.
The build fails at multiple stages unless several environment variables and Python build dependencies are manually set or installed. These requirements are not clearly documented in the source installation instructions, and some of them appear to be required before the custom PEP 517 build backend can even be imported.
This creates a poor installation experience for users who need to build DeepMD-kit from source for PyTorch/CUDA workflows.
DeePMD-kit Version
Unreleased main branch at 2026/7/4 in the morning
Backend and its version
pytorch 2.11.0 cuda 128 wheel
How did you download the software?
Built from source
Input Files, Running Commands, Error Log, etc.
-DeepMD-kit source tree: 3.2.0b1.dev94+gd279173a1
-Python: 3.12.3
Problem 1: CUDA path detection is incomplete for PyTorch/Caffe2
With only CUDAToolkit_ROOT set, DeepMD-kit’s own CMake configuration appears to find CUDA:
-- Found CUDAToolkit: /opt/cuda_128/targets/x86_64-linux/include (found version "12.8.93")
-- Found CUDA in /opt/cuda_128/bin, build nv GPU support
However, PyTorch/Caffe2 then fails:
This means that setting only
CUDAToolkit_ROOTis insufficient. Users also need to manually set the older CUDA variables expected indirectly by PyTorch/Caffe2:It would be useful if the documentation explicitly stated this, or if the build system propagated
CUDAToolkit_ROOTto the legacy variables when building with PyTorch + CUDA.Problem 2: Custom PEP 517 backend cannot be imported unless source root is added to PYTHONPATH
After trying to work around CUDA detection and using source installation, the build fails with:
This appears to require manually setting:
Otherwise, pip cannot import the custom build backend from the source tree.
If this is expected, it should be documented. If not, the
pyproject.tomlconfiguration may need to be adjusted, for example with the appropriate backend-path.Problem 3: Build backend has undeclared Python dependencies
After setting
PYTHONPATH, importing the backend fails again because required build-time Python packages are missing.First failure:
After manually installing scikit-build-core, another failure occurs:
This suggests that the custom build backend imports packages that are not guaranteed to exist before the backend itself is loaded.
The user currently has to manually install build dependencies such as:
These dependencies should either be declared in [build-system].requires or documented clearly before source installation instructions.
Current workaround
The following workaround gets further than the documented/simple installation path:
This is a large amount of undocumented manual configuration for what appears to be a supported PyTorch + CUDA source build.
Expected behavior
For a source build with PyTorch + CUDA, the documentation should clearly specify:
Required Python build dependencies before invoking pip install ..
Required environment variables for CUDA Toolkit discovery.
Whether
CUDAToolkit_ROOTalone is sufficient, or whether legacy variables such asCUDA_TOOLKIT_ROOT_DIR,CUDA_NVCC_EXECUTABLE,CUDA_INCLUDE_DIRS, andCUDA_CUDART_LIBRARYmust also be set.Whether
PYTHONPATH=$(pwd)is required for the custom build backend, or whether pyproject.toml should handle this automatically.Whether Python 3.12 is officially supported for source builds with PyTorch + CUDA.
Actual behavior
A straightforward source installation fails repeatedly at different stages:
PyTorch/Caffe2 cannot find CUDA unless several legacy CUDA variables are manually set.
pip cannot import backend.dp_backend unless the source root is added to
PYTHONPATH.The custom backend then fails due to missing build dependencies such as scikit_build_core and dependency_groups.
Request
Please consider improving the source installation documentation and/or build configuration for the PyTorch + CUDA backend.
In particular, it would be very helpful to:
Add a complete documented installation recipe for source builds with
DP_ENABLE_PYTORCH=1,DP_ENABLE_TENSORFLOW=0, andDP_VARIANT=cuda.Add all required build-backend dependencies to
[build-system].requires, if missing.Ensure the custom backend can be imported by pip without requiring users to manually set
PYTHONPATH.Clarify CUDA Toolkit detection behavior for PyTorch/Caffe2 and document the required variables.
Provide a minimal tested Dockerfile or shell script for PyTorch + CUDA source builds.
This is a serious usability issue for users who need to build DeepMD-kit from source in GPU-enabled PyTorch environments.
Steps to Reproduce
Intended configurations:
Further Information, Files, and Links
No response