-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from Sprate/feature
add separate compilation for feature engineering
- Loading branch information
Showing
26 changed files
with
321 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
set(PYBIND_HE_SRCS | ||
"./he_utils.cc" | ||
"./paillier.cc" | ||
) | ||
|
||
if (NOT PYTHON_INCLUDE_DIRS) | ||
find_package(PythonLibs REQUIRED) | ||
endif() | ||
|
||
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(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}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
## 联邦特征工程 | ||
|
||
支持计算正样本占比、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.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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.