# See the License for the specific language governing permissions and # limitations under the License. """ This module test add op. """ import unittest from multiprocessing import Manager import numpy as np import paddle.fluid as fluid import paddle_fl.mpc as pfl_mpc import test_op_base from paddle_fl.mpc.data_utils.data_utils import get_datautils aby3 = get_datautils('aby3') class TestOpPool2d(test_op_base.TestOpBase): def pool2d(self, **kwargs): """ Add two variables with one dimension. :param kwargs: :return: """ role = kwargs['role'] d_1 = kwargs['data_1'][role] return_results = kwargs['return_results'] pfl_mpc.init("aby3", role, "localhost", self.server, int(self.port)) x = pfl_mpc.data(name='x', shape=[1, 1, 4, 6], dtype='int64')
MPC prediction. """ import sys import time import numpy as np import paddle.fluid as fluid import paddle_fl.mpc as pfl_mpc from paddle_fl.mpc.data_utils.data_utils import get_datautils sys.path.append('..') import process_data import network mpc_protocol_name = 'aby3' mpc_du = get_datautils(mpc_protocol_name) def load_mpc_model_and_predict(role, ip, server, port, mpc_model_dir, mpc_model_filename): """ Predict based on MPC inference model, save prediction results into files. """ place = fluid.CPUPlace() exe = fluid.Executor(place) # Step 1. initialize MPC environment and load MPC model to predict pfl_mpc.init(mpc_protocol_name, role, ip, server, port) infer_prog, feed_names, fetch_targets = mpc_du.load_mpc_model( exe=exe,
# # 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. """ This module test privc in data_utils. """ import os import unittest import numpy as np from paddle_fl.mpc.data_utils.data_utils import get_datautils privc = get_datautils('privc') class TestDataUtilsPrivc(unittest.TestCase): def test_encrypt_decrypt(self): number = 123.4 number_shares = privc.encrypt(number) self.assertEqual(len(number_shares), 2) revealed_number = privc.decrypt(number_shares) self.assertAlmostEqual(number, revealed_number, delta=1e-4) def test_make_shares(self): num_arr = np.arange(0, 4).reshape((2, 2))
# # 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. """ Process data for mean normalize demo. """ import numpy as np import six import os import paddle from paddle_fl.mpc.data_utils.data_utils import get_datautils mpc_du = get_datautils('aby3') data_path = './data/' def encrypted_data(data): """ feature stat reader """ def func(): """ make shares """ yield mpc_du.make_shares(data) return func
import os import time import six import pandas as pd import logging from paddle_fl.mpc.data_utils.data_utils import get_datautils import args import get_topk logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger('fluid') logger.setLevel(logging.INFO) aby3 = get_datautils("aby3") args = args.parse_args() watch_vec_size = args.watch_vec_size search_vec_size = args.search_vec_size other_feat_size = args.other_feat_size dataset_size = args.dataset_size batch_size = args.batch_size sample_size = args.batch_num output_size = args.output_size # max movie id def prepare_movielens_data(sample_size, batch_size, watch_vec_size, search_vec_size, other_feat_size, dataset_size, label_actual_filepath): """
# See the License for the specific language governing permissions and # limitations under the License. """ This module test fc op. """ import unittest from multiprocessing import Manager import numpy as np import paddle.fluid as fluid import paddle.fluid.core as core import paddle_fl.mpc as pfl_mpc from paddle_fl.mpc.data_utils.data_utils import get_datautils import test_op_base mpc_du = get_datautils('privc') scaling_factor = 32 class TestOpAdd(test_op_base.TestOpBase): def elementwise_add(self, **kwargs): """ Normal case. :param kwargs: :return: """ role = kwargs['role'] d_1 = kwargs['data_1'][role] d_2 = kwargs['data_2'][role] return_results = kwargs['return_results']