Skip to content

Commit 3d77e59

Browse files
authored
Merge pull request #224 from denghuilu/devel-submit
fix bugs of gelu activation function
2 parents 60634f9 + a6f76b7 commit 3d77e59

File tree

13 files changed

+58
-56
lines changed

13 files changed

+58
-56
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
- CXX=g++-7
8484
- TENSORFLOW_VERSION=2.1
8585
install:
86-
- python -m pip install twine cibuildwheel==1.1.0 scikit-build
86+
- python -m pip install twine cibuildwheel==1.1.0 scikit-build setuptools_scm
8787
script:
8888
- python -m cibuildwheel --output-dir wheelhouse
8989
- python setup.py sdist

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "m2r"]
2+
requires = ["setuptools", "setuptools_scm", "wheel", "scikit-build", "cmake", "ninja", "m2r"]
33

setup.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
from skbuild import setup
22
from skbuild.exceptions import SKBuildError
33
from skbuild.cmaker import get_cmake_version
4+
from setuptools_scm import get_version
45
from packaging.version import LegacyVersion
56
from os import path, makedirs
6-
import imp
7+
import imp, sys, platform
8+
9+
def get_dp_install_path() :
10+
site_packages_path = path.join(path.dirname(path.__file__), 'site-packages')
11+
dp_scm_version = get_version(root="./", relative_to=__file__)
12+
python_version = 'py' + str(sys.version_info.major + sys.version_info.minor * 0.1)
13+
os_info = sys.platform
14+
machine_info = platform.machine()
15+
dp_pip_install_path = site_packages_path + '/deepmd'
16+
dp_setup_install_path = site_packages_path + '/deepmd_kit-' + dp_scm_version + '-' + python_version + '-' + os_info + '-' + machine_info + '.egg/deepmd'
17+
18+
return dp_pip_install_path, dp_setup_install_path
719

820
readme_file = path.join(path.dirname(path.abspath(__file__)), 'README.md')
921
try:
@@ -34,6 +46,8 @@
3446
except OSError:
3547
pass
3648

49+
dp_pip_install_path, dp_setup_install_path = get_dp_install_path()
50+
3751
setup(
3852
name="deepmd-kit",
3953
setup_requires=setup_requires,
@@ -56,6 +70,8 @@
5670
'-DBUILD_PY_IF:BOOL=TRUE',
5771
'-DBUILD_CPP_IF:BOOL=FALSE',
5872
'-DFLOAT_PREC:STRING=high',
73+
'-DDP_PIP_INSTALL_PATH=%s' % dp_pip_install_path,
74+
'-DDP_SETUP_INSTALL_PATH=%s' % dp_setup_install_path,
5975
],
6076
cmake_source_dir='source',
6177
cmake_minimum_required_version='3.0',

source/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ include_directories(${TensorFlow_INCLUDE_DIRS})
184184
if (BUILD_CPP_IF)
185185
set (LIB_DEEPMD "deepmd")
186186
set (LIB_DEEPMD_OP "deepmd_op")
187+
if (USE_CUDA_TOOLKIT)
188+
set (LIB_DEEPMD_OP_CUDA "deepmd_op_cuda")
189+
else ()
190+
set (LIB_DEEPMD_OP_CUDA "deepmd_op")
191+
endif()
187192
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)
188193
set (LIB_DEEPMD_NATIVE "deepmd_native_md")
189194
set (LIB_DEEPMD_IPI "deepmd_ipi")

source/lmp/env.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ TF_RPATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -Wl,-rpath=/g"`
88

99
NNP_INC=" -std=c++11 @PREC_DEF@ @TTM_DEF@ @OLD_LMP_PPPM_DEF@ -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/deepmd "
1010
NNP_PATH=" -L$TF_LIBRARY_PATH -L$DEEPMD_ROOT/lib"
11-
NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_OP@ -l@LIB_DEEPMD@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib"
11+
NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_OP_CUDA@ -l@LIB_DEEPMD_OP@ -l@LIB_DEEPMD@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib"

source/op/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ if (BUILD_CPP_IF)
2424
endif (BUILD_CPP_IF)
2525

