-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDP_run_3.py
94 lines (87 loc) · 4.73 KB
/
DP_run_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import flgo.algorithm.fedavg as fedavg
import flgo.experiment.analyzer
import DP
# 创建svhn_classification数据集的横向联邦benchmark
bmk = flgo.gen_benchmark_from_file(
benchmark='svhn_classification',
config_file='./config.py',
target_path='.',
data_type='cv',
task_type='classification',
)
# 从benchmark构造IID划分的联邦任务
task = './svhn_DP_Laplace_clip' # 任务名称·1
task_config = {
'benchmark': bmk,
'partitioner': {
'name': 'IIDPartitioner'
}
} # 任务配置
flgo.gen_task(task_config, task) # 生成任务
option = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 0, 'load_checkpoint': 0, 'log_file': True, 'log_level': 'DEBUG'}
option_1 = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 1, 'load_checkpoint': 1, 'algo_para': [10, 1,2], 'sample': 'sequential',
'log_file': True, 'log_level': 'DEBUG'}
option_2 = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 2, 'load_checkpoint': 2, 'algo_para': [10, 1,3], 'sample': 'sequential',
'log_file': True, 'log_level': 'DEBUG'}
option_3 = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 3, 'load_checkpoint': 3, 'algo_para': [10, 1,4], 'sample': 'sequential',
'log_file': True, 'log_level': 'DEBUG'}
option_4 = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 4, 'load_checkpoint': 4, 'algo_para': [10, 1,5], 'sample': 'sequential',
'log_file': True, 'log_level': 'DEBUG'}
option_5 = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 5, 'load_checkpoint': 5, 'algo_para': [10, 1,6], 'sample': 'sequential',
'log_file': True, 'log_level': 'DEBUG'}
option_6 = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 6, 'load_checkpoint': 6, 'algo_para': [10, 1,7], 'sample': 'sequential',
'log_file': True, 'log_level': 'DEBUG'}
option_7 = {'gpu': 0, 'num_rounds': 20, 'proportion': 0.1, 'batch_size': 64, 'learning_rate': 0.1,
'save_checkpoint': 7, 'load_checkpoint': 7, 'algo_para': [10, 1,8], 'sample': 'sequential',
'log_file': True, 'log_level': 'DEBUG'}
# fedavg_runner = flgo.init(task, fedavg, option=option)
MY_runner_DP_1 = flgo.init(task, DP.PPFL_DP, option=option_1)
MY_runner_DP_2 = flgo.init(task, DP.PPFL_DP, option=option_2)
MY_runner_DP_3 = flgo.init(task, DP.PPFL_DP, option=option_3)
MY_runner_DP_4 = flgo.init(task, DP.PPFL_DP, option=option_4)
MY_runner_DP_5 = flgo.init(task, DP.PPFL_DP, option=option_5)
MY_runner_DP_6 = flgo.init(task, DP.PPFL_DP, option=option_6)
MY_runner_DP_7 = flgo.init(task, DP.PPFL_DP, option=option_7)
# fedavg_runner.run()
MY_runner_DP_1.run()
MY_runner_DP_2.run()
MY_runner_DP_3.run()
MY_runner_DP_4.run()
MY_runner_DP_5.run()
MY_runner_DP_6.run()
MY_runner_DP_7.run()
analysis_plan = {
'Selector': {
'task': task,
'header': ['PPFL_DP'],
'legend_with': ['C']
},
'Painter': {
'Curve': [
{'args': {'x': 'communication_round', 'y': 'test_loss'},
'obj_option': {#'color': ['r', 'g', 'b', 'y', 'k','m','c','g'],
'marker':['o','<','>','^','v','*','x','.']},
'fig_option': {'xlabel': 'communication round', 'ylabel': 'test_accuracy','title': 'test loss on Synthetic'}},
{'args': {'x': 'communication_round', 'y': 'test_accuracy'},
'obj_option': {#'color': ['r', 'g', 'b', 'y', 'k','m','c','g'],
'marker':['o','<','>','^','v','*','x','.']},
'fig_option': {'xlabel': 'communication round', 'ylabel': 'test_accuracy','title': 'test accuracy on Synthetic'}},
{'args': {'x': 'communication_round', 'y': 'val_accuracy'},
'obj_option': {#'color': ['r', 'g', 'b', 'y', 'k','m','c','g'],
'marker':['o','<','>','^','v','*','x','.']},
'fig_option': {'xlabel': 'communication round', 'ylabel': 'test_accuracy','title': 'valid accuracy on Synthetic'}},
{'args': {'x': 'communication_round', 'y': 'val_loss'},
'obj_option': {#'color': ['r', 'g', 'b', 'y', 'k','m','c','g'],
'marker':['o','<','>','^','v','*','x','.']},
'fig_option': {'xlabel': 'communication round', 'ylabel': 'test_accuracy','title': 'valid loss on Synthetic'}},
]
}
}
flgo.experiment.analyzer.show(analysis_plan)