Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleFL
提交
a561cc11
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看板
提交
a561cc11
编写于
1月 13, 2020
作者:
Q
qjing666
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add scheduler in SECAGG and fix compatibility between py2 and py3
上级
5ea8b13c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
35 addition
and
17 deletion
+35
-17
docs/requirements.txt
docs/requirements.txt
+1
-0
paddle_fl/core/trainer/diffiehellman/diffiehellman.py
paddle_fl/core/trainer/diffiehellman/diffiehellman.py
+9
-9
paddle_fl/core/trainer/fl_trainer.py
paddle_fl/core/trainer/fl_trainer.py
+5
-4
paddle_fl/examples/secagg_demo/fl_scheduler.py
paddle_fl/examples/secagg_demo/fl_scheduler.py
+9
-0
paddle_fl/examples/secagg_demo/fl_server.py
paddle_fl/examples/secagg_demo/fl_server.py
+3
-0
paddle_fl/examples/secagg_demo/fl_trainer.py
paddle_fl/examples/secagg_demo/fl_trainer.py
+2
-0
paddle_fl/examples/secagg_demo/run.sh
paddle_fl/examples/secagg_demo/run.sh
+6
-4
未找到文件。
docs/requirements.txt
浏览文件 @
a561cc11
...
...
@@ -2,3 +2,4 @@ sphinx==2.1.0
mistune
sphinx_rtd_theme
paddlepaddle>=1.6
zqm
paddle_fl/core/trainer/diffiehellman/diffiehellman.py
浏览文件 @
a561cc11
...
...
@@ -42,9 +42,9 @@ try:
from
ssl
import
RAND_bytes
rng
=
RAND_bytes
except
(
AttributeError
,
ImportError
):
raise
RNGError
rng
=
os
.
urandom
#raise RNGError
#python2
#rng = os.urandom
class
DiffieHellman
:
"""
...
...
@@ -115,13 +115,13 @@ class DiffieHellman:
self
.
shared_secret
=
pow
(
other_public_key
,
self
.
private_key
,
self
.
prime
)
#python2
#length = self.shared_secret.bit_length() // 8 + 1
#shared_secret_as_bytes = ('%%0%dx' % (length << 1) % self.shared_secret).decode('hex')[-length:]
#python3
shared_secret_as_bytes
=
self
.
shared_secret
.
to_bytes
(
self
.
shared_secret
.
bit_length
()
//
8
+
1
,
byteorder
=
'big'
)
try
:
#python3
shared_secret_as_bytes
=
self
.
shared_secret
.
to_bytes
(
self
.
shared_secret
.
bit_length
()
//
8
+
1
,
byteorder
=
'big'
)
except
:
#python2
length
=
self
.
shared_secret
.
bit_length
()
//
8
+
1
shared_secret_as_bytes
=
(
'%%0%dx'
%
(
length
<<
1
)
%
self
.
shared_secret
).
decode
(
'hex'
)[
-
length
:]
_h
=
sha256
()
_h
.
update
(
bytes
(
shared_secret_as_bytes
))
...
...
paddle_fl/core/trainer/fl_trainer.py
浏览文件 @
a561cc11
...
...
@@ -16,7 +16,8 @@ import logging
from
paddle_fl.core.scheduler.agent_master
import
FLWorkerAgent
import
numpy
import
hmac
#from .diffiehellman.diffiehellman import DiffieHellman
import
hashlib
from
.diffiehellman.diffiehellman
import
DiffieHellman
class
FLTrainerFactory
(
object
):
def
__init__
(
self
):
...
...
@@ -190,6 +191,8 @@ class SecAggTrainer(FLTrainer):
self
.
_step_id
=
s
def
start
(
self
):
self
.
agent
=
FLWorkerAgent
(
self
.
_scheduler_ep
,
self
.
_current_ep
)
self
.
agent
.
connect_scheduler
()
self
.
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
self
.
exe
.
run
(
self
.
_startup_program
)
self
.
cur_step
=
0
...
...
@@ -219,7 +222,7 @@ class SecAggTrainer(FLTrainer):
self
.
_logger
.
debug
(
"begin to run send program"
)
noise
=
0.0
scale
=
pow
(
10.0
,
5
)
digestmod
=
"SHA256"
digestmod
=
hashlib
.
sha256
# 1. load priv key and other's pub key
dh
=
DiffieHellman
(
group
=
15
,
key_length
=
256
)
dh
.
load_private_key
(
self
.
_key_dir
+
str
(
self
.
_trainer_id
)
+
"_priv_key.txt"
)
...
...
@@ -245,5 +248,3 @@ class SecAggTrainer(FLTrainer):
self
.
cur_step
+=
1
return
loss
def
stop
(
self
):
return
False
paddle_fl/examples/secagg_demo/fl_scheduler.py
0 → 100644
浏览文件 @
a561cc11
from
paddle_fl.core.scheduler.agent_master
import
FLScheduler
worker_num
=
2
server_num
=
1
scheduler
=
FLScheduler
(
worker_num
,
server_num
)
scheduler
.
set_sample_worker_num
(
worker_num
)
scheduler
.
init_env
()
print
(
"init env done."
)
scheduler
.
start_fl_training
()
paddle_fl/examples/secagg_demo/fl_server.py
浏览文件 @
a561cc11
...
...
@@ -21,5 +21,8 @@ server_id = 0
job_path
=
"fl_job_config"
job
=
FLRunTimeJob
()
job
.
load_server_job
(
job_path
,
server_id
)
job
.
_scheduler_ep
=
"127.0.0.1:9091"
server
.
set_server_job
(
job
)
server
.
_current_ep
=
"127.0.0.1:8181"
server
.
start
()
print
(
"connect"
)
paddle_fl/examples/secagg_demo/fl_trainer.py
浏览文件 @
a561cc11
...
...
@@ -28,8 +28,10 @@ trainer_id = int(sys.argv[1]) # trainer id for each guest
job_path
=
"fl_job_config"
job
=
FLRunTimeJob
()
job
.
load_trainer_job
(
job_path
,
trainer_id
)
job
.
_scheduler_ep
=
"127.0.0.1:9091"
trainer
=
FLTrainerFactory
().
create_fl_trainer
(
job
)
trainer
.
trainer_id
=
trainer_id
trainer
.
_current_ep
=
"127.0.0.1:{}"
.
format
(
9000
+
trainer_id
)
trainer
.
trainer_num
=
trainer_num
trainer
.
key_dir
=
"./keys/"
trainer
.
start
()
...
...
paddle_fl/examples/secagg_demo/run.sh
浏览文件 @
a561cc11
...
...
@@ -5,10 +5,12 @@ if [ ! -d log ];then
mkdir
log
fi
python
3
fl_master.py
python fl_master.py
sleep
2
python
3
-u
fl_server.py
>
log/server0.log &
python
-u
fl_server.py
>
log/server0.log &
sleep
2
python
3
-u
fl_trainer.py 0
>
log/trainer0
.log &
python
-u
fl_scheduler.py
>
log/scheduler
.log &
sleep
2
python3
-u
fl_trainer.py 1
>
log/trainer1.log &
python
-u
fl_trainer.py 0
>
log/trainer0.log &
sleep
2
python
-u
fl_trainer.py 1
>
log/trainer1.log &
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录