Skip to content

Commit

Permalink
[Paddle Backend][Fix] Fix wrong custom operator installation filename (
Browse files Browse the repository at this point in the history
…#3127)

1. Fix wrong custom operator installation filename
2. Fix missing file `deepmd/entrypoints/gui.py`
3. Annotated `@cast_precision` and keep brackets `[]` util problems
fixed @SigureMo
  • Loading branch information
HydrogenSulfate authored Jan 10, 2024
1 parent d6cdc35 commit f132a39
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

``` sh
cd ./source/lib/paddle_src
python setup_ins.py install
python custom_op_install.py install
```

安装完毕之后建议运行如下命令测试一下 python 端自定义算子在 CPU、GPU 上的正确性:
Expand Down
13 changes: 9 additions & 4 deletions deepmd/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np

from deepmd.common import (
cast_precision,
get_activation_func,
get_precision,
)
Expand Down Expand Up @@ -973,7 +972,9 @@ def _filter_lower(
transpose_x=True,
)

@cast_precision
# FIXME: @cast_precision should be annotated when convert to static model
# will restore it when it fixed.
# @cast_precision
def _filter(
self,
inputs: paddle.Tensor,
Expand Down Expand Up @@ -1025,8 +1026,12 @@ def _filter(
outputs_size = [1, *self.filter_neuron]
outputs_size_2 = self.n_axis_neuron # 16
all_excluded = all(
(type_input, type_i) in self.exclude_types # set()
for type_i in range(self.ntypes)
# FIXME: the bracket '[]' is needed when convert to static model, will be
# removed when fixed.
[ # noqa
(type_input, type_i) in self.exclude_types # set() noqa
for type_i in range(self.ntypes)
]
)
if all_excluded:
# all types are excluded so result and qmat should be zeros
Expand Down
31 changes: 31 additions & 0 deletions deepmd/entrypoints/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""DP-GUI entrypoint."""


def start_dpgui(*, port: int, bind_all: bool, **kwargs):
"""Host DP-GUI server.
Parameters
----------
port : int
The port to serve DP-GUI on.
bind_all : bool
Serve on all public interfaces. This will expose your DP-GUI instance
to the network on both IPv4 and IPv6 (where available).
**kwargs
additional arguments
Raises
------
ModuleNotFoundError
The dpgui package is not installed
"""
try:
from dpgui import (
start_dpgui,
)
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
"To use DP-GUI, please install the dpgui package:\npip install dpgui"
) from e
start_dpgui(port=port, bind_all=bind_all)
11 changes: 5 additions & 6 deletions deepmd/env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Module that sets tensorflow working environment and exports inportant constants."""

import ctypes
import logging
import os
import platform
Expand Down Expand Up @@ -46,11 +45,11 @@ def dlopen_library(module: str, filename: str):
m = import_module(module)
except ModuleNotFoundError:
pass
else:
libs = sorted(Path(m.__file__).parent.glob(filename))
# hope that there is only one version installed...
if len(libs):
ctypes.CDLL(str(libs[0].absolute()))
# else:
# libs = sorted(Path(m.__file__).parent.glob(filename))
# # hope that there is only one version installed...
# if len(libs):
# ctypes.CDLL(str(libs[0].absolute()))


# dlopen pip cuda library before tensorflow
Expand Down

0 comments on commit f132a39

Please sign in to comment.