2626
if (BUILD_PY_IF)
27+
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
28+
set(CMAKE_INSTALL_RPATH DESTINATION ${DP_PIP_INSTALL_PATH} ${DP_SETUP_INSTALL_PATH} ${CMAKE_BINARY_DIR}/op/cuda)
2729
if (USE_CUDA_TOOLKIT)
2830
add_library(op_abi SHARED ${OP_PY_CUDA_SRC} ${OP_LIB})
2931
add_library(op_grads SHARED ${OP_GRADS_SRC})
@@ -33,11 +35,11 @@ if (BUILD_PY_IF)
3335
set (EXTRA_LIBS ${EXTRA_LIBS} deepmd_op_cuda)
3436
target_link_libraries (op_abi ${EXTRA_LIBS})
3537
target_link_libraries (op_grads ${EXTRA_LIBS})
36-
message(STATUS ${TensorFlowFramework_LIBRARY})
3738
else (USE_CUDA_TOOLKIT)
3839
add_library(op_abi SHARED ${OP_SRC} ${OP_LIB})
3940
add_library(op_grads SHARED ${OP_GRADS_SRC})
4041
endif(USE_CUDA_TOOLKIT)
42+
message(STATUS ${TensorFlowFramework_LIBRARY})
4143
target_link_libraries(
4244
op_abi ${TensorFlowFramework_LIBRARY}
4345
)

source/op/_gelu.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from deepmd.env import op_module
88

99
@ops.RegisterGradient("Gelu")
10-
def gelu_cc (op, dy) :
10+
def _gelu_cc (op, dy) :
1111
return op_module.gelu_grad(dy, op.inputs[0])
1212

1313
@ops.RegisterGradient("GeluGrad")
14-
def gelu_grad_cc (op, dy) :
15-
return [None, op_module.gelu_grad_grad(dy, op.inputs[0], op.inputs[1])]
14+
def _gelu_grad_cc (op, dy) :
15+
return [op_module.gelu_grad(dy, op.inputs[1]), op_module.gelu_grad_grad(dy, op.inputs[0], op.inputs[1])]

source/op/cuda/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ set (SOURCE_FILES
8383
descrpt_se_a.cu descrpt_se_r.cu prod_force_se_a.cu prod_force_se_r.cu prod_virial_se_a.cu prod_virial_se_r.cu gelu.cu
8484
)
8585

86-
cuda_add_library(deepmd_op_cuda STATIC ${SOURCE_FILES})
86+
cuda_add_library(deepmd_op_cuda SHARED ${SOURCE_FILES})
8787

8888
if (BUILD_CPP_IF)
8989
install(TARGETS deepmd_op_cuda DESTINATION lib/)

source/op/gelu.cc

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,20 @@ using GPUDevice = Eigen::GpuDevice;
1111
REGISTER_OP("Gelu")
1212
.Attr("T: {float, double}")
1313
.Input("x: T")
14-
.Output("output: T")
15-
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
16-
c->set_output(0, c->input(0));
17-
return Status::OK();
18-
});
14+
.Output("output: T");
1915

2016
REGISTER_OP("GeluGrad")
2117
.Attr("T: {float, double}")
2218
.Input("dy: T")
2319
.Input("x: T")
24-
.Output("output: T")
25-
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
26-
c->set_output(0, c->input(1));
27-
return Status::OK();
28-
});
20+
.Output("output: T");
2921

3022
REGISTER_OP("GeluGradGrad")
3123
.Attr("T: {float, double}")
3224
.Input("dy: T")
3325
.Input("dy_: T")
3426
.Input("x: T")
35-
.Output("output: T")
36-
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
37-
c->set_output(0, c->input(2));
38-
return Status::OK();
39-
});
27+
.Output("output: T");
4028

4129
template <typename Device, typename T>
4230
struct GeluFunctor {

source/op/gelu_gpu.cc

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,20 @@ using GPUDevice = Eigen::GpuDevice;
1010
REGISTER_OP("Gelu")
1111
.Attr("T: {float, double}")
1212
.Input("x: T")
13-
.Output("output: T")
14-
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
15-
c->set_output(0, c->input(0));
16-
return Status::OK();
17-
});
13+
.Output("output: T");
1814

1915
REGISTER_OP("GeluGrad")
2016
.Attr("T: {float, double}")
2117
.Input("dy: T")
2218
.Input("x: T")
23-
.Output("output: T")
24-
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
25-
c->set_output(0, c->input(1));
26-
return Status::OK();
27-
});
19+
.Output("output: T");
2820

2921
REGISTER_OP("GeluGradGrad")
3022
.Attr("T: {float, double}")
3123
.Input("dy: T")
3224
.Input("dy_: T")
3325
.Input("x: T")
34-
.Output("output: T")
35-
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
36-
c->set_output(0, c->input(2));
37-
return Status::OK();
38-
});
26+
.Output("output: T");
3927

4028
// maybe instead use cudnn activation forward
4129
void GeluLauncher(const float * in, float * out, int const size);

0 commit comments

Comments
 (0)