-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.py
239 lines (228 loc) · 6.93 KB
/
args.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import os
import argparse
def args_to_string(args):
"""
Transform experiment's arguments into a string
:param args:
:return: string
"""
if args.decentralized:
return f"{args.experiment}_decentralized"
args_string = ""
args_to_show = ["experiment", "method"]
for arg in args_to_show:
args_string = os.path.join(args_string, str(getattr(args, arg)))
if args.locally_tune_clients:
args_string += "_adapt"
return args_string
def parse_args(args_list=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'experiment',
help='name of experiment',
type=str
)
parser.add_argument(
'method',
help='the method to be used;'
' possible are `FedAvg`, `FedEM`, `local`, `FedProx`, `L2SGD`,'
' `pFedMe`, `AFL`, `FFL` and `clustered`;',
type=str
)
parser.add_argument(
'--decentralized',
help='if chosen decentralized version is used,'
'client are connected via an erdos-renyi graph of parameter p=0.5,'
'the mixing matrix is obtained via FMMC (Fast Mixin Markov Chain),'
'see https://web.stanford.edu/~boyd/papers/pdf/fmmc.pdf);'
'can be combined with `method=FedEM`, in that case it is equivalent to `D-EM`;'
'can not be used when method is `AFL` or `FFL`, in that case a warning is raised'
'and decentralized is set to `False`;'
'in all other cases D-SGD is used;',
action='store_true'
)
parser.add_argument(
'--sampling_rate',
help='proportion of clients to be used at each round; default is 1.0',
type=float,
default=1.0
)
parser.add_argument(
'--input_dimension',
help='the dimension of one input sample; only used for synthetic dataset',
type=int,
default=None
)
parser.add_argument(
'--output_dimension',
help='the dimension of output space; only used for synthetic dataset',
type=int,
default=None
)
parser.add_argument(
'--n_learners',
help='number of learners_ensemble to be used with `FedEM`; ignored if method is not `FedEM`; default is 3',
type=int,
default=3
)
parser.add_argument(
'--n_rounds',
help='number of communication rounds; default is 1',
type=int,
default=1
)
parser.add_argument(
'--bz',
help='batch_size; default is 1',
type=int,
default=1
)
parser.add_argument(
'--local_steps',
help='number of local steps before communication; default is 1',
type=int,
default=1
)
parser.add_argument(
'--log_freq',
help='frequency of writing logs; defaults is 1',
type=int,
default=1
)
parser.add_argument(
'--device',
help='device to use, either cpu or cuda; default is cpu',
type=int,
default=0
)
parser.add_argument(
'--optimizer',
help='optimizer to be used for the training; default is sgd',
type=str,
default="sgd"
)
parser.add_argument(
"--lr",
type=float,
help='learning rate; default is 1e-3',
default=1e-3
)
parser.add_argument(
"--lr_lambda",
type=float,
help='learning rate for clients weights; only used for agnostic FL; default is 0.',
default=0.
)
parser.add_argument(
"--lr_scheduler",
help='learning rate decay scheme to be used;'
' possible are "sqrt", "linear", "cosine_annealing", "multi_step" and "constant" (no learning rate decay);'
'default is "constant"',
type=str,
default="constant"
)
parser.add_argument(
"--mu",
help='proximal / penalty term weight, used when --optimizer=`prox_sgd` also used with L2SGD; default is `0.`',
type=float,
default=0
)
parser.add_argument(
"--gamma",
help='the tolerate threhold of adaptive FedConceptEM; default is `0.`',
type=float,
default=0.05
)
parser.add_argument(
"--suffix",
help='the suffix to be added at the name of log files; default is empty string',
type=str,
default=''
)
parser.add_argument(
"--communication_probability",
help='communication probability, only used with L2SGD',
type=float,
default=0.1
)
parser.add_argument(
"--q",
help='fairness hyper-parameter, ony used for FFL client; default is 1.',
type=float,
default=1.
)
parser.add_argument(
"--locally_tune_clients",
help='if selected, clients are tuned locally for one epoch before writing logs;',
action='store_true'
)
parser.add_argument(
"--split",
help='if selected, feature and classifiers will be splitted',
action='store_true'
)
parser.add_argument(
"--hard_cluster",
help='if selected, use hard cluster for prediction',
action='store_true'
)
parser.add_argument(
"--binary",
help='if selected, use binary classification loss',
action='store_true'
)
parser.add_argument(
"--domain_disc",
help='if selected, will add a domain discriminator to learn more robust feature extractors',
action='store_true'
)
parser.add_argument(
"--phi_model",
help='if selected, will add an additional model phi for distance calculation (for stoCFL)',
action='store_true'
)
parser.add_argument(
'--validation',
help='if chosen the validation part will be used instead of test part;'
' make sure to use `val_frac > 0` in `generate_data.py`;',
action='store_true'
)
parser.add_argument(
"--verbose",
help='verbosity level, `0` to quiet, `1` to show global logs and `2` to show local logs; default is `0`;',
type=int,
default=0
)
parser.add_argument(
"--logs_dir",
help='directory to write logs; if not passed, it is set using arguments',
default=argparse.SUPPRESS
)
parser.add_argument(
"--save_dir",
help='directory to save checkpoints once the training is over; if not specified checkpoints are not saved',
default=argparse.SUPPRESS
)
parser.add_argument(
"--seed",
help='random seed',
type=int,
default=1234
)
parser.add_argument(
'--embedding_dimension',
help='the dimension of the internal embedding',
type=int,
default=32
)
parser.add_argument(
'--em_step',
help='steps interval of updating ems',
type=int,
default=1
)
if args_list:
args = parser.parse_args(args_list)
else:
args = parser.parse_args()
return args