Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleFL
提交
48813130
P
PaddleFL
项目概览
PaddlePaddle
/
PaddleFL
通知
35
Star
5
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
6
列表
看板
标记
里程碑
合并请求
4
Wiki
3
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleFL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
6
Issue
6
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
3
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
48813130
编写于
5月 14, 2020
作者:
Q
Qinghe JING
提交者:
GitHub
5月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into smc-611
上级
072ccc32
5302307d
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
34 addition
and
431 deletion
+34
-431
python/paddle_fl/mpc/data_utils/alignment.py
python/paddle_fl/mpc/data_utils/alignment.py
+5
-3
python/paddle_fl/mpc/examples/env_set.py
python/paddle_fl/mpc/examples/env_set.py
+0
-37
python/paddle_fl/mpc/examples/mnist_demo/mnist_demo.py
python/paddle_fl/mpc/examples/mnist_demo/mnist_demo.py
+1
-4
python/paddle_fl/mpc/examples/mnist_demo/run_standalone.sh
python/paddle_fl/mpc/examples/mnist_demo/run_standalone.sh
+13
-0
python/paddle_fl/mpc/examples/run_standalone.sh
python/paddle_fl/mpc/examples/run_standalone.sh
+0
-70
python/paddle_fl/mpc/examples/test_add.py
python/paddle_fl/mpc/examples/test_add.py
+0
-47
python/paddle_fl/mpc/examples/test_compare.py
python/paddle_fl/mpc/examples/test_compare.py
+0
-57
python/paddle_fl/mpc/examples/test_data_utils.py
python/paddle_fl/mpc/examples/test_data_utils.py
+0
-28
python/paddle_fl/mpc/examples/test_init.py
python/paddle_fl/mpc/examples/test_init.py
+0
-32
python/paddle_fl/mpc/examples/test_mixed.py
python/paddle_fl/mpc/examples/test_mixed.py
+0
-53
python/paddle_fl/mpc/examples/test_ml.py
python/paddle_fl/mpc/examples/test_ml.py
+0
-48
python/paddle_fl/mpc/examples/test_net.py
python/paddle_fl/mpc/examples/test_net.py
+0
-47
python/paddle_fl/mpc/examples/uci_demo/run_standalone.sh
python/paddle_fl/mpc/examples/uci_demo/run_standalone.sh
+13
-0
python/paddle_fl/mpc/examples/uci_demo/uci_housing_demo.py
python/paddle_fl/mpc/examples/uci_demo/uci_housing_demo.py
+1
-4
python/setup.py
python/setup.py
+1
-1
未找到文件。
python/paddle_fl/mpc/data_utils/alignment.py
浏览文件 @
48813130
...
@@ -18,7 +18,7 @@ PSI (Private Set Intersection) algorithm.
...
@@ -18,7 +18,7 @@ PSI (Private Set Intersection) algorithm.
import
os
import
os
import
sys
import
sys
import
mpc_data_utils
as
mdu
import
mpc_data_utils
as
mdu
from
multiprocessing.connection
import
Client
,
Listener
__all__
=
[
'align'
,
]
__all__
=
[
'align'
,
]
...
@@ -90,7 +90,6 @@ def _send_align_result(result, send_list):
...
@@ -90,7 +90,6 @@ def _send_align_result(result, send_list):
Each party is represented as "id:ip:port".
Each party is represented as "id:ip:port".
:return:
:return:
"""
"""
from
multiprocessing.connection
import
Client
for
host
in
send_list
:
for
host
in
send_list
:
ip_addr
=
host
.
split
(
":"
)[
1
]
ip_addr
=
host
.
split
(
":"
)[
1
]
port
=
int
(
host
.
split
(
":"
)[
2
])
port
=
int
(
host
.
split
(
":"
)[
2
])
...
@@ -112,4 +111,7 @@ def _recv_align_result(host):
...
@@ -112,4 +111,7 @@ def _recv_align_result(host):
port
=
int
(
host
.
split
(
":"
)[
2
])
port
=
int
(
host
.
split
(
":"
)[
2
])
server
=
Listener
((
ip_addr
,
port
))
server
=
Listener
((
ip_addr
,
port
))
conn
=
server
.
accept
()
conn
=
server
.
accept
()
return
conn
.
recv
()
result
=
conn
.
recv
()
conn
.
close
()
server
.
close
()
return
result
python/paddle_fl/mpc/examples/env_set.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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 proper fluid_encrypted pkg path
"""
import
sys
class
TestOptions
:
"""
Read test options of role, server ip, and port
"""
def
__init__
(
self
):
if
len
(
sys
.
argv
)
<
4
:
print
(
"Args: $ROLE $SERVER $PORT"
)
sys
.
exit
()
self
.
__role
=
sys
.
argv
[
1
]
self
.
__server
=
sys
.
argv
[
2
]
self
.
__port
=
sys
.
argv
[
3
]
def
values
(
self
):
"""
Return argument values
"""
return
self
.
__role
,
self
.
__server
,
self
.
__port
python/paddle_fl/mpc/examples/mnist_demo/mnist_demo.py
浏览文件 @
48813130
# coding=utf-8
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
...
@@ -17,9 +16,7 @@ MNIST Demo
...
@@ -17,9 +16,7 @@ MNIST Demo
"""
"""
import
sys
import
sys
sys
.
path
.
append
(
'../'
)
import
env_set
import
numpy
as
np
import
numpy
as
np
import
time
import
time
...
@@ -29,7 +26,7 @@ import paddle_fl.mpc as pfl_mpc
...
@@ -29,7 +26,7 @@ import paddle_fl.mpc as pfl_mpc
import
paddle_fl.mpc.data_utils.aby3
as
aby3
import
paddle_fl.mpc.data_utils.aby3
as
aby3
import
prepare_data
import
prepare_data
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
role
,
server
,
port
=
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
]
# modify host(localhost).
# modify host(localhost).
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
role
=
int
(
role
)
role
=
int
(
role
)
...
...
python/paddle_fl/mpc/examples/mnist_demo/run_standalone.sh
浏览文件 @
48813130
...
@@ -61,10 +61,23 @@ fi
...
@@ -61,10 +61,23 @@ fi
# clear the redis cache
# clear the redis cache
$REDIS_BIN
-h
$SERVER
-p
$PORT
flushall
$REDIS_BIN
-h
$SERVER
-p
$PORT
flushall
# remove temp data generated in last time
LOSS_FILE
=
"/tmp/mnist_output_loss.*"
PRED_FILE
=
"/tmp/mnist_output_prediction.*"
if
[
"
$LOSS_FILE
"
]
;
then
rm
-rf
$LOSS_FILE
fi
if
[
"
$PRED_FILE
"
]
;
then
rm
-rf
$PRED_FILE
fi
# kick off script with roles of 1 and 2, and redirect output to /dev/null
for
role
in
{
1..2
}
;
do
for
role
in
{
1..2
}
;
do
$PYTHON
$SCRIPT
$role
$SERVER
$PORT
2>&1
>
/dev/null &
$PYTHON
$SCRIPT
$role
$SERVER
$PORT
2>&1
>
/dev/null &
done
done
# for party of role 0, run in a foreground mode and show the output
# for party of role 0, run in a foreground mode and show the output
$PYTHON
$SCRIPT
0
$SERVER
$PORT
$PYTHON
$SCRIPT
0
$SERVER
$PORT
python/paddle_fl/mpc/examples/run_standalone.sh
已删除
100755 → 0
浏览文件 @
072ccc32
# 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
python/paddle_fl/mpc/examples/test_add.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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.
"""
test mpc add op
"""
# set proper path for fluid_encrypted without install, should be first line
import
env_set
import
sys
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle_fl.mpc
as
pfl_mpc
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
# call mpc add
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
data_1
=
pfl_mpc
.
data
(
name
=
'data_1'
,
shape
=
[
8
],
dtype
=
'int64'
)
data_2
=
pfl_mpc
.
data
(
name
=
'data_2'
,
shape
=
[
8
],
dtype
=
'int64'
)
d_1
=
np
.
array
(
[[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
],
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]]).
astype
(
'int64'
)
d_2
=
np
.
array
(
[[
7
,
6
,
5
,
4
,
3
,
2
,
1
,
0
],
[
7
,
6
,
5
,
4
,
3
,
2
,
1
,
0
]]).
astype
(
'int64'
)
out_add
=
data_1
+
data_2
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
out_add
=
exe
.
run
(
feed
=
{
'data_1'
:
d_1
,
'data_2'
:
d_2
,
},
fetch_list
=
[
out_add
])
print
(
out_add
)
python/paddle_fl/mpc/examples/test_compare.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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.
"""
test mixed mpc ops
"""
# set proper path for fluid_encrypted without install, should be first line
import
env_set
import
time
import
sys
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle_fl.mpc
as
pfl_mpc
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
data_1
=
pfl_mpc
.
data
(
name
=
'data_1'
,
shape
=
[
2
,
2
],
dtype
=
'int64'
)
data_2
=
fluid
.
data
(
name
=
'data_2'
,
shape
=
[
1
,
2
,
2
],
dtype
=
'float32'
)
out_gt
=
data_1
>
data_2
out_ge
=
data_1
>=
data_2
out_lt
=
data_1
<
data_2
out_le
=
data_1
<=
data_2
out_eq
=
data_1
==
data_2
out_neq
=
data_1
!=
data_2
d_1
=
np
.
array
([[[
65536
,
65536
],
[
65536
,
65536
]],
[[
65536
,
65536
],
[
65536
,
65536
]]]).
astype
(
'int64'
)
d_2
=
np
.
array
([[[
10
,
3
],
[
0
,
-
3
]]]).
astype
(
'float32'
)
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
exe
.
run
(
fluid
.
default_startup_program
())
out_gt
,
out_ge
,
out_lt
,
out_le
,
out_eq
,
out_neq
=
exe
.
run
(
feed
=
{
'data_1'
:
d_1
,
'data_2'
:
d_2
},
fetch_list
=
[
out_gt
,
out_ge
,
out_lt
,
out_le
,
out_eq
,
out_neq
])
print
(
"Input:
\n
d_1: {}
\n
d_2: {}
\n
"
.
format
(
d_1
,
d_2
))
print
(
"greater_than:{}
\n
greater_equal:{}
\n
less_than:{}
\n
less_equal:{}
\n
equal:{}
\n
not_equal:{}
\n
"
.
format
(
out_gt
,
out_ge
,
out_lt
,
out_le
,
out_eq
,
out_neq
))
python/paddle_fl/mpc/examples/test_data_utils.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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.
# export
import
sys
import
data_utils
as
du
import
numpy
as
np
plaintext
=
2.9
print
(
"Plaintext: {0}"
.
format
(
plaintext
))
shares
=
du
.
share
(
plaintext
)
print
(
"Shares: {0}"
.
format
(
shares
))
revealed_text
=
du
.
reveal
(
shares
)
print
(
"Revealed plaintext: {0}"
.
format
(
revealed_text
))
python/paddle_fl/mpc/examples/test_init.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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.
"""
test mpc init op
"""
# set proper path for fluid_encrypted without install, should be first line
import
env_set
import
sys
import
paddle.fluid
as
fluid
import
paddle_fl.mpc
as
pfl_mpc
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
# call mpc init
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
exe
.
run
()
print
(
"Role "
+
role
+
" started"
)
python/paddle_fl/mpc/examples/test_mixed.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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.
"""
test mixed mpc ops
"""
# set proper path for fluid_encrypted without install, should be first line
import
env_set
import
time
import
sys
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle_fl.mpc
as
pfl_mpc
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
# call mpc add
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
data_1
=
pfl_mpc
.
data
(
name
=
'data_1'
,
shape
=
[
2
,
2
],
dtype
=
'int64'
)
data_2
=
pfl_mpc
.
data
(
name
=
'data_2'
,
shape
=
[
2
,
2
],
dtype
=
'int64'
)
data_3
=
fluid
.
data
(
name
=
'data_3'
,
shape
=
[
1
,
2
,
2
],
dtype
=
'int64'
)
out_sub
=
data_1
-
data_2
out_mul
=
pfl_mpc
.
layers
.
mul
(
x
=
data_1
,
y
=
data_2
)
out_mean
=
pfl_mpc
.
layers
.
mean
(
x
=
data_1
)
out_square
=
pfl_mpc
.
layers
.
square
(
x
=
data_1
)
out_sum
=
pfl_mpc
.
layers
.
sum
([
data_1
,
data_2
])
d_1
=
np
.
array
([[[
10
,
10
],
[
10
,
10
]],
[[
10
,
10
],
[
10
,
10
]]]).
astype
(
'int64'
)
d_2
=
np
.
array
([[[
5
,
5
],
[
5
,
5
]],
[[
5
,
5
],
[
5
,
5
]]]).
astype
(
'int64'
)
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
exe
.
run
(
fluid
.
default_startup_program
())
out_sub
,
out_mul
,
out_mean
,
out_square
,
out_sum
=
exe
.
run
(
feed
=
{
'data_1'
:
d_1
,
'data_2'
:
d_2
},
fetch_list
=
[
out_sub
,
out_mul
,
out_mean
,
out_square
,
out_sum
])
print
(
"sub:{},
\n
mul: {},
\n
mean:{},
\n
square:{},
\n
sum: {}
\n
"
.
format
(
out_sub
,
out_mul
,
out_mean
,
out_square
,
out_sum
))
python/paddle_fl/mpc/examples/test_ml.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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.
"""
test mixed mpc ops
"""
# set proper path for fluid_encrypted without install, should be first line
import
env_set
import
time
import
sys
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle_fl.mpc
as
pfl_mpc
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
data_1
=
pfl_mpc
.
data
(
name
=
'data_1'
,
shape
=
[
2
,
2
],
dtype
=
'int64'
)
data_2
=
pfl_mpc
.
data
(
name
=
'data_2'
,
shape
=
[
2
,
2
],
dtype
=
'int64'
)
out_sec
=
pfl_mpc
.
layers
.
square_error_cost
(
input
=
data_1
,
label
=
data_2
)
out_fc
=
pfl_mpc
.
layers
.
fc
(
input
=
data_1
,
size
=
1
,
act
=
None
)
out_relu
=
pfl_mpc
.
layers
.
relu
(
data_1
)
d_1
=
np
.
array
([[[
10
,
10
],
[
10
,
10
]],
[[
10
,
10
],
[
10
,
10
]]]).
astype
(
'int64'
)
d_2
=
np
.
array
([[[
5
,
5
],
[
5
,
5
]],
[[
5
,
5
],
[
5
,
5
]]]).
astype
(
'int64'
)
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
exe
.
run
(
fluid
.
default_startup_program
())
out_sec
,
out_fc
,
out_relu
=
exe
.
run
(
feed
=
{
'data_1'
:
d_1
,
'data_2'
:
d_2
},
fetch_list
=
[
out_sec
,
out_fc
,
out_relu
])
print
(
"square_error_cost: {},
\n
out_fc:{},
\n
out_relu:{}
\n
"
.
format
(
out_sec
,
out_fc
,
out_relu
))
python/paddle_fl/mpc/examples/test_net.py
已删除
100644 → 0
浏览文件 @
072ccc32
# 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
env_set
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle_fl.mpc
as
pfl_mpc
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
batch_size
=
3
# x is in cypher text type
x
=
pfl_mpc
.
data
(
name
=
'x'
,
shape
=
[
batch_size
,
8
],
dtype
=
'int64'
)
# y is in cypher text type
y
=
pfl_mpc
.
data
(
name
=
'y'
,
shape
=
[
batch_size
,
1
],
dtype
=
'int64'
)
y_pre
=
pfl_mpc
.
layers
.
fc
(
input
=
x
,
size
=
1
,
act
=
None
)
y_relu
=
pfl_mpc
.
layers
.
relu
(
input
=
y_pre
)
cost
=
pfl_mpc
.
layers
.
square_error_cost
(
input
=
y_relu
,
label
=
y
)
avg_loss
=
pfl_mpc
.
layers
.
mean
(
cost
)
optimizer
=
pfl_mpc
.
optimizer
.
SGD
(
learning_rate
=
0.001
)
optimizer
.
minimize
(
avg_loss
)
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
exe
.
run
(
fluid
.
default_startup_program
())
iters
=
1
for
_
in
range
(
iters
):
d_1
=
np
.
ones
(
shape
=
(
2
,
batch_size
,
8
),
dtype
=
'int64'
)
d_2
=
np
.
zeros
(
shape
=
(
2
,
batch_size
,
1
),
dtype
=
'int64'
)
loss
=
exe
.
run
(
feed
=
{
'x'
:
d_1
,
'y'
:
d_2
},
fetch_list
=
[
avg_loss
])
print
(
loss
)
python/paddle_fl/mpc/examples/uci_demo/run_standalone.sh
浏览文件 @
48813130
...
@@ -61,10 +61,23 @@ fi
...
@@ -61,10 +61,23 @@ fi
# clear the redis cache
# clear the redis cache
$REDIS_BIN
-h
$SERVER
-p
$PORT
flushall
$REDIS_BIN
-h
$SERVER
-p
$PORT
flushall
# remove temp data generated in last time
LOSS_FILE
=
"/tmp/uci_loss.*"
PRED_FILE
=
"/tmp/uci_prediction.*"
if
[
"
$LOSS_FILE
"
]
;
then
rm
-rf
$LOSS_FILE
fi
if
[
"
$PRED_FILE
"
]
;
then
rm
-rf
$PRED_FILE
fi
# kick off script with roles of 1 and 2, and redirect output to /dev/null
for
role
in
{
1..2
}
;
do
for
role
in
{
1..2
}
;
do
$PYTHON
$SCRIPT
$role
$SERVER
$PORT
2>&1
>
/dev/null &
$PYTHON
$SCRIPT
$role
$SERVER
$PORT
2>&1
>
/dev/null &
done
done
# for party of role 0, run in a foreground mode and show the output
# for party of role 0, run in a foreground mode and show the output
$PYTHON
$SCRIPT
0
$SERVER
$PORT
$PYTHON
$SCRIPT
0
$SERVER
$PORT
python/paddle_fl/mpc/examples/uci_demo/uci_housing_demo.py
浏览文件 @
48813130
...
@@ -12,9 +12,6 @@
...
@@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
sys
import
sys
sys
.
path
.
append
(
'../'
)
import
env_set
import
numpy
as
np
import
numpy
as
np
import
time
import
time
...
@@ -23,7 +20,7 @@ import paddle.fluid as fluid
...
@@ -23,7 +20,7 @@ import paddle.fluid as fluid
import
paddle_fl.mpc
as
pfl_mpc
import
paddle_fl.mpc
as
pfl_mpc
import
paddle_fl.mpc.data_utils.aby3
as
aby3
import
paddle_fl.mpc.data_utils.aby3
as
aby3
role
,
server
,
port
=
env_set
.
TestOptions
().
values
()
role
,
server
,
port
=
sys
.
argv
[
1
],
sys
.
argv
[
2
],
sys
.
argv
[
3
]
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
pfl_mpc
.
init
(
"aby3"
,
int
(
role
),
"localhost"
,
server
,
int
(
port
))
role
=
int
(
role
)
role
=
int
(
role
)
...
...
python/setup.py
浏览文件 @
48813130
...
@@ -34,7 +34,7 @@ def python_version():
...
@@ -34,7 +34,7 @@ def python_version():
max_version
,
mid_version
,
min_version
=
python_version
()
max_version
,
mid_version
,
min_version
=
python_version
()
REQUIRED_PACKAGES
=
[
REQUIRED_PACKAGES
=
[
'six >= 1.10.0'
,
'protobuf >= 3.1.0'
,
'paddlepaddle
=
= 1.8.0'
,
'paddlepaddle-gpu >= 1.8'
'six >= 1.10.0'
,
'protobuf >= 3.1.0'
,
'paddlepaddle
>
= 1.8.0'
,
'paddlepaddle-gpu >= 1.8'
]
]
if
max_version
<
3
:
if
max_version
<
3
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录