flgo.benchmark.base
AbstractTaskCalculator
Abstract Task Calculator
Source code in flgo\benchmark\base.py
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 |
|
compute_loss(model, data, *args, **kwargs)
abstractmethod
Compute the loss of the model on the data to complete the forward process
Source code in flgo\benchmark\base.py
69 70 71 72 |
|
get_dataloader(*args, **kwargs)
abstractmethod
Return a data loader that splits the input data into batches
Source code in flgo\benchmark\base.py
59 60 61 62 |
|
get_optimizer(model, *args, **kwargs)
abstractmethod
Return the optimizer on the parameters of the model
Source code in flgo\benchmark\base.py
74 75 76 77 |
|
test(model, data, *args, **kwargs)
abstractmethod
Evaluate the model on the data
Source code in flgo\benchmark\base.py
64 65 66 67 |
|
to_device(*args, **kwargs)
abstractmethod
Put the data into the gpu device
Source code in flgo\benchmark\base.py
54 55 56 57 |
|
AbstractTaskGenerator
Abstract Task Generator
Source code in flgo\benchmark\base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
generate(*args, **kwarg)
abstractmethod
Load and partition the data, and then generate the necessary information about the federated task (e.g. path, partition way, ...)
Source code in flgo\benchmark\base.py
30 31 32 33 34 |
|
load_data(*args, **kwarg)
abstractmethod
Load the original data into memory that can be partitioned
Source code in flgo\benchmark\base.py
18 19 20 21 |
|
partition(*args, **kwarg)
abstractmethod
Partition the loaded data into subsets of data owned by clients and the test data owned by the server
Source code in flgo\benchmark\base.py
23 24 25 26 27 28 |
|
AbstractTaskPipe
Abstract Task Pipe
Source code in flgo\benchmark\base.py
36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
load_task(*args, **kwargs)
abstractmethod
Load a federated task from disk
Source code in flgo\benchmark\base.py
45 46 47 48 |
|
save_task(*args, **kwargs)
abstractmethod
Save a federated task created by TaskGenerator as a static file on the disk
Source code in flgo\benchmark\base.py
40 41 42 43 |
|
BasicTaskCalculator
Bases: AbstractTaskCalculator
Support task-specific computation when optimizing models, such as putting data into device, computing loss, evaluating models, and creating the data loader
Source code in flgo\benchmark\base.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
__init__(device, optimizer_name='sgd')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
torch.device
|
device |
required |
optimizer_name |
str
|
the name of the optimizer |
'sgd'
|
Source code in flgo\benchmark\base.py
354 355 356 357 358 359 360 361 362 363 364 |
|
get_optimizer(model=None, lr=0.1, weight_decay=0, momentum=0)
Create optimizer of the model parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
torch.nn.Module
|
model |
None
|
lr |
float
|
learning rate |
0.1
|
weight_decay |
float
|
the weight_decay coefficient |
0
|
momentum |
float
|
the momentum coefficient |
0
|
Returns:
Type | Description |
---|---|
the optimizer |
Source code in flgo\benchmark\base.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
BasicTaskGenerator
Bases: AbstractTaskGenerator
Load the original dataset and partition the original dataset into local_movielens_recommendation data
Source code in flgo\benchmark\base.py
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 |
|
__init__(benchmark, rawdata_path)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
benchmark |
str
|
the name of the federated task |
required |
rawdata_path |
str
|
the dictionary of the original dataset |
required |
Source code in flgo\benchmark\base.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
generate(*args, **kwarg)
The whole process to generate federated task.
Source code in flgo\benchmark\base.py
104 105 106 107 108 109 110 111 112 |
|
get_task_name()
Create the default name of the task
Source code in flgo\benchmark\base.py
139 140 141 142 143 144 145 146 |
|
load_data(*args, **kwargs)
Download and load dataset into memory.
Source code in flgo\benchmark\base.py
114 115 116 |
|
partition(*args, **kwargs)
Partition the data into different local_movielens_recommendation datasets
Source code in flgo\benchmark\base.py
118 119 120 |
|
register_partitioner(partitioner=None)
Register the partitioner as self's data partitioner
Source code in flgo\benchmark\base.py
122 123 124 |
|
BasicTaskPipe
Bases: AbstractTaskPipe
Store the partition information of TaskGenerator into the disk when generating federated tasks.
Load the original dataset and the partition information to create the federated scenario when optimizing models
Source code in flgo\benchmark\base.py
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
__init__(task_path)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_path |
str
|
the path of the federated task |
required |
Source code in flgo\benchmark\base.py
158 159 160 161 162 163 164 165 166 |
|
create_task_architecture()
Create the directories of the task.
Source code in flgo\benchmark\base.py
329 330 331 332 333 334 335 336 |
|
distribute(task_data, objects)
Distribute the loaded local_movielens_recommendation datasets to different objects in the federated scenario
Source code in flgo\benchmark\base.py
282 283 284 285 286 287 288 289 290 291 |
|
gen_client_names(num_clients)
Generate the names of clients
Returns:
Type | Description |
---|---|
a list of strings |
Source code in flgo\benchmark\base.py
338 339 340 341 342 343 344 345 |
|
generate_objects(running_time_option, algorithm, scene='horizontal')
Generate the virtual objects (i.e. coordinators and participants) in the FL system
Parameters:
Name | Type | Description | Default |
---|---|---|---|
running_time_option |
dict
|
the option (i.e. configuration) |
required |
algorithm |
module|class
|
algorithm |
required |
scene |
str
|
horizontal or vertical |
'horizontal'
|
Source code in flgo\benchmark\base.py
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
load_data(running_time_option)
Load the data and process it to the format that can be distributed to different objects
Source code in flgo\benchmark\base.py
173 174 175 176 |
|
load_task(running_time_option, *args, **kwargs)
Load the generated task into disk and create objects in the federated scenario.
Source code in flgo\benchmark\base.py
272 273 274 275 276 277 278 279 280 |
|
remove_task()
Remove this task
Source code in flgo\benchmark\base.py
323 324 325 326 327 |
|
save_info(generator)
Save the basic information of the generated task into the disk
Source code in flgo\benchmark\base.py
262 263 264 265 266 267 268 269 270 |
|
save_task(generator)
Construct feddata
and store it into the disk for recovering
the partitioned datasets again from it
Source code in flgo\benchmark\base.py
168 169 170 171 |
|
split_dataset(dataset, p=0.0)
Split the dataset into two parts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
torch.utils.data.Dataset
|
the dataset to be splitted |
required |
p |
float
|
the ratio of the splitting |
0.0
|
Returns:
Type | Description |
---|---|
The two split parts |
Source code in flgo\benchmark\base.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
task_exists()
Check whether the task already exists.
Returns:
Type | Description |
---|---|
True if the task already exists |
Source code in flgo\benchmark\base.py
314 315 316 317 318 319 320 321 |
|
FromDatasetGenerator
Bases: BasicTaskGenerator
This generator will do: 1. Directly create train_data and test_data from input; 2. Convert the train_data into the scheme that can be partitioned by Partitioner if necessary.
Source code in flgo\benchmark\base.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
prepare_data_for_partition()
Transform the attribution self.train_data into the format that can be received by partitioner
Source code in flgo\benchmark\base.py
503 504 505 |
|
XYHorizontalTaskPipe
Bases: BasicTaskPipe
This pipe is for supervised learning where each sample contains a feature \(x_i\) and a label \(y_i\)
that can be indexed by \(i\).
To use this pipe, it's necessary to set the attribute test_data
of the generator to be a dict like:
{'x': [...], 'y':[...]}
and the attribute local_datas
to be a list of the above dict that means the local_movielens_recommendation data owned by clients:
[{'x':[...], 'y':[...]}, ..., ]
Source code in flgo\benchmark\base.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|