diff --git a/python/paddle_fl/mpc/tests/unittests/op_test.py b/python/paddle_fl/mpc/tests/unittests/op_test.py index 9064074c6e68479ffb2fa22b343b1d56f75ea714..50e2b5409380b04d01f5340d77b06bdf9153e18e 100644 --- a/python/paddle_fl/mpc/tests/unittests/op_test.py +++ b/python/paddle_fl/mpc/tests/unittests/op_test.py @@ -140,13 +140,13 @@ class OpTest(unittest.TestCase): target = kwargs['target'] - partys = [] + parties = [] for role in range(self.party_num): kwargs.update({'role': role}) - partys.append(Aby3Process(target=target, kwargs=kwargs)) - partys[-1].start() - for party in partys: + parties.append(Aby3Process(target=target, kwargs=kwargs)) + parties[-1].start() + for party in parties: party.join() if party.exception: return party.exception diff --git a/python/paddle_fl/mpc/tests/unittests/test_op_base.py b/python/paddle_fl/mpc/tests/unittests/test_op_base.py index 3f41f69d2fda9c89a77334b182bfb7e966145fb2..3ca84d843e9a9e54b01d4e566f75bf9f161e759f 100644 --- a/python/paddle_fl/mpc/tests/unittests/test_op_base.py +++ b/python/paddle_fl/mpc/tests/unittests/test_op_base.py @@ -77,13 +77,13 @@ class TestOpBase(unittest.TestCase): """ target = kwargs['target'] + parties = [] for role in range(self.party_num): kwargs.update({'role': role}) - party = Aby3Process(target=target, kwargs=kwargs) - party.start() - if role == self.party_num - 1: - party.join() - if party.exception: - return party.exception - else: - return (True,) + parties.append(Aby3Process(target=target, kwargs=kwargs)) + parties[-1].start() + for party in parties: + party.join() + if party.exception: + return party.exception + return (True,) diff --git a/python/paddle_fl/mpc/tests/unittests/test_op_conv.py b/python/paddle_fl/mpc/tests/unittests/test_op_conv.py index ee45be251f65f02ffffad813d9360cab9118d546..307c6367eda654ea519928b524db661195a678aa 100644 --- a/python/paddle_fl/mpc/tests/unittests/test_op_conv.py +++ b/python/paddle_fl/mpc/tests/unittests/test_op_conv.py @@ -19,10 +19,10 @@ import unittest from multiprocessing import Manager import numpy as np - import test_op_base from op_test import OpTest import paddle_fl.mpc.data_utils.aby3 as aby3 +import mpc_data_utils as mdu import paddle.fluid as fluid import paddle.fluid.core as core @@ -190,7 +190,7 @@ class TestConv2dOp(OpTest): 'dilation': self.dilations } - share = lambda x: np.array([x * 65536/3] * 2).astype('int64') + share = lambda x: np.array([x * mdu.mpc_one_share] * 2).astype('int64') input = np.random.random(self.input_size) filter = np.random.uniform(-1, 1, self.filter_size) @@ -385,7 +385,7 @@ class TestConv2dOp_v2(OpTest): 'dilation': self.dilations } - share = lambda x: np.array([x * 65536/3] * 2).astype('int64') + share = lambda x: np.array([x * mdu.mpc_one_share] * 2).astype('int64') input = np.random.random(self.input_size) filter = np.random.uniform(-1, 1, self.filter_size) diff --git a/python/paddle_fl/mpc/tests/unittests/test_op_metric.py b/python/paddle_fl/mpc/tests/unittests/test_op_metric.py index 9260957e69e79d0cd5d770206511292dd81d78a1..873ad699813bd4ffa6370cdbf4efc2052bd415d6 100644 --- a/python/paddle_fl/mpc/tests/unittests/test_op_metric.py +++ b/python/paddle_fl/mpc/tests/unittests/test_op_metric.py @@ -20,6 +20,7 @@ import unittest import numpy as np import paddle.fluid as fluid import paddle_fl.mpc as pfl_mpc +import mpc_data_utils as mdu import test_op_base @@ -92,7 +93,7 @@ class TestOpPrecisionRecall(test_op_base.TestOpBase): self.threshold = np.random.random() preds, labels = [], [] self.exp_res = (0, [0] * 3) - share = lambda x: np.array([x * 65536/3] * 2).astype('int64').reshape( + share = lambda x: np.array([x * mdu.mpc_one_share] * 2).astype('int64').reshape( [2] + self.input_size) for _ in range(n): diff --git a/python/paddle_fl/mpc/tests/unittests/test_op_pool.py b/python/paddle_fl/mpc/tests/unittests/test_op_pool.py index 685689782ede4393fac454baba33c8af5255cfe3..c519dc8721007dc9df0b3485959103822b9d78f8 100644 --- a/python/paddle_fl/mpc/tests/unittests/test_op_pool.py +++ b/python/paddle_fl/mpc/tests/unittests/test_op_pool.py @@ -54,15 +54,15 @@ class TestOpPool2d(test_op_base.TestOpBase): def test_pool2d(self): data_1 = np.array( - [[[[1, 2, 3, 4, 0, 100], - [5, 6, 7, 8, 0, 100], + [[[[1, 2, 3, 4, 0, 100], + [5, 6, 7, 8, 0, 100], [9, 10, 11, 12, 0, 200], [13, 14, 15, 16, 0, 200]]]]).astype('float32') - + expected_out = np.array( - [[[[6, 8, 100], + [[[[6, 8, 100], [14, 16, 200]]]]).astype('float32') - print("input data_1: {} \n".format(data_1)) + # print("input data_1: {} \n".format(data_1)) data_1_shares = aby3.make_shares(data_1)