From 15bc66d46fda851c21a42ad1a8586f5c8034d37d Mon Sep 17 00:00:00 2001 From: qianhaohao Date: Wed, 1 Dec 2021 20:55:51 +0800 Subject: [PATCH 1/2] add separate compilation for feature engineering --- CMakeLists.txt | 5 +- {feature => core}/he/CMakeLists.txt | 3 + {feature => core}/he/he_utils.cc | 0 {feature => core}/he/paillier.cc | 0 {feature => core}/he/paillier.h | 0 feature/python/example/README.md | 54 ---------- .../paddle_fl/feature_engineering/README.md | 101 ++++++++++++++++++ .../paddle_fl/feature_engineering/__init__.py | 28 +++++ .../feature_engineering}/core/__init__.py | 8 +- .../federated_feature_engineering_client.py | 8 +- .../federated_feature_engineering_server.py | 8 +- .../core/metrics_client.py | 7 +- .../core/metrics_server.py | 7 +- .../feature_engineering}/example/__init__.py | 0 .../example/gen_test_file.py | 0 .../example/metrics_plain.py | 0 .../example/metrics_test_client.py | 11 +- .../example/metrics_test_server.py | 11 +- .../feature_engineering/proto}/__init__.py | 6 +- .../feature_engineering}/proto/metrics.proto | 0 .../proto/run_protogen.py | 6 +- python/paddle_fl/feature_engineering/setup.py | 98 +++++++++++++++++ .../paddle_fl/feature_engineering/version.py | 16 +++ 23 files changed, 275 insertions(+), 102 deletions(-) rename {feature => core}/he/CMakeLists.txt (71%) rename {feature => core}/he/he_utils.cc (100%) rename {feature => core}/he/paillier.cc (100%) rename {feature => core}/he/paillier.h (100%) delete mode 100644 feature/python/example/README.md create mode 100644 python/paddle_fl/feature_engineering/README.md create mode 100644 python/paddle_fl/feature_engineering/__init__.py rename {feature/python => python/paddle_fl/feature_engineering}/core/__init__.py (73%) rename feature/python/core/federal_feature_engineering_client.py => python/paddle_fl/feature_engineering/core/federated_feature_engineering_client.py (93%) rename feature/python/core/federal_feature_engineering_server.py => python/paddle_fl/feature_engineering/core/federated_feature_engineering_server.py (93%) rename {feature/python => python/paddle_fl/feature_engineering}/core/metrics_client.py (99%) rename {feature/python => python/paddle_fl/feature_engineering}/core/metrics_server.py (99%) rename {feature/python => python/paddle_fl/feature_engineering}/example/__init__.py (100%) rename {feature/python => python/paddle_fl/feature_engineering}/example/gen_test_file.py (100%) rename {feature/python => python/paddle_fl/feature_engineering}/example/metrics_plain.py (100%) rename {feature/python => python/paddle_fl/feature_engineering}/example/metrics_test_client.py (91%) rename {feature/python => python/paddle_fl/feature_engineering}/example/metrics_test_server.py (89%) rename {feature/python => python/paddle_fl/feature_engineering/proto}/__init__.py (88%) rename {feature => python/paddle_fl/feature_engineering}/proto/metrics.proto (100%) rename {feature => python/paddle_fl/feature_engineering}/proto/run_protogen.py (87%) create mode 100644 python/paddle_fl/feature_engineering/setup.py create mode 100644 python/paddle_fl/feature_engineering/version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 05111dcc..dabbdaeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ if (USE_ABY3_TRUNC1) endif(USE_ABY3_TRUNC1) add_subdirectory(core/common) -add_subdirectory(feature/he) +add_subdirectory(core/he) if (NOT WITH_GPU) add_subdirectory(core/privc) endif() @@ -171,9 +171,6 @@ install(DIRECTORY "${THIRD_PARTY_PATH}/install/openssl/lib/" install(TARGETS paddle_enc mpc_data_utils LIBRARY DESTINATION ${PADDLE_ENCRYPTED_LIB_PATH} LIBRARY DESTINATION ${PADDLE_ENCRYPTED_LIB_PATH}) - -set(FEATURE_LIB "${CMAKE_SOURCE_DIR}/feature/python/libs") -install(TARGETS he_utils LIBRARY DESTINATION ${FEATURE_LIB}) if (WITH_PSI) install(TARGETS psi LIBRARY DESTINATION ${PADDLE_ENCRYPTED_LIB_PATH}) diff --git a/feature/he/CMakeLists.txt b/core/he/CMakeLists.txt similarity index 71% rename from feature/he/CMakeLists.txt rename to core/he/CMakeLists.txt index 6acc4a89..f5a33972 100644 --- a/feature/he/CMakeLists.txt +++ b/core/he/CMakeLists.txt @@ -12,3 +12,6 @@ include_directories(${PYTHON_INCLUDE_DIRS}) add_library(he_utils MODULE ${PYBIND_HE_SRCS}) target_link_libraries(he_utils PRIVATE pybind gmp gmpxx) set_target_properties(he_utils PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}") + +set(FEATURE_LIB "${CMAKE_SOURCE_DIR}/python/paddle_fl/feature_engineering/libs") +install(TARGETS he_utils LIBRARY DESTINATION ${FEATURE_LIB}) diff --git a/feature/he/he_utils.cc b/core/he/he_utils.cc similarity index 100% rename from feature/he/he_utils.cc rename to core/he/he_utils.cc diff --git a/feature/he/paillier.cc b/core/he/paillier.cc similarity index 100% rename from feature/he/paillier.cc rename to core/he/paillier.cc diff --git a/feature/he/paillier.h b/core/he/paillier.h similarity index 100% rename from feature/he/paillier.h rename to core/he/paillier.h diff --git a/feature/python/example/README.md b/feature/python/example/README.md deleted file mode 100644 index 79e6c712..00000000 --- a/feature/python/example/README.md +++ /dev/null @@ -1,54 +0,0 @@ -## 联邦特征工程 - -支持计算正样本占比、woe、iv - -## 准备工作 - -编译paillier(参照docs/source/md/compile_and_install_cn.md 编译PaddleFL) -``` -cd ../../../build -make -j48 -make install -``` -完成后在feature/python/libs 目录下会有 he_utils.so - -生成proto -``` -cd ../feature/proto -python3 run_protogen.py -``` - -## 准备数据 -``` -cd ../python/example -python3 gen_test_file.py -``` -简单测试: gen_simple_file 性能测试: gen_bench_file -## 生成证书 -生成grpc证书 grpc secure channel 需要用到 - -``` -openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 3650 -out server.crt -``` -示例中定义Common Name 为 metrics_service 其余为空 - -在example目录下会生成 server.key server.crt - -## 流程示例 -channel: grpc client channel 可自定义 - -server: grpc server 可自定义 -``` -#client - fed_fea_eng_client = FederalFeatureEngineeringClient(1024) - fed_fea_eng_client.connect(channel) - result = fed_fea_eng_client.get_woe(labels) -#server - fed_fea_eng_server = FederalFeatureEngineeringServer() - fed_fea_eng_server.serve(server) - woe_list = fed_fea_eng_server.get_woe(features) -``` -## 具体例子及测试 -服务器端:python3 metrics_test_server.py - -客户端: python3 metrics_test_client.py diff --git a/python/paddle_fl/feature_engineering/README.md b/python/paddle_fl/feature_engineering/README.md new file mode 100644 index 00000000..33637911 --- /dev/null +++ b/python/paddle_fl/feature_engineering/README.md @@ -0,0 +1,101 @@ +## 联邦特征工程 + +支持计算正样本占比、woe、iv + +## 单独编译 + +### 环境准备 +* CentOS 7 (64 bit) or Ubuntu 16.04 +* Python 3.5/3.6/3.7 ( 64 bit) or above +* pip3 9.0.1+ (64 bit) +* GCC or G++ 8.2.0+ +* cmake 3.15+ +* grpcio +* grpcio-tools + + +### 克隆源码并安装 + +1.获取源代码 +```sh +git clone https://github.com/PaddlePaddle/PaddleFL +cd /path/to/PaddleFL +mkdir build && cd build +``` + +2.执行部分编译指令(参照 docs/source/md/compile_and_install_cn.md ) + +``` +cmake .. -DCMAKE_C_COMPILER=${gcc_path} -DCMAKE_CXX_COMPILER=${g++_path} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DPYTHON_INCLUDE_DIRS=${PYTHON_INCLUDE_DIRS} -DBUILD_PADDLE_FROM_SOURCE=ON -DWITH_GRPC=ON -DWITH_GPU=OFF +``` + +``` +cd core/he +make -j48 +make install +``` + +3.生成grpc_pb +``` +cd /path/to/PaddleFL/python +python3 paddle_fl/feature_engineering/proto/run_protogen.py +``` + +4.pip打包并安装 +``` +cd /path/to/PaddleFL/python/paddle_fl +mkdir build && cd build +python3 ../feature_engineering/setup.py sdist bdist_wheel +pip3 install dist/paddle_fl_feature_engineering-1.2.0-py3-none-any.whl -U +``` +## 跟随paddlefl编译 +不久后将支持 + +## 测试 + +1.准备数据 +``` +cd /path/to/PaddleFL/python/paddle_fl/feature_engineering/example +python3 gen_test_file.py +``` +简单测试: gen_simple_file 性能测试: gen_bench_file + +2.生成证书 +生成grpc证书 grpc secure channel 需要 + +``` +openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 3650 -out server.crt +``` +示例中定义Common Name 为 metrics_service 其余为空 + +在example目录下会生成 server.key server.crt + +3.进行测试 + +服务器端:python3 metrics_test_server.py + +客户端: python3 metrics_test_client.py + +## 构建自己的程序 + +我们提供了pip打包支持,用户只需在自己的程序中 import paddle_fl.feature_engineering.core 即可,grpc通信模块可由用户自定义 + +示例如下: + +channel: grpc client channel 自定义 + +server: grpc server 自定义 + +``` +#client + from paddle_fl.feature_engineering.core.federated_feature_engineering_client import FederatedFeatureEngineeringClient + fed_fea_eng_client = FederatedFeatureEngineeringClient(1024) + fed_fea_eng_client.connect(channel) + result = fed_fea_eng_client.get_woe(labels) + +#server + from paddle_fl.feature_engineering.core.federated_feature_engineering_server import FederatedFeatureEngineeringServer + fed_fea_eng_server = FederatedFeatureEngineeringServer() + fed_fea_eng_server.serve(server) + woe_list = fed_fea_eng_server.get_woe(features) +``` \ No newline at end of file diff --git a/python/paddle_fl/feature_engineering/__init__.py b/python/paddle_fl/feature_engineering/__init__.py new file mode 100644 index 00000000..53fd7b2f --- /dev/null +++ b/python/paddle_fl/feature_engineering/__init__.py @@ -0,0 +1,28 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Import modules. +""" + +import os +import sysconfig +import sys + +he_utils_path = sysconfig.get_paths()["purelib"] + "/paddle_fl/feature_engineering/libs" +he_utils_lib = he_utils_path + '/he_utils.so' +sys.path.append(he_utils_path) +os.system('patchelf --set-rpath {} {}'.format(he_utils_path, he_utils_lib)) + +from . import core + diff --git a/feature/python/core/__init__.py b/python/paddle_fl/feature_engineering/core/__init__.py similarity index 73% rename from feature/python/core/__init__.py rename to python/paddle_fl/feature_engineering/core/__init__.py index 6b7f8e53..10c9904c 100644 --- a/feature/python/core/__init__.py +++ b/python/paddle_fl/feature_engineering/core/__init__.py @@ -14,5 +14,9 @@ """ init """ -from .federal_feature_engineering_client import FederalFeatureEngineeringClient -from .federal_feature_engineering_server import FederalFeatureEngineeringServer \ No newline at end of file + +from .federated_feature_engineering_client import FederatedFeatureEngineeringClient +from .federated_feature_engineering_server import FederatedFeatureEngineeringServer + +from .metrics_client import * +from .metrics_server import * \ No newline at end of file diff --git a/feature/python/core/federal_feature_engineering_client.py b/python/paddle_fl/feature_engineering/core/federated_feature_engineering_client.py similarity index 93% rename from feature/python/core/federal_feature_engineering_client.py rename to python/paddle_fl/feature_engineering/core/federated_feature_engineering_client.py index c8b14ed9..6a8093d3 100644 --- a/feature/python/core/federal_feature_engineering_client.py +++ b/python/paddle_fl/feature_engineering/core/federated_feature_engineering_client.py @@ -12,15 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License """ -Federal feature engineering client-side +Federated feature engineering client-side support postive_ratio, woe, iv, ks, auc """ -import metrics_client as mc +from . import metrics_client as mc -class FederalFeatureEngineeringClient(object): +class FederatedFeatureEngineeringClient(object): """ - Federal feature engineering client-side implementation + Federated feature engineering client-side implementation """ def __init__(self, key_len=1024): """ diff --git a/feature/python/core/federal_feature_engineering_server.py b/python/paddle_fl/feature_engineering/core/federated_feature_engineering_server.py similarity index 93% rename from feature/python/core/federal_feature_engineering_server.py rename to python/paddle_fl/feature_engineering/core/federated_feature_engineering_server.py index ecfe8618..bc4dbbb0 100644 --- a/feature/python/core/federal_feature_engineering_server.py +++ b/python/paddle_fl/feature_engineering/core/federated_feature_engineering_server.py @@ -12,16 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License """ -Federal feature engineering server-side interface +Federated feature engineering server-side interface support postive_ratio, woe, iv, ks, auc """ import threading -import metrics_server as ms +from . import metrics_server as ms -class FederalFeatureEngineeringServer(object): +class FederatedFeatureEngineeringServer(object): """ - Federal feature engineering server-side implementation + Federated feature engineering server-side implementation """ def serve(self, server): """ diff --git a/feature/python/core/metrics_client.py b/python/paddle_fl/feature_engineering/core/metrics_client.py similarity index 99% rename from feature/python/core/metrics_client.py rename to python/paddle_fl/feature_engineering/core/metrics_client.py index 4e795778..82219cea 100644 --- a/feature/python/core/metrics_client.py +++ b/python/paddle_fl/feature_engineering/core/metrics_client.py @@ -21,12 +21,9 @@ import numpy as np import grpc -import sys -sys.path.append("../libs") - import he_utils as hu -import metrics_pb2 -import metrics_pb2_grpc +from ..proto import metrics_pb2_grpc +from ..proto import metrics_pb2 __all__ = [ 'get_mpc_postive_ratio_alice', diff --git a/feature/python/core/metrics_server.py b/python/paddle_fl/feature_engineering/core/metrics_server.py similarity index 99% rename from feature/python/core/metrics_server.py rename to python/paddle_fl/feature_engineering/core/metrics_server.py index 6ae7d826..6cc81e14 100644 --- a/feature/python/core/metrics_server.py +++ b/python/paddle_fl/feature_engineering/core/metrics_server.py @@ -21,12 +21,9 @@ import numpy as np import grpc -import sys -sys.path.append("../libs") - import he_utils as hu -import metrics_pb2 -import metrics_pb2_grpc +from ..proto import metrics_pb2 +from ..proto import metrics_pb2_grpc class MpcPositiveRatioServicer(metrics_pb2_grpc.MpcPositiveRatioServicer): diff --git a/feature/python/example/__init__.py b/python/paddle_fl/feature_engineering/example/__init__.py similarity index 100% rename from feature/python/example/__init__.py rename to python/paddle_fl/feature_engineering/example/__init__.py diff --git a/feature/python/example/gen_test_file.py b/python/paddle_fl/feature_engineering/example/gen_test_file.py similarity index 100% rename from feature/python/example/gen_test_file.py rename to python/paddle_fl/feature_engineering/example/gen_test_file.py diff --git a/feature/python/example/metrics_plain.py b/python/paddle_fl/feature_engineering/example/metrics_plain.py similarity index 100% rename from feature/python/example/metrics_plain.py rename to python/paddle_fl/feature_engineering/example/metrics_plain.py diff --git a/feature/python/example/metrics_test_client.py b/python/paddle_fl/feature_engineering/example/metrics_test_client.py similarity index 91% rename from feature/python/example/metrics_test_client.py rename to python/paddle_fl/feature_engineering/example/metrics_test_client.py index a4f99394..dd3e8b9e 100644 --- a/feature/python/example/metrics_test_client.py +++ b/python/paddle_fl/feature_engineering/example/metrics_test_client.py @@ -15,15 +15,12 @@ mpc metrics test client-side """ -import sys -sys.path.append("../core") - import time import grpc import gen_test_file import metrics_plain -from federal_feature_engineering_client import FederalFeatureEngineeringClient +from paddle_fl.feature_engineering.core.federated_feature_engineering_client import FederatedFeatureEngineeringClient SERVER_ADRESS = 'localhost:50051' @@ -48,7 +45,7 @@ def postive_ratio_test_client(file_name): """ labels, features = gen_test_file.read_file(file_name) - fed_fea_eng_client = FederalFeatureEngineeringClient(1024) + fed_fea_eng_client = FederatedFeatureEngineeringClient(1024) channel = gen_client_channel(SERVER_ADRESS) fed_fea_eng_client.connect(channel) result = fed_fea_eng_client.get_positive_ratio(labels) @@ -63,7 +60,7 @@ def woe_test_client(file_name): """ labels, features = gen_test_file.read_file(file_name) - fed_fea_eng_client = FederalFeatureEngineeringClient(1024) + fed_fea_eng_client = FederatedFeatureEngineeringClient(1024) channel = gen_client_channel(SERVER_ADRESS) fed_fea_eng_client.connect(channel) result = fed_fea_eng_client.get_woe(labels) @@ -78,7 +75,7 @@ def iv_test_client(file_name): """ labels, features = gen_test_file.read_file(file_name) - fed_fea_eng_client = FederalFeatureEngineeringClient(1024) + fed_fea_eng_client = FederatedFeatureEngineeringClient(1024) channel = gen_client_channel(SERVER_ADRESS) fed_fea_eng_client.connect(channel) result = fed_fea_eng_client.get_iv(labels) diff --git a/feature/python/example/metrics_test_server.py b/python/paddle_fl/feature_engineering/example/metrics_test_server.py similarity index 89% rename from feature/python/example/metrics_test_server.py rename to python/paddle_fl/feature_engineering/example/metrics_test_server.py index 77aabbe4..c0dd4c16 100644 --- a/feature/python/example/metrics_test_server.py +++ b/python/paddle_fl/feature_engineering/example/metrics_test_server.py @@ -15,16 +15,13 @@ mpc metrics test server-side """ -import sys -sys.path.append("../core") - from concurrent import futures import time import grpc import gen_test_file import metrics_plain -from federal_feature_engineering_server import FederalFeatureEngineeringServer +from paddle_fl.feature_engineering.core.federated_feature_engineering_server import FederatedFeatureEngineeringServer SERVER_ADRESS = 'localhost:50051' @@ -51,7 +48,7 @@ def postive_ratio_test_server(file_name): """ labels, features = gen_test_file.read_file(file_name) server = gen_server() - fed_fea_eng_server = FederalFeatureEngineeringServer() + fed_fea_eng_server = FederatedFeatureEngineeringServer() fed_fea_eng_server.serve(server) fed_fea_eng_server.get_positive_ratio(features) @@ -62,7 +59,7 @@ def woe_test_server(file_name): """ labels, features = gen_test_file.read_file(file_name) server = gen_server() - fed_fea_eng_server = FederalFeatureEngineeringServer() + fed_fea_eng_server = FederatedFeatureEngineeringServer() fed_fea_eng_server.serve(server) woe_list = fed_fea_eng_server.get_woe(features) print("server woe is \n", woe_list) @@ -74,7 +71,7 @@ def iv_test_server(file_name): """ labels, features = gen_test_file.read_file(file_name) server = gen_server() - fed_fea_eng_server = FederalFeatureEngineeringServer() + fed_fea_eng_server = FederatedFeatureEngineeringServer() fed_fea_eng_server.serve(server) iv_list = fed_fea_eng_server.get_iv(features) print("server iv is \n", iv_list) diff --git a/feature/python/__init__.py b/python/paddle_fl/feature_engineering/proto/__init__.py similarity index 88% rename from feature/python/__init__.py rename to python/paddle_fl/feature_engineering/proto/__init__.py index e52a4482..0d60b524 100644 --- a/feature/python/__init__.py +++ b/python/paddle_fl/feature_engineering/proto/__init__.py @@ -10,8 +10,4 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. -""" -Import modules. -""" -from . import core \ No newline at end of file +# limitations under the License \ No newline at end of file diff --git a/feature/proto/metrics.proto b/python/paddle_fl/feature_engineering/proto/metrics.proto similarity index 100% rename from feature/proto/metrics.proto rename to python/paddle_fl/feature_engineering/proto/metrics.proto diff --git a/feature/proto/run_protogen.py b/python/paddle_fl/feature_engineering/proto/run_protogen.py similarity index 87% rename from feature/proto/run_protogen.py rename to python/paddle_fl/feature_engineering/proto/run_protogen.py index b950b610..181e558c 100644 --- a/feature/proto/run_protogen.py +++ b/python/paddle_fl/feature_engineering/proto/run_protogen.py @@ -20,8 +20,4 @@ '-I.', '--python_out=.', '--grpc_python_out=.', - 'metrics.proto', )) - -import os -os.system("mv *pb2.py ../python/core") -os.system("mv *pb2_grpc.py ../python/core") \ No newline at end of file + 'paddle_fl/feature_engineering/proto/metrics.proto', )) diff --git a/python/paddle_fl/feature_engineering/setup.py b/python/paddle_fl/feature_engineering/setup.py new file mode 100644 index 00000000..6c608b83 --- /dev/null +++ b/python/paddle_fl/feature_engineering/setup.py @@ -0,0 +1,98 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Setup file for python code install +""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os +import platform +import sys + +from setuptools import find_packages +from setuptools import setup +from version import fl_version + +def python_version(): + """ + get python version + """ + return [int(v) for v in platform.python_version().split(".")] + +max_version, mid_version, min_version = python_version() + +pflfe_name = "paddle_fl_feature_engineering" + +REQUIRED_PACKAGES = [ + 'six >= 1.10.0', 'protobuf >= 3.1.0' +] + +if max_version < 3: + REQUIRED_PACKAGES += ["enum"] +else: + REQUIRED_PACKAGES += ["numpy"] + +REQUIRED_PACKAGES += ["unittest2"] +packages = [ + 'paddle_fl.feature_engineering', + 'paddle_fl.feature_engineering.core', + 'paddle_fl.feature_engineering.proto', +] +package_data = { + 'paddle_fl.feature_engineering': ['libs/*'] +} +package_dir = { + 'paddle_fl.feature_engineering': '../feature_engineering', + 'paddle_fl.feature_engineering.core': '../feature_engineering/core', + 'paddle_fl.feature_engineering.proto': '../feature_engineering/proto' +} + +setup( + name=pflfe_name, + version=fl_version.replace('-', ''), + description=( + 'Federated Feature Engineering Package Baed On PaddleFL'), + long_description='', + url='https://github.com/PaddlePaddle/PaddleFL', + author='PaddlePaddle Author', + author_email='paddle-dev@baidu.com', + install_requires=REQUIRED_PACKAGES, + packages=packages, + package_data=package_data, + package_dir=package_dir, + # PyPI package information. + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'Intended Audience :: Education', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: Apache Software License', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Topic :: Scientific/Engineering', + 'Topic :: Scientific/Engineering :: Mathematics', + 'Topic :: Scientific/Engineering :: Artificial Intelligence', + 'Topic :: Software Development', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + license='Apache 2.0', + keywords=( + 'paddle_fl paddlepaddle multi-task transfer distributed-training multiparty-computation privacy-preserving' + )) diff --git a/python/paddle_fl/feature_engineering/version.py b/python/paddle_fl/feature_engineering/version.py new file mode 100644 index 00000000..8fa95ef7 --- /dev/null +++ b/python/paddle_fl/feature_engineering/version.py @@ -0,0 +1,16 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" PaddleFL version string """ +fl_version = "1.2.0" +module_proto_version = "1.2.0" From 21bfc1616c4452fe6b25bb977e56986ca1c7df0d Mon Sep 17 00:00:00 2001 From: qianhaohao Date: Fri, 3 Dec 2021 13:06:00 +0800 Subject: [PATCH 2/2] add cmake for python grpc proto --- cmake/external/grpc.cmake | 1 + cmake/generic.cmake | 30 +++++++++++++++++++ core/he/CMakeLists.txt | 7 +++++ .../paddle_fl/feature_engineering/README.md | 8 +---- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/cmake/external/grpc.cmake b/cmake/external/grpc.cmake index bdbd13a4..91b3173f 100644 --- a/cmake/external/grpc.cmake +++ b/cmake/external/grpc.cmake @@ -19,6 +19,7 @@ SET(GRPC_SOURCES_DIR ${THIRD_PARTY_PATH}/grpc) SET(GRPC_INSTALL_DIR ${THIRD_PARTY_PATH}/install/grpc) SET(GRPC_INCLUDE_DIR "${GRPC_INSTALL_DIR}/include/" CACHE PATH "grpc include directory." FORCE) SET(GRPC_CPP_PLUGIN "${GRPC_INSTALL_DIR}/bin/grpc_cpp_plugin" CACHE FILEPATH "GRPC_CPP_PLUGIN" FORCE) +SET(GRPC_PYTHON_PLUGIN "${GRPC_INSTALL_DIR}/bin/grpc_python_plugin" CACHE FILEPATH "GRPC_PYTHON_PLUGIN" FORCE) include(ProcessorCount) ProcessorCount(NUM_OF_PROCESSOR) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index c0275cac..f078b535 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -714,6 +714,36 @@ function(py_proto_compile TARGET_NAME) add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs} protobuf) endfunction() +function(py_proto_grpc_compile TARGET_NAME) + set(oneValueArgs PROTO PROTO_PATH) + set(multiValueArgs SRCS) + set(options "") + cmake_parse_arguments(py_proto_grpc_compile "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + get_filename_component(ABS_PROTO ${py_proto_grpc_compile_PROTO} ABSOLUTE) + get_filename_component(PROTO_WE ${py_proto_grpc_compile_PROTO} NAME_WE) + #get_filename_component(PROTO_PATH ${ABS_PROTO} PATH) + set(PROTO_PATH ${py_proto_grpc_compile_PROTO_PATH}) + + set(grpc_proto_py "${CMAKE_CURRENT_BINARY_DIR}/${PROTO_WE}_pb2.py") + set(grpc_grpc_py "${CMAKE_CURRENT_BINARY_DIR}/${PROTO_WE}_pb2_grpc.py") + + set(py_srcs) + list(APPEND py_srcs "${grpc_proto_py}" "${grpc_grpc_py}") + + add_custom_command( + OUTPUT "${grpc_proto_py}" "${grpc_grpc_py}" + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} + ARGS --grpc_python_out "${CMAKE_CURRENT_BINARY_DIR}" -I "${PROTO_PATH}" + --plugin=protoc-gen-grpc_python="${GRPC_PYTHON_PLUGIN}" "${ABS_PROTO}" + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} + ARGS --python_out "${CMAKE_CURRENT_BINARY_DIR}" -I "${PROTO_PATH}" + "${ABS_PROTO}" + DEPENDS "${ABS_PROTO}" ${PROTOBUF_PROTOC_EXECUTABLE} extern_grpc) + + add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs} protobuf extern_grpc) +endfunction() + function(py_test TARGET_NAME) if(WITH_TESTING) set(options "") diff --git a/core/he/CMakeLists.txt b/core/he/CMakeLists.txt index f5a33972..05539a38 100644 --- a/core/he/CMakeLists.txt +++ b/core/he/CMakeLists.txt @@ -13,5 +13,12 @@ add_library(he_utils MODULE ${PYBIND_HE_SRCS}) target_link_libraries(he_utils PRIVATE pybind gmp gmpxx) set_target_properties(he_utils PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}") +set(FE_PROTO_MODULE_PATH "paddle_fl/feature_engineering/proto") +py_proto_grpc_compile(my_target PROTO "${CMAKE_SOURCE_DIR}/python/${FE_PROTO_MODULE_PATH}/metrics.proto" + PROTO_PATH "${CMAKE_SOURCE_DIR}/python") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FE_PROTO_MODULE_PATH}/metrics_pb2.py" + "${CMAKE_CURRENT_BINARY_DIR}/${FE_PROTO_MODULE_PATH}/metrics_pb2_grpc.py" + DESTINATION "${CMAKE_SOURCE_DIR}/python/${FE_PROTO_MODULE_PATH}") + set(FEATURE_LIB "${CMAKE_SOURCE_DIR}/python/paddle_fl/feature_engineering/libs") install(TARGETS he_utils LIBRARY DESTINATION ${FEATURE_LIB}) diff --git a/python/paddle_fl/feature_engineering/README.md b/python/paddle_fl/feature_engineering/README.md index 33637911..a844833f 100644 --- a/python/paddle_fl/feature_engineering/README.md +++ b/python/paddle_fl/feature_engineering/README.md @@ -35,13 +35,7 @@ make -j48 make install ``` -3.生成grpc_pb -``` -cd /path/to/PaddleFL/python -python3 paddle_fl/feature_engineering/proto/run_protogen.py -``` - -4.pip打包并安装 +3.pip打包并安装 ``` cd /path/to/PaddleFL/python/paddle_fl mkdir build && cd build