diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a0e597b5c37af3cceb8693986cad7f6fac3ba8e..aac6879b85e184a1b7ad7b034c78d92295c7e207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ elseif (LINUX) endif() if (NOT PYTHON_EXECUTABLE) - set(PYTHON_EXECUTABLE python3) + set(PYTHON_EXECUTABLE python) endif() find_program(PYTHON ${PYTHON_EXECUTABLE}) diff --git a/python/paddle_fl/mpc/examples/mnist_demo/mnist_demo.py b/python/paddle_fl/mpc/examples/mnist_demo/mnist_demo.py index a1b6e5b984fa739c1c21471becab80b6314841b3..efa69836b13ad996f19967980da6d4c9543cf181 100644 --- a/python/paddle_fl/mpc/examples/mnist_demo/mnist_demo.py +++ b/python/paddle_fl/mpc/examples/mnist_demo/mnist_demo.py @@ -86,9 +86,9 @@ step = 0 for epoch_id in range(epoch_num): # feed data via loader for sample in loader(): - exe.run(feed=sample) + loss = exe.run(feed=sample, fetch_list=[cost.name]) if step % 50 == 0: - print('Epoch={}, Step={}'.format(epoch_id, step)) + print('Epoch={}, Step={}, loss={}'.format(epoch_id, step, loss)) step += 1 end_time = time.time() diff --git a/python/paddle_fl/mpc/examples/mnist_demo/prepare_data.py b/python/paddle_fl/mpc/examples/mnist_demo/prepare_data.py index 13e2a820b0da7fac9538b31c0227d03a8c49993c..54d5716672d5c4f1f74bfd0c9f0597a38fdbd56b 100644 --- a/python/paddle_fl/mpc/examples/mnist_demo/prepare_data.py +++ b/python/paddle_fl/mpc/examples/mnist_demo/prepare_data.py @@ -94,6 +94,6 @@ def decrypt_data_to_file(filepath, shape, decrypted_filepath): for i in p: f.write(str(i) + '\n') -# generate_encrypted_data() -# generate_encrypted_test_data() +generate_encrypted_data() +generate_encrypted_test_data() diff --git a/python/paddle_fl/mpc/examples/mnist_demo/run_standalone.sh b/python/paddle_fl/mpc/examples/mnist_demo/run_standalone.sh new file mode 100755 index 0000000000000000000000000000000000000000..4c6041fbad34663f8e888bad8eb27c9e406aed63 --- /dev/null +++ b/python/paddle_fl/mpc/examples/mnist_demo/run_standalone.sh @@ -0,0 +1,70 @@ +# 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. + +#!/bin/bash +# +# A tools to faciliate the parallel running of fluid_encrypted test scrips. +# A test script is EXPECTED to accepted arguments in the following format: +# +# SCRIPT_NAME $ROLE $SERVER $PORT +# ROLE: the role of the running party +# SERVER: the address of the party discovering service +# PORT: the port of the party discovering service +# +# This tool will try to fill the above three argument to the test script, +# so that totally three processes running the script will be started, to +# simulate run of three party in a standalone machine. +# +# Usage of this script: +# +# bash run_standalone.sh TEST_SCRIPT_NAME +# + +# modify the following vars according to your environment +PYTHON="python" +REDIS_HOME="path_to_redis_bin" +SERVER="localhost" +PORT=9937 + +function usage() { + echo 'run_standalone.sh SCRIPT_NAME [ARG...]' + exit 0 +} + +if [ $# -lt 1 ]; then + usage +fi + +SCRIPT=$1 +if [ ! -f $SCRIPT ]; then + echo 'Could not find script of '$SCRIPT + exit 1 +fi + +REDIS_BIN=$REDIS_HOME/redis-cli +if [ ! -f $REDIS_BIN ]; then + echo 'Could not find redis cli in '$REDIS_HOME + exit 1 +fi + +# clear the redis cache +$REDIS_BIN -h $SERVER -p $PORT flushall + + +for role in {1..2}; do + $PYTHON $SCRIPT $role $SERVER $PORT 2>&1 >/dev/null & +done + +# for party of role 0, run in a foreground mode and show the output +$PYTHON $SCRIPT 0 $SERVER $PORT diff --git a/python/paddle_fl/mpc/examples/run_standalone.sh b/python/paddle_fl/mpc/examples/run_standalone.sh index fd409c897ddced184b4dc91011f5f3176a73710a..4c6041fbad34663f8e888bad8eb27c9e406aed63 100755 --- a/python/paddle_fl/mpc/examples/run_standalone.sh +++ b/python/paddle_fl/mpc/examples/run_standalone.sh @@ -32,13 +32,10 @@ # # modify the following vars according to your environment -LD_LIB_PATH="path_to_needed_libs" PYTHON="python" REDIS_HOME="path_to_redis_bin" SERVER="localhost" PORT=9937 -MPC_DATA_UTILS_MODULE_DIRPATH="mpc_data_utils_so_dirpath" -export PYTHONPATH=$MPC_DATA_UTILS_MODULE_DIRPATH:$PYTHONPATH function usage() { echo 'run_standalone.sh SCRIPT_NAME [ARG...]' @@ -64,8 +61,6 @@ fi # clear the redis cache $REDIS_BIN -h $SERVER -p $PORT flushall -# kick off script with roles of 1 and 2, and redirect output to /dev/null -export LD_LIBRARY_PATH=$LD_LIB_PATH:$LD_LIBRARY_PATH for role in {1..2}; do $PYTHON $SCRIPT $role $SERVER $PORT 2>&1 >/dev/null & diff --git a/python/paddle_fl/mpc/examples/uci_demo/prepare_data.py b/python/paddle_fl/mpc/examples/uci_demo/prepare_data.py index df6f61caeb01eb28aaa74658b4d81297241467e2..2d327ce7726eb078b9c2bed06ba5d69ff35ef3b6 100644 --- a/python/paddle_fl/mpc/examples/uci_demo/prepare_data.py +++ b/python/paddle_fl/mpc/examples/uci_demo/prepare_data.py @@ -60,3 +60,6 @@ def load_decrypt_data(filepath, shape): for instance in aby3_share_reader(): p = aby3.reconstruct(np.array(instance)) print(p) + + +generate_encrypted_data() diff --git a/python/paddle_fl/mpc/examples/uci_demo/run_standalone.sh b/python/paddle_fl/mpc/examples/uci_demo/run_standalone.sh new file mode 100755 index 0000000000000000000000000000000000000000..4c6041fbad34663f8e888bad8eb27c9e406aed63 --- /dev/null +++ b/python/paddle_fl/mpc/examples/uci_demo/run_standalone.sh @@ -0,0 +1,70 @@ +# 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. + +#!/bin/bash +# +# A tools to faciliate the parallel running of fluid_encrypted test scrips. +# A test script is EXPECTED to accepted arguments in the following format: +# +# SCRIPT_NAME $ROLE $SERVER $PORT +# ROLE: the role of the running party +# SERVER: the address of the party discovering service +# PORT: the port of the party discovering service +# +# This tool will try to fill the above three argument to the test script, +# so that totally three processes running the script will be started, to +# simulate run of three party in a standalone machine. +# +# Usage of this script: +# +# bash run_standalone.sh TEST_SCRIPT_NAME +# + +# modify the following vars according to your environment +PYTHON="python" +REDIS_HOME="path_to_redis_bin" +SERVER="localhost" +PORT=9937 + +function usage() { + echo 'run_standalone.sh SCRIPT_NAME [ARG...]' + exit 0 +} + +if [ $# -lt 1 ]; then + usage +fi + +SCRIPT=$1 +if [ ! -f $SCRIPT ]; then + echo 'Could not find script of '$SCRIPT + exit 1 +fi + +REDIS_BIN=$REDIS_HOME/redis-cli +if [ ! -f $REDIS_BIN ]; then + echo 'Could not find redis cli in '$REDIS_HOME + exit 1 +fi + +# clear the redis cache +$REDIS_BIN -h $SERVER -p $PORT flushall + + +for role in {1..2}; do + $PYTHON $SCRIPT $role $SERVER $PORT 2>&1 >/dev/null & +done + +# for party of role 0, run in a foreground mode and show the output +$PYTHON $SCRIPT 0 $SERVER $PORT diff --git a/python/paddle_fl/paddle_fl/examples/dpsgd_demo/fl_server.py b/python/paddle_fl/paddle_fl/examples/dpsgd_demo/fl_server.py index bfda7a2e05e0f0efe5169ac8265d58db2a127d5e..aa1e9a86504673968cdfb969de5321df5d33277e 100644 --- a/python/paddle_fl/paddle_fl/examples/dpsgd_demo/fl_server.py +++ b/python/paddle_fl/paddle_fl/examples/dpsgd_demo/fl_server.py @@ -14,8 +14,8 @@ import paddle_fl.paddle_fl as fl import paddle.fluid as fluid -from paddle_fl.core.server.fl_server import FLServer -from paddle_fl.core.master.fl_job import FLRunTimeJob +from paddle_fl.paddle_fl.core.server.fl_server import FLServer +from paddle_fl.paddle_fl.core.master.fl_job import FLRunTimeJob server = FLServer() server_id = 0 job_path = "fl_job_config" diff --git a/python/paddle_fl/paddle_fl/examples/femnist_demo/fl_trainer.py b/python/paddle_fl/paddle_fl/examples/femnist_demo/fl_trainer.py index 4e58610f7e04dba9eb5f4ed9c2492df9b85cee06..131ee7a3911d3c01f02f5847c938c09519a0b3a7 100644 --- a/python/paddle_fl/paddle_fl/examples/femnist_demo/fl_trainer.py +++ b/python/paddle_fl/paddle_fl/examples/femnist_demo/fl_trainer.py @@ -14,7 +14,7 @@ from paddle_fl.paddle_fl.core.trainer.fl_trainer import FLTrainerFactory from paddle_fl.paddle_fl.core.master.fl_job import FLRunTimeJob -import paddle_fl.paddle_fl.dataset.femnist +import paddle_fl.paddle_fl.dataset.femnist as femnist import numpy import sys import paddle @@ -76,7 +76,7 @@ while not trainer.stop(): #train_data,test_data= data_generater(trainer_id,inner_step=trainer._step,batch_size=64,count_by_step=count_by_step) train_reader = paddle.batch( paddle.reader.shuffle( - paddle_fl.dataset.femnist.train( + femnist.train( trainer_id, inner_step=trainer._step, batch_size=64, @@ -85,7 +85,7 @@ while not trainer.stop(): batch_size=64) test_reader = paddle.batch( - paddle_fl.dataset.femnist.test( + femnist.test( trainer_id, inner_step=trainer._step, batch_size=64, diff --git a/python/paddle_fl/paddle_fl/version.py b/python/paddle_fl/paddle_fl/version.py deleted file mode 100644 index 8540fde4fe0814938593a0a6a93854d99fbb51a5..0000000000000000000000000000000000000000 --- a/python/paddle_fl/paddle_fl/version.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2019 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 = "0.2.0" -module_proto_version = "0.2.0" diff --git a/python/setup.py b/python/setup.py index 79f73d506d71d9771ec06625c2d0489c5190ba13..5cc8769e5979b213c99cbb919f62c9e5f63c7d89 100644 --- a/python/setup.py +++ b/python/setup.py @@ -22,7 +22,7 @@ import platform from setuptools import find_packages from setuptools import setup -from paddle_fl.version import fl_version +from version import fl_version def python_version(): """ @@ -34,7 +34,7 @@ def python_version(): max_version, mid_version, min_version = python_version() REQUIRED_PACKAGES = [ - 'six >= 1.10.0', 'protobuf >= 3.1.0', 'paddlepaddle == 1.6.3' + 'six >= 1.10.0', 'protobuf >= 3.1.0', 'paddlepaddle == 1.6.3', 'paddlepaddle-gpu >= 1.8' ] if max_version < 3: diff --git a/python/paddle_fl/version.py b/python/version.py similarity index 100% rename from python/paddle_fl/version.py rename to python/version.